semacode 0.7.1 → 0.7.2

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/CHANGELOG ADDED
@@ -0,0 +1,25 @@
1
+ CHANGELOG
2
+
3
+ 2007-03-02 guido
4
+
5
+ * Initial encoder wrapping for Ruby API
6
+
7
+ * Packaged as a gem
8
+
9
+
10
+ 2007-03-03 guido
11
+
12
+ * Separated native extension into its own namespace
13
+
14
+ * Trying to make a correct gem still
15
+
16
+
17
+ 2007-03-04 guido
18
+
19
+ * Exposed the encoding list used to create the semacode
20
+
21
+ * Use Ruby allocation functions instead of malloc.
22
+
23
+ * Fixes compiler errors with Fink not finding malloc.h
24
+
25
+ * Given up on making the gem do auto-require
data/README CHANGED
@@ -27,10 +27,12 @@ available from <http://www.gnu.org>
27
27
  You can contact me via <guido@sohne.net> if you have patches, bug fixes or
28
28
  improvements.
29
29
 
30
- * Based on the iec16022ecc200.c encoder by Adrian Kennard, Andrews & Arnold Ltd
31
-
32
- * Copyright (C) 2007, Guido Sohne
30
+ Copyright (C) 2007, Guido Sohne
31
+ Website: http://sohne.net/projects/semafox
32
+
33
+ === Credits
33
34
 
35
+ Based on the iec16022ecc200.c encoder by Adrian Kennard, Andrews & Arnold Ltd
34
36
 
35
37
  == Quick Start
36
38
 
@@ -80,6 +82,14 @@ Return the semacode as an array of arrays of boolean
80
82
  <tt>grid = semacode.data</tt> or
81
83
  <tt>grid = semacode.to_a</tt> or
82
84
 
85
+ Return the encoding list used to create the semacode
86
+
87
+ This encoding list is composed of the 'character set', complete with
88
+ shifts from one encoding type to another, that is used for the DataMatrix
89
+ algorithm.
90
+
91
+ <tt>encoding = semacode.encoding</tt>
92
+
83
93
  Return the semacode as a string
84
94
 
85
95
  The string is a comma separated list of character vectors. Each vector is a row
@@ -93,11 +103,11 @@ Encode another string
93
103
 
94
104
  <tt>semacode.encode "http://sohne.net"</tt>
95
105
 
96
- Get the width
106
+ Get the width of the semacode
97
107
 
98
108
  <tt>semacode.width</tt>
99
109
 
100
- Get the height
110
+ Get the height of the semacode
101
111
 
102
112
  <tt>semacode.height</tt>
103
113
 
@@ -106,7 +116,7 @@ How long is the semacode? (width * height)
106
116
  <tt>semacode.length</tt> or
107
117
  <tt>semacode.size</tt>
108
118
 
109
- Get the raw encoded length (before padding and before ecc)
119
+ Get the raw encoded length (before padding and before ECC)
110
120
 
111
121
  <tt>semacode.raw_encoded_length</tt>
112
122
 
@@ -114,11 +124,11 @@ Get the symbol size
114
124
 
115
125
  The max number of characters this semacode type
116
126
  (specific width x height) can hold is called the
117
- symbol size
127
+ symbol size.
118
128
 
119
129
  <tt>semacode.symbol_size</tt>
120
130
 
121
- * count the ECC bytes
131
+ Count the ECC bytes
122
132
 
123
133
  How many bytes were used for error correction?
124
134
 
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ spec = Gem::Specification.new do |s|
5
+ s.name = "semacode"
6
+ s.version = "0.7.2"
7
+ s.author = "Guido Sohne"
8
+ s.email = "guido@sohne.net"
9
+ s.homepage = "http://sohne.net/projects/semafox/"
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = "Create semacodes (2D barcodes) using Ruby."
12
+ s.rubyforge_project = "semacode"
13
+ s.description = <<DESC
14
+ This Ruby extension implements a DataMatrix encoder for Ruby. It is typically
15
+ used to create semacodes, which are barcodes, that contain URLs. This encoder
16
+ does not create image files or visual representations of the semacode. This is
17
+ because it can be used for more than creating images, such as rendering
18
+ semacodes to HTML, SVG, PDF or even stored in a database or file for later
19
+ use.
20
+ DESC
21
+
22
+ s.extensions << 'ext/extconf.rb'
23
+ s.add_dependency('rake', '>= 0.7.0')
24
+ s.files = FileList[
25
+ "{lib,ext}/**/*.rb",
26
+ "ext/**/*.c",
27
+ "ext/**/*.h",
28
+ "tests/**/*.rb",
29
+ "README",
30
+ "CHANGELOG",
31
+ "Rakefile"].to_a
32
+ s.require_path = "lib"
33
+ s.autorequire = "semacode"
34
+ s.test_files = FileList["{tests}/**/*test.rb"].to_a
35
+ s.has_rdoc = true
36
+ s.extra_rdoc_files = ["README"]
37
+ end
38
+
39
+ Rake::GemPackageTask.new(spec) do |pkg|
40
+ pkg.need_zip = true
41
+ pkg.need_tar_gz = true
42
+ pkg.need_tar_bz2 = true
43
+ end
44
+
45
+ task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
46
+ puts "Successfully created #{spec.name}-#{spec.version} gem"
47
+ end
48
+
49
+ if $0 == __FILE__
50
+ Gem::manage_gems
51
+ Gem::Builder.new(spec).build
52
+ end
data/ext/iec16022ecc200.c CHANGED
@@ -26,7 +26,6 @@
26
26
  #include <ctype.h>
27
27
  #include <string.h>
28
28
  #include <time.h>
29
- #include <malloc.h>
30
29
  #include "ruby.h"
31
30
  #include "reedsol.h"
32
31
  #include "iec16022ecc200.h"
@@ -71,19 +70,6 @@ ecc200matrix[] =
71
70
  0 // terminate
72
71
  };
73
72
 
74
- // simple checked response malloc
75
- static void *
76
- safemalloc (int n)
77
- {
78
- void *p = (void *) malloc((size_t) n);
79
- if (!p)
80
- {
81
- rb_raise(rb_eRuntimeError, "malloc failed", n);
82
- exit (1);
83
- }
84
- return p;
85
- }
86
-
87
73
  // Annex M placement alorithm low level
88
74
  static void
89
75
  ecc200placementbit (int *array, int NR, int NC, int r, int c, int p, char b)
@@ -506,6 +492,7 @@ unsigned char switchcost[E_MAX][E_MAX] = {
506
492
  static char *
507
493
  encmake (int l, unsigned char *s, int *lenp, char exact)
508
494
  {
495
+ VALUE rb_str = NULL;
509
496
  char *encoding = 0;
510
497
  int p = l;
511
498
  char e;
@@ -761,7 +748,7 @@ encmake (int l, unsigned char *s, int *lenp, char exact)
761
748
  enc[p][b].s += enc[p + 1][b].s;
762
749
  //rb_raise(rb_eRuntimeError, "%d:", p); for (e = 0; e < E_MAX; e++) rb_raise(rb_eRuntimeError, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); rb_raise(rb_eRuntimeError, "\n");
763
750
  }
764
- encoding = safemalloc (l + 1);
751
+ encoding = ALLOC_N(char, l + 1);
765
752
  p = 0;
766
753
  {
767
754
  char cur = E_ASCII; // starts ASCII
@@ -873,7 +860,7 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign
873
860
  }
874
861
  if (!matrix->W)
875
862
  {
876
- rb_raise(rb_eRuntimeError, "barcode too long");
863
+ rb_raise(rb_eRuntimeError, "overlong barcode");
877
864
  return 0;
878
865
  }
879
866
  W = matrix->W;
@@ -894,9 +881,9 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign
894
881
  *places;
895
882
  NC = W - 2 * (W / matrix->FW);
896
883
  NR = H - 2 * (H / matrix->FH);
897
- places = safemalloc (NC * NR * sizeof (int));
884
+ places = ALLOC_N(int, NC * NR);
898
885
  ecc200placement (places, NR, NC);
899
- grid = safemalloc (W * H);
886
+ grid = ALLOC_N(char, W * H);
900
887
  memset (grid, 0, W * H);
901
888
  for (y = 0; y < H; y += matrix->FH)
902
889
  {
@@ -931,6 +918,8 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign
931
918
  *Hptr = H;
932
919
  if (encodingptr)
933
920
  *encodingptr = encoding;
921
+ else
922
+ free(encoding); // get rid of this if we aren't returning it
934
923
  if (maxp)
935
924
  *maxp = matrix->bytes;
936
925
  if (eccp)
data/ext/semacode.c CHANGED
@@ -41,7 +41,11 @@ encode_string(semacode_t *semacode, int message_length, char *message)
41
41
  /* deallocate if exists already */
42
42
  if(semacode !=NULL && semacode->data != NULL)
43
43
  free(semacode->data);
44
-
44
+
45
+ /* deallocate if exists already */
46
+ if(semacode !=NULL && semacode->encoding != NULL)
47
+ free(semacode->encoding);
48
+
45
49
  bzero(semacode, sizeof(semacode_t));
46
50
 
47
51
  // work around encoding bug by appending an extra character.
@@ -55,7 +59,7 @@ encode_string(semacode_t *semacode, int message_length, char *message)
55
59
  semacode->data = (char *) iec16022ecc200(
56
60
  &semacode->width,
57
61
  &semacode->height,
58
- NULL,
62
+ &semacode->encoding,
59
63
  message_length,
60
64
  (unsigned char *) message,
61
65
  &semacode->raw_encoded_length,
@@ -81,7 +85,8 @@ semacode_free(semacode_t *semacode)
81
85
  {
82
86
  if(semacode != NULL) {
83
87
  if(semacode->data != NULL)
84
- free(semacode->data);
88
+ free(semacode->encoding);
89
+ free(semacode->data);
85
90
  bzero(semacode, sizeof(semacode));
86
91
  free(semacode);
87
92
  }
@@ -257,6 +262,18 @@ semacode_data(VALUE self)
257
262
  return semacode_grid(semacode);
258
263
  }
259
264
 
265
+ /*
266
+ This returns the encoding string used to create the semacode.
267
+ */
268
+ static VALUE
269
+ semacode_encoded(VALUE self)
270
+ {
271
+ semacode_t *semacode;
272
+ Data_Get_Struct(self, semacode_t, semacode);
273
+
274
+ return rb_str_new2(semacode->encoding);
275
+ }
276
+
260
277
  /*
261
278
  This returns the width of the semacode.
262
279
  */
@@ -347,6 +364,7 @@ Init_semacode_native()
347
364
  rb_define_method(rb_cEncoder, "encode", semacode_encode, 1);
348
365
  rb_define_method(rb_cEncoder, "to_a", semacode_data, 0);
349
366
  rb_define_method(rb_cEncoder, "data", semacode_data, 0);
367
+ rb_define_method(rb_cEncoder, "encoding", semacode_encoded, 0);
350
368
  rb_define_method(rb_cEncoder, "to_s", semacode_to_s, 0);
351
369
  rb_define_method(rb_cEncoder, "to_str", semacode_to_s, 0);
352
370
  rb_define_method(rb_cEncoder, "width", semacode_width, 0);
data/ext/semacode.h CHANGED
@@ -10,6 +10,7 @@ typedef struct semacode_t {
10
10
  int raw_encoded_length;
11
11
  int symbol_capacity;
12
12
  int ecc_bytes;
13
+ char *encoding;
13
14
  char *data;
14
15
  } semacode_t;
15
16
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: semacode
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.1
6
+ version: 0.7.2
7
7
  date: 2007-03-04 00:00:00 +00:00
8
8
  summary: Create semacodes (2D barcodes) using Ruby.
9
9
  require_paths:
@@ -29,16 +29,18 @@ post_install_message:
29
29
  authors:
30
30
  - Guido Sohne
31
31
  files:
32
+ - lib/semacode.rb
32
33
  - ext/extconf.rb
33
34
  - ext/iec16022ecc200.c
34
- - ext/iec16022ecc200.h
35
35
  - ext/reedsol.c
36
- - ext/reedsol.h
37
36
  - ext/semacode.c
37
+ - ext/iec16022ecc200.h
38
+ - ext/reedsol.h
38
39
  - ext/semacode.h
39
- - lib/semacode.rb
40
40
  - tests/test.rb
41
41
  - README
42
+ - CHANGELOG
43
+ - Rakefile
42
44
  test_files:
43
45
  - tests/test.rb
44
46
  rdoc_options: []