pdf417 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -12,4 +12,3 @@ lib/pdf417/Makefile
12
12
  stash
13
13
  .rake_tasks
14
14
  tmp
15
- *.gemspec
@@ -15,6 +15,8 @@ A wrapper for the pdf417lib C Library, from the README:
15
15
  Fetching the codewords only can be handy for using rtex and the pst-barcode package. If you're using prawn
16
16
  or RMagic the to_blob function should help generate a complete barcode.
17
17
 
18
+ Much of this was based off of reading through the Nokogiri and RMagic source code. Thanks!
19
+
18
20
  == Usage
19
21
 
20
22
  There are a few ways to use the library, at its simplest:
data/Rakefile CHANGED
@@ -57,3 +57,9 @@ Rake::RDocTask.new do |rdoc|
57
57
  rdoc.rdoc_files.include("*.rdoc")
58
58
  rdoc.rdoc_files.include("ext/pdf417/*.c")
59
59
  end
60
+
61
+ desc 'rebuilds the pdf417 library'
62
+ task :build_extension do
63
+ pwd = `pwd`
64
+ exec "cd ext/pdf417 && make clean && ruby extconf.rb && make && cd #{pwd}"
65
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -39,7 +39,6 @@ void Init_pdf417() {
39
39
  rb_define_method(rb_cPdf417, "code_columns", rb_pdf417_codeColumns, 0);
40
40
  rb_define_method(rb_cPdf417, "codeword_length", rb_pdf417_lenCodewords, 0);
41
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
42
  rb_define_method(rb_cPdf417, "aspect_ratio", rb_pdf417_aspectRatio, 0);
44
43
  rb_define_method(rb_cPdf417, "y_height", rb_pdf417_yHeight, 0);
45
44
  rb_define_method(rb_cPdf417, "generation_error", rb_pdf417_error, 0);
@@ -96,6 +95,7 @@ static VALUE rb_pdf417_new(VALUE class, VALUE text) {
96
95
  pdf417param *ptr;
97
96
  VALUE tdata = Data_Make_Struct(class, pdf417param, 0, rb_pdf417_cleanup, ptr);
98
97
  pdf417init(ptr);
98
+ rb_iv_set(tdata, "@generation_options", INT2NUM(ptr->options));
99
99
  argv[0] = text;
100
100
  rb_obj_call_init(tdata, 1, argv);
101
101
  return tdata;
@@ -112,15 +112,7 @@ static VALUE rb_pdf417_codewords(VALUE self) {
112
112
  int k;
113
113
  pdf417param *ptr;
114
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
115
+ refreshStruct(self, ptr);
124
116
  if (ptr->error) {
125
117
  return Qnil; //could also return list
126
118
  }
@@ -143,15 +135,7 @@ static VALUE rb_pdf417_codewords(VALUE self) {
143
135
  static VALUE rb_pdf417_to_blob(VALUE self) {
144
136
  pdf417param *ptr;
145
137
  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
138
+ refreshStruct(self, ptr);
155
139
  if (ptr->error) {
156
140
  return Qnil; //could also return list
157
141
  }
@@ -231,26 +215,6 @@ static VALUE rb_pdf417_errorLevel(VALUE self){
231
215
  return INT2NUM(ptr->errorLevel);
232
216
  }
233
217
 
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
218
  /*
255
219
  * call-seq:
256
220
  * aspect_ratio
@@ -289,3 +253,29 @@ static VALUE rb_pdf417_error(VALUE self){
289
253
  Data_Get_Struct(self, pdf417param, ptr);
290
254
  return INT2NUM(ptr->error);
291
255
  }
256
+
257
+ // Refresh the PDF417 struct containing our data if anything important has changed.
258
+ static void refreshStruct(VALUE self, pdf417param *ptr) {
259
+
260
+ char* text = STR2CSTR(rb_iv_get(self, "@text"));
261
+ int options = 0;
262
+ VALUE generation_options = rb_iv_get(self, "@generation_options");
263
+
264
+ if ( TYPE(generation_options) == T_FIXNUM ){
265
+ options = FIX2INT(generation_options);
266
+ }
267
+
268
+ // Only re-do it if our text has changed
269
+ if ( 0 != strcmp(ptr->text, text) || options != ptr->options) {
270
+ ptr->options = options;
271
+ ptr->outBits = NULL;
272
+ ptr->lenBits = 0;
273
+ ptr->error = 0;
274
+ ptr->lenText = -1;
275
+ ptr->text = "";
276
+ ptr->yHeight = 3;
277
+ ptr->aspectRatio = 0.5;
278
+ ptr->text = STR2CSTR(rb_iv_get(self, "@text"));
279
+ paintCode(ptr); //paintCode also sets the error correction, we call it here so we can get the blob if needed w/o trouble
280
+ }
281
+ }
@@ -1,12 +1,3 @@
1
- // strfunctions from Nokogiri
2
- #define PDF417_STR_NEW2(str) \
3
- rb_str_new2((const char *)(str))
4
-
5
- #define PDF417_STR_NEW(str, len) \
6
- rb_str_new((const char *)(str), (long)(len))
7
-
8
- #define RBSTR_OR_QNIL(_str) \
9
- (_str ? PDF417_STR_NEW2(_str) : Qnil)
10
1
 
11
2
  VALUE rb_cPdf417;
12
3
  static VALUE rb_pdf417_encode_text(VALUE self, VALUE text);
@@ -21,7 +12,7 @@ static VALUE rb_pdf417_codeRows(VALUE self);
21
12
  static VALUE rb_pdf417_codeColumns(VALUE self);
22
13
  static VALUE rb_pdf417_lenCodewords(VALUE self);
23
14
  static VALUE rb_pdf417_errorLevel(VALUE self);
24
- static VALUE rb_pdf417_options(VALUE self);
25
15
  static VALUE rb_pdf417_aspectRatio(VALUE self);
26
16
  static VALUE rb_pdf417_yHeight(VALUE self);
27
17
  static VALUE rb_pdf417_error(VALUE self);
18
+ static void refreshStruct(VALUE self, pdf417param *ptr);
@@ -1,6 +1,33 @@
1
1
  require 'pdf417/pdf417'
2
2
 
3
3
  class PDF417
4
+
5
+ PDF417_USE_ASPECT_RATIO = 0
6
+ PDF417_FIXED_RECTANGLE = 1
7
+ PDF417_FIXED_COLUMNS = 2
8
+ PDF417_FIXED_ROWS = 4
9
+ PDF417_AUTO_ERROR_LEVEL = 0
10
+ PDF417_USE_ERROR_LEVEL = 16
11
+ PDF417_USE_RAW_CODEWORDS = 64
12
+ PDF417_INVERT_BITMAP = 128
13
+
14
+ PDF417_ERROR_SUCCESS = 0
15
+ PDF417_ERROR_TEXT_TOO_BIG = 1
16
+ PDF417_ERROR_INVALID_PARAMS = 2
17
+
18
+ # The int representing the options used to generate the barcode, defined in the library as:
19
+ # [PDF417_USE_ASPECT_RATIO] use aspectRatio to set the y/x dimension. Also uses yHeight
20
+ # [PDF417_FIXED_RECTANGLE] make the barcode dimensions at least codeColumns by codeRows
21
+ # [PDF417_FIXED_COLUMNS] make the barcode dimensions at least codeColumns
22
+ # [PDF417_FIXED_ROWS] make the barcode dimensions at least codeRows
23
+ # [PDF417_AUTO_ERROR_LEVEL] automatic error level depending on text size
24
+ # [PDF417_USE_ERROR_LEVEL] the error level is errorLevel. The used errorLevel may be different
25
+ # [PDF417_USE_RAW_CODEWORDS] use codewords instead of text
26
+ # [PDF417_INVERT_BITMAP] invert the resulting bitmap
27
+ #
28
+ # For example
29
+ # b.generation_options = PDF417::PDF417_INVERT_BITMAP | PDF417::PDF417_AUTO_ERROR_LEVEL
30
+ attr_accessor :generation_options
4
31
  attr_accessor :text
5
32
  def inspect # :nodoc:
6
33
  attributes = inspect_attributes.reject { |x|
@@ -14,8 +41,7 @@ class PDF417
14
41
  "#{attribute.to_s}=#{send(attribute).inspect}"
15
42
  }.join ' '
16
43
  "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
17
- end
18
-
44
+ end
19
45
 
20
46
  private
21
47
  def inspect_attributes
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pdf417}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jamesprior"]
12
+ s.date = %q{2011-03-30}
13
+ s.description = %q{Generate a series of codewords or a binary blob for PDF417 barcodes}
14
+ s.email = %q{j.prior@asee.org}
15
+ s.extensions = ["ext/pdf417/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "ext/pdf417/Makefile",
28
+ "ext/pdf417/extconf.rb",
29
+ "ext/pdf417/pdf417.c",
30
+ "ext/pdf417/pdf417.h",
31
+ "ext/pdf417/pdf417lib.c",
32
+ "ext/pdf417/pdf417lib.h",
33
+ "ext/pdf417/pdf417libimp.h",
34
+ "lib/pdf417.rb",
35
+ "pdf417.gemspec",
36
+ "test/pdf417_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/asee/pdf417}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib", "ext"]
42
+ s.rubygems_version = %q{1.6.2}
43
+ s.summary = %q{A Ruby wrapper for the PDF417 barcode library}
44
+ s.test_files = [
45
+ "test/pdf417_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ else
54
+ end
55
+ else
56
+ end
57
+ end
@@ -1,7 +1,55 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Pdf417Test < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+
5
+ should "initialize text" do
6
+ b = PDF417.new("fred")
7
+ assert_equal "fred", b.text
6
8
  end
9
+
10
+ should "initialize generation_options" do
11
+ b = PDF417.new("fred")
12
+ assert_equal 0, b.generation_options
13
+ end
14
+
15
+ should "know the right codewords for fred" do
16
+ assert_equal [4, 815, 514, 119], PDF417.encode_text("fred")
17
+ assert_equal [4, 815, 514, 119], PDF417.new("fred").codewords
18
+ end
19
+
20
+ should "re-generate if the text has been reassigned" do
21
+ b = PDF417.new("fred")
22
+ fred_words = b.codewords
23
+ fred_blob = b.to_blob
24
+ b.text = "Joebob"
25
+ assert fred_words != b.codewords
26
+ assert fred_blob != b.to_blob
27
+ end
28
+
29
+ should "re-generate if the text has been updated" do
30
+ b = PDF417.new("fred")
31
+ fred_words = b.codewords
32
+ fred_blob = b.to_blob
33
+ b.text += " and joe"
34
+ assert fred_words != b.codewords
35
+ assert fred_blob != b.to_blob
36
+ end
37
+
38
+ should "re-generate if the options have changed" do
39
+ b = PDF417.new("fred")
40
+ fred_words = b.codewords
41
+ fred_blob = b.to_blob
42
+ b.generation_options = PDF417::PDF417_INVERT_BITMAP
43
+ assert_equal b.generation_options, PDF417::PDF417_INVERT_BITMAP
44
+ assert_equal fred_words, b.codewords # NOTE that the codewords have not changed, just the binary blob
45
+ assert fred_blob != b.to_blob
46
+ end
47
+
48
+ should "work when generation options are set weird" do
49
+ b = PDF417.new("fred")
50
+ b.generation_options = "ALBERT"
51
+ assert b.codewords.is_a?(Array)
52
+ end
53
+
54
+
7
55
  end
@@ -1,10 +1,13 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
1
 
5
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext'))
6
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
5
  require 'pdf417'
8
6
 
7
+ require 'rubygems'
8
+ require 'test/unit'
9
+ require 'shoulda'
10
+
11
+
9
12
  class Test::Unit::TestCase
10
13
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf417
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - jamesprior
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2011-03-29 00:00:00 -04:00
18
+ date: 2011-03-30 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -36,8 +42,8 @@ files:
36
42
  - ext/pdf417/pdf417lib.c
37
43
  - ext/pdf417/pdf417lib.h
38
44
  - ext/pdf417/pdf417libimp.h
39
- - ext/pdf417/test.rb
40
45
  - lib/pdf417.rb
46
+ - pdf417.gemspec
41
47
  - test/pdf417_test.rb
42
48
  - test/test_helper.rb
43
49
  has_rdoc: true
@@ -51,21 +57,27 @@ require_paths:
51
57
  - lib
52
58
  - ext
53
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
54
61
  requirements:
55
62
  - - ">="
56
63
  - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
57
67
  version: "0"
58
- version:
59
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
60
70
  requirements:
61
71
  - - ">="
62
72
  - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
63
76
  version: "0"
64
- version:
65
77
  requirements: []
66
78
 
67
79
  rubyforge_project:
68
- rubygems_version: 1.3.5
80
+ rubygems_version: 1.6.2
69
81
  signing_key:
70
82
  specification_version: 3
71
83
  summary: A Ruby wrapper for the PDF417 barcode library
@@ -1,52 +0,0 @@
1
- # Basic testing file, run via make clean && ruby extconf.rb && make && ruby test.rb
2
- require 'pdf417'
3
-
4
- class PDF417
5
- attr_accessor :text
6
- def inspect # :nodoc:
7
- attributes = inspect_attributes.reject { |x|
8
- begin
9
- attribute = send x
10
- !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
11
- rescue NoMethodError
12
- true
13
- end
14
- }.map { |attribute|
15
- "#{attribute.to_s}=#{send(attribute).inspect}"
16
- }.join ' '
17
- "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
18
- end
19
-
20
-
21
- private
22
- def inspect_attributes
23
- [:text, :bit_columns, :bit_length, :code_rows, :code_columns, :codeword_length, :error_level, :generation_options, :aspect_ratio, :y_height, :generation_error]
24
- end
25
- end
26
-
27
-
28
- puts "Testing codewords for 'fred'"
29
- PDF417.encode_text("fred").each_with_index{|cw,i| puts "Ruby thinks cw #{i} is #{cw}"}
30
- # For fred, should return:
31
- # Ruby thinks cw 0 is 4
32
- # Ruby thinks cw 1 is 815
33
- # Ruby thinks cw 2 is 514
34
- # Ruby thinks cw 3 is 119
35
-
36
- p = PDF417.new("test")
37
- puts p.inspect
38
- p = PDF417.new("fred")
39
- puts p.text
40
- puts p.codewords.inspect
41
- puts p.to_blob.inspect
42
- puts p.bit_columns
43
- puts p.bit_length
44
- puts p.code_rows
45
- puts p.code_columns
46
- puts p.codeword_length
47
- puts p.error_level
48
- puts p.generation_options
49
- puts p.aspect_ratio
50
- puts p.y_height
51
- puts p.generation_error
52
- puts p.inspect