pdf417 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +15 -0
- data/LICENSE +20 -0
- data/README.rdoc +46 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/ext/pdf417/Makefile +157 -0
- data/ext/pdf417/extconf.rb +4 -0
- data/ext/pdf417/pdf417.c +291 -0
- data/ext/pdf417/pdf417.h +27 -0
- data/ext/pdf417/pdf417lib.c +860 -0
- data/ext/pdf417/pdf417lib.h +91 -0
- data/ext/pdf417/pdf417libimp.h +514 -0
- data/ext/pdf417/test.rb +52 -0
- data/lib/pdf417.rb +24 -0
- data/test/pdf417_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +74 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 jamesprior
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= pdf417
|
2
|
+
|
3
|
+
A wrapper for the pdf417lib C Library, from the README:
|
4
|
+
|
5
|
+
A library to generate the 2D barcode PDF417
|
6
|
+
|
7
|
+
Project: http://sourceforge.net/projects/pdf417.lib
|
8
|
+
Creator: Paulo Soares (psoares@consiste.pt)
|
9
|
+
License: LGPL or MPL 1.1
|
10
|
+
|
11
|
+
This library generates a PDF417 image of the barcode in a 1x1 scale.
|
12
|
+
It requires that the displayed image be as least stretched 3 times
|
13
|
+
in the vertical direction in relation with the horizontal dimension.
|
14
|
+
|
15
|
+
Fetching the codewords only can be handy for using rtex and the pst-barcode package. If you're using prawn
|
16
|
+
or RMagic the to_blob function should help generate a complete barcode.
|
17
|
+
|
18
|
+
== Usage
|
19
|
+
|
20
|
+
There are a few ways to use the library, at its simplest:
|
21
|
+
|
22
|
+
PDF417.encode_text("readable barcode data") => [12, 827, 120, 90, 41, 146, 30, 512, 423, 146, 90, 570]
|
23
|
+
|
24
|
+
If you want to get the bitmap:
|
25
|
+
|
26
|
+
barcode = PDF417.new("readable barcode data")
|
27
|
+
barcode.to_blob # oops, wrong text
|
28
|
+
barcode.text = "ACTUAL barcode data"
|
29
|
+
barcode.to_blob
|
30
|
+
|
31
|
+
See the RDocs for more information.
|
32
|
+
|
33
|
+
== Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally.
|
39
|
+
* Commit, do not mess with rakefile, version, or history.
|
40
|
+
(if you want to have your own version, that is fine but
|
41
|
+
bump version in a commit by itself I can ignore when I pull)
|
42
|
+
* Send me a pull request. Bonus points for topic branches.
|
43
|
+
|
44
|
+
== Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2011 jamesprior. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "pdf417"
|
8
|
+
gem.summary = %Q{A Ruby wrapper for the PDF417 barcode library}
|
9
|
+
gem.description = %Q{Generate a series of codewords or a binary blob for PDF417 barcodes}
|
10
|
+
gem.email = "j.prior@asee.org"
|
11
|
+
gem.homepage = "http://github.com/asee/pdf417"
|
12
|
+
gem.authors = ["jamesprior"]
|
13
|
+
gem.extensions << 'ext/pdf417/extconf.rb'
|
14
|
+
gem.require_paths << 'ext'
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/*_test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/*_test.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
if File.exist?('VERSION')
|
48
|
+
version = File.read('VERSION')
|
49
|
+
else
|
50
|
+
version = ""
|
51
|
+
end
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "pdf417 #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
rdoc.rdoc_files.include("*.rdoc")
|
58
|
+
rdoc.rdoc_files.include("ext/pdf417/*.c")
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/ext/pdf417/Makefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/1.8/i686-darwin10.3.0
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
exec_prefix = $(prefix)
|
11
|
+
prefix = $(DESTDIR)/opt/ruby-enterprise-1.8.7-2010.01
|
12
|
+
sharedstatedir = $(prefix)/com
|
13
|
+
mandir = $(datarootdir)/man
|
14
|
+
psdir = $(docdir)
|
15
|
+
oldincludedir = $(DESTDIR)/usr/include
|
16
|
+
localedir = $(datarootdir)/locale
|
17
|
+
bindir = $(exec_prefix)/bin
|
18
|
+
libexecdir = $(exec_prefix)/libexec
|
19
|
+
sitedir = $(libdir)/ruby/site_ruby
|
20
|
+
htmldir = $(docdir)
|
21
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
+
includedir = $(prefix)/include
|
23
|
+
infodir = $(datarootdir)/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
+
sysconfdir = $(prefix)/etc
|
26
|
+
libdir = $(exec_prefix)/lib
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
+
dvidir = $(docdir)
|
31
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
+
datarootdir = $(prefix)/share
|
33
|
+
pdfdir = $(docdir)
|
34
|
+
archdir = $(rubylibdir)/$(arch)
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(prefix)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
+
|
40
|
+
CC = gcc
|
41
|
+
LIBRUBY = $(LIBRUBY_A)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED =
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fno-common -g -O2 -pipe -fno-common $(cflags)
|
48
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
49
|
+
DEFS =
|
50
|
+
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L.
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby
|
61
|
+
RUBY_SO_NAME = ruby
|
62
|
+
arch = i686-darwin10.3.0
|
63
|
+
sitearch = i686-darwin10.3.0
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /opt/ruby-enterprise-1.8.7-2010.01/bin/ruby
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = -ldl -lobjc
|
90
|
+
SRCS = pdf417.c pdf417lib.c
|
91
|
+
OBJS = pdf417.o pdf417lib.o
|
92
|
+
TARGET = pdf417
|
93
|
+
DLLIB = $(TARGET).bundle
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS) Makefile
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/ext/pdf417/pdf417.c
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
/* NOTE: This relies on the PDF417 Library from http://sourceforge.net/projects/pdf417lib and is included here
|
2
|
+
*
|
3
|
+
*/
|
4
|
+
|
5
|
+
#include <ruby.h>
|
6
|
+
#include "pdf417lib.h"
|
7
|
+
#include "pdf417.h"
|
8
|
+
|
9
|
+
/* A wrapper for the pdf417lib C Library, from the README:
|
10
|
+
|
11
|
+
A library to generate the 2D barcode PDF417
|
12
|
+
|
13
|
+
Project: http://sourceforge.net/projects/pdf417.lib
|
14
|
+
Creator: Paulo Soares (psoares@consiste.pt)
|
15
|
+
License: LGPL or MPL 1.1
|
16
|
+
|
17
|
+
This library generates a PDF417 image of the barcode in a 1x1 scale.
|
18
|
+
It requires that the displayed image be as least stretched 3 times
|
19
|
+
in the vertical direction in relation with the horizontal dimension.
|
20
|
+
|
21
|
+
This class will interface with the C library to take a text string representing
|
22
|
+
the barcode data and produce a list of data codewords, or a binary string (blob)
|
23
|
+
representing a bitmap.
|
24
|
+
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
// The initialization method for this module
|
29
|
+
void Init_pdf417() {
|
30
|
+
rb_cPdf417 = rb_define_class("PDF417", rb_cObject);
|
31
|
+
rb_define_singleton_method(rb_cPdf417, "encode_text", rb_pdf417_encode_text, 1);
|
32
|
+
rb_define_singleton_method(rb_cPdf417, "new", rb_pdf417_new, 1);
|
33
|
+
rb_define_method(rb_cPdf417, "initialize", rb_pdf417_init, 1);
|
34
|
+
rb_define_method(rb_cPdf417, "codewords", rb_pdf417_codewords, 0);
|
35
|
+
rb_define_method(rb_cPdf417, "to_blob", rb_pdf417_to_blob, 0);
|
36
|
+
rb_define_method(rb_cPdf417, "bit_columns", rb_pdf417_bitColumns, 0);
|
37
|
+
rb_define_method(rb_cPdf417, "bit_length", rb_pdf417_lenBits, 0);
|
38
|
+
rb_define_method(rb_cPdf417, "code_rows", rb_pdf417_codeRows, 0);
|
39
|
+
rb_define_method(rb_cPdf417, "code_columns", rb_pdf417_codeColumns, 0);
|
40
|
+
rb_define_method(rb_cPdf417, "codeword_length", rb_pdf417_lenCodewords, 0);
|
41
|
+
rb_define_method(rb_cPdf417, "error_level", rb_pdf417_errorLevel, 0);
|
42
|
+
rb_define_method(rb_cPdf417, "generation_options", rb_pdf417_options, 0);
|
43
|
+
rb_define_method(rb_cPdf417, "aspect_ratio", rb_pdf417_aspectRatio, 0);
|
44
|
+
rb_define_method(rb_cPdf417, "y_height", rb_pdf417_yHeight, 0);
|
45
|
+
rb_define_method(rb_cPdf417, "generation_error", rb_pdf417_error, 0);
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* encode_text(text)
|
51
|
+
*
|
52
|
+
* Returns an array of integers showing the codewords
|
53
|
+
*/
|
54
|
+
static VALUE rb_pdf417_encode_text(VALUE self, VALUE text) {
|
55
|
+
VALUE list;
|
56
|
+
int k;
|
57
|
+
|
58
|
+
pdf417param p;
|
59
|
+
pdf417init(&p);
|
60
|
+
p.text = StringValuePtr(text);
|
61
|
+
fetchCodewords(&p);
|
62
|
+
if (p.error) {
|
63
|
+
pdf417free(&p);
|
64
|
+
return Qnil; //could also return list or raise something
|
65
|
+
}
|
66
|
+
|
67
|
+
list = rb_ary_new2(p.lenCodewords);
|
68
|
+
|
69
|
+
pdf417free(&p);
|
70
|
+
|
71
|
+
for (k = 0; k < p.lenCodewords; ++k) {
|
72
|
+
rb_ary_push(list, INT2NUM(p.codewords[k]));
|
73
|
+
}
|
74
|
+
return list;
|
75
|
+
}
|
76
|
+
|
77
|
+
/* :nodoc: */
|
78
|
+
static void rb_pdf417_cleanup(void *p) {
|
79
|
+
pdf417free(p);
|
80
|
+
}
|
81
|
+
|
82
|
+
/* :nodoc: */
|
83
|
+
static VALUE rb_pdf417_init(VALUE self, VALUE text) {
|
84
|
+
rb_iv_set(self, "@text", text);
|
85
|
+
return self;
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* call-seq:
|
90
|
+
* new(text)
|
91
|
+
*
|
92
|
+
* Makes a new PDF417 object for the given text string
|
93
|
+
*/
|
94
|
+
static VALUE rb_pdf417_new(VALUE class, VALUE text) {
|
95
|
+
VALUE argv[1];
|
96
|
+
pdf417param *ptr;
|
97
|
+
VALUE tdata = Data_Make_Struct(class, pdf417param, 0, rb_pdf417_cleanup, ptr);
|
98
|
+
pdf417init(ptr);
|
99
|
+
argv[0] = text;
|
100
|
+
rb_obj_call_init(tdata, 1, argv);
|
101
|
+
return tdata;
|
102
|
+
}
|
103
|
+
|
104
|
+
/*
|
105
|
+
* call-seq:
|
106
|
+
* codewords
|
107
|
+
*
|
108
|
+
* Generates an array of codewords from the current text attribute
|
109
|
+
*/
|
110
|
+
static VALUE rb_pdf417_codewords(VALUE self) {
|
111
|
+
VALUE list;
|
112
|
+
int k;
|
113
|
+
pdf417param *ptr;
|
114
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
115
|
+
|
116
|
+
// Only re-do it if our text has changed
|
117
|
+
if ( ptr->text != STR2CSTR(rb_iv_get(self, "@text")) ) {
|
118
|
+
ptr->text = STR2CSTR(rb_iv_get(self, "@text")); //StringValuePtr(text);
|
119
|
+
|
120
|
+
paintCode(ptr); //paintCode also sets the error correction, we call it here so we can get the blob if needed w/o trouble
|
121
|
+
}
|
122
|
+
|
123
|
+
// otherwise, fill the array and respond
|
124
|
+
if (ptr->error) {
|
125
|
+
return Qnil; //could also return list
|
126
|
+
}
|
127
|
+
|
128
|
+
list = rb_ary_new2(ptr->lenCodewords);
|
129
|
+
|
130
|
+
// The first codeword is the length of the data, which is all we're interested in here.
|
131
|
+
for (k = 0; k < ptr->codewords[0]; ++k) {
|
132
|
+
rb_ary_push(list, INT2NUM(ptr->codewords[k]));
|
133
|
+
}
|
134
|
+
return list;
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* call-seq:
|
139
|
+
* to_blob
|
140
|
+
*
|
141
|
+
* Returns a binary string representing the image bits, requires scaling before display
|
142
|
+
*/
|
143
|
+
static VALUE rb_pdf417_to_blob(VALUE self) {
|
144
|
+
pdf417param *ptr;
|
145
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
146
|
+
|
147
|
+
// Only re-do it if our text has changed
|
148
|
+
if ( ptr->text != STR2CSTR(rb_iv_get(self, "@text")) ) {
|
149
|
+
ptr->text = STR2CSTR(rb_iv_get(self, "@text")); //StringValuePtr(text);
|
150
|
+
|
151
|
+
paintCode(ptr);
|
152
|
+
}
|
153
|
+
|
154
|
+
// otherwise, fill the array and respond
|
155
|
+
if (ptr->error) {
|
156
|
+
return Qnil; //could also return list
|
157
|
+
}
|
158
|
+
|
159
|
+
return rb_str_new2(ptr->outBits);
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* call-seq:
|
164
|
+
* bit_columns
|
165
|
+
*
|
166
|
+
* The number of column bits in the bitmap
|
167
|
+
*/
|
168
|
+
static VALUE rb_pdf417_bitColumns(VALUE self) {
|
169
|
+
pdf417param *ptr;
|
170
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
171
|
+
return INT2NUM(ptr->bitColumns);
|
172
|
+
}
|
173
|
+
|
174
|
+
/*
|
175
|
+
* call-seq:
|
176
|
+
* bit_length
|
177
|
+
*
|
178
|
+
* The size in bytes of the bitmap
|
179
|
+
*/
|
180
|
+
static VALUE rb_pdf417_lenBits(VALUE self) {
|
181
|
+
pdf417param *ptr;
|
182
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
183
|
+
return INT2NUM(ptr->lenBits);
|
184
|
+
}
|
185
|
+
|
186
|
+
/*
|
187
|
+
* call-seq:
|
188
|
+
* code_rows
|
189
|
+
*
|
190
|
+
* The number of code rows and bitmap lines
|
191
|
+
*/
|
192
|
+
static VALUE rb_pdf417_codeRows(VALUE self) {
|
193
|
+
pdf417param *ptr;
|
194
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
195
|
+
return INT2NUM(ptr->codeRows);
|
196
|
+
}
|
197
|
+
|
198
|
+
/*
|
199
|
+
* call-seq:
|
200
|
+
* code_columns
|
201
|
+
*
|
202
|
+
* The number of code columns
|
203
|
+
*/
|
204
|
+
static VALUE rb_pdf417_codeColumns(VALUE self) {
|
205
|
+
pdf417param *ptr;
|
206
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
207
|
+
return INT2NUM(ptr->codeColumns);
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* call-seq:
|
212
|
+
* codeword_length
|
213
|
+
*
|
214
|
+
* The size of the code words, including error correction codes
|
215
|
+
*/
|
216
|
+
static VALUE rb_pdf417_lenCodewords(VALUE self) {
|
217
|
+
pdf417param *ptr;
|
218
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
219
|
+
return INT2NUM(ptr->lenCodewords);
|
220
|
+
}
|
221
|
+
|
222
|
+
/*
|
223
|
+
* call-seq:
|
224
|
+
* error_level
|
225
|
+
*
|
226
|
+
* The error level required 0-8
|
227
|
+
*/
|
228
|
+
static VALUE rb_pdf417_errorLevel(VALUE self){
|
229
|
+
pdf417param *ptr;
|
230
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
231
|
+
return INT2NUM(ptr->errorLevel);
|
232
|
+
}
|
233
|
+
|
234
|
+
/*
|
235
|
+
* call-seq:
|
236
|
+
* generation_options
|
237
|
+
*
|
238
|
+
* The int representing the options used to generate the barcode, defined in the library as:
|
239
|
+
* [PDF417_USE_ASPECT_RATIO] use aspectRatio to set the y/x dimension. Also uses yHeight
|
240
|
+
* [PDF417_FIXED_RECTANGLE] make the barcode dimensions at least codeColumns by codeRows
|
241
|
+
* [PDF417_FIXED_COLUMNS] make the barcode dimensions at least codeColumns
|
242
|
+
* [PDF417_FIXED_ROWS] make the barcode dimensions at least codeRows
|
243
|
+
* [PDF417_AUTO_ERROR_LEVEL] automatic error level depending on text size
|
244
|
+
* [PDF417_USE_ERROR_LEVEL] the error level is errorLevel. The used errorLevel may be different
|
245
|
+
* [PDF417_USE_RAW_CODEWORDS] use codewords instead of text
|
246
|
+
* [PDF417_INVERT_BITMAP] invert the resulting bitmap
|
247
|
+
*/
|
248
|
+
static VALUE rb_pdf417_options(VALUE self){
|
249
|
+
pdf417param *ptr;
|
250
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
251
|
+
return INT2NUM(ptr->options);
|
252
|
+
}
|
253
|
+
|
254
|
+
/*
|
255
|
+
* call-seq:
|
256
|
+
* aspect_ratio
|
257
|
+
*
|
258
|
+
* The y/x aspect ratio
|
259
|
+
*/
|
260
|
+
static VALUE rb_pdf417_aspectRatio(VALUE self){
|
261
|
+
pdf417param *ptr;
|
262
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
263
|
+
return rb_float_new(ptr->aspectRatio);
|
264
|
+
}
|
265
|
+
|
266
|
+
/*
|
267
|
+
* call-seq:
|
268
|
+
* y_height
|
269
|
+
*
|
270
|
+
* The y/x dot ratio
|
271
|
+
*/
|
272
|
+
static VALUE rb_pdf417_yHeight(VALUE self){
|
273
|
+
pdf417param *ptr;
|
274
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
275
|
+
return rb_float_new(ptr->yHeight);
|
276
|
+
}
|
277
|
+
|
278
|
+
/*
|
279
|
+
* call-seq:
|
280
|
+
* generation_error
|
281
|
+
*
|
282
|
+
* The error returned as an int, defined in C as:
|
283
|
+
* [PDF417_ERROR_SUCCESS] no errors
|
284
|
+
* [PDF417_ERROR_TEXT_TOO_BIG] the text was too big the PDF417 specifications
|
285
|
+
* [PDF417_ERROR_INVALID_PARAMS] invalid parameters. Only used with PDF417_USE_RAW_CODEWORDS
|
286
|
+
*/
|
287
|
+
static VALUE rb_pdf417_error(VALUE self){
|
288
|
+
pdf417param *ptr;
|
289
|
+
Data_Get_Struct(self, pdf417param, ptr);
|
290
|
+
return INT2NUM(ptr->error);
|
291
|
+
}
|