pdf-417 0.9.3 → 0.9.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edeff481ba46d80c17fbafacd21012357501bee7
4
- data.tar.gz: bc883efd77890727f27f9edb102cf458eabb8ea0
3
+ metadata.gz: 86b1f485fbbdc619f2ffd1b092c2f96229566265
4
+ data.tar.gz: 99b81ab01e2b8fbae68921347437dd4a9a9d4b2e
5
5
  SHA512:
6
- metadata.gz: 3340691392c4f1b42bb7762e3c3dcd70d59b02844f10e2c5034edc951a415dcf3a460fb7e62f6a307829a3316c89d0183b06b9de6a4f4ea9f1cf95e2c6026e6e
7
- data.tar.gz: f8ab45de6b68d7c0e7203277e6c25df7124fb73ffe7331c8faaf4ef6905244b22492730020e00d99c5d63e4fa7adf611289c46f80268a4553e982671507b428b
6
+ metadata.gz: 751c8ecdc7c66abb2e08073989070e9ba5781274201c450152a2c6154d46586fe5cb1cc6a28c46bf449de1b1f40e3e6b8f1d94d17d9954bf07cdca7edf2e5d1e
7
+ data.tar.gz: d7f28a5a25c8aced0747c9c7ebf0f412f51ca963cc98e0f71d45862d594371e2d4ea1b1e8384752eda0975cfbfbb2281862ac7e270673fa8d0cb81a351f600b1
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.4
data/README.md CHANGED
@@ -20,6 +20,11 @@ The above example produces:
20
20
 
21
21
  ![Sample PDF417 barcode](/sample.png?raw=true "Sample PDF417 barcode")
22
22
 
23
+ ## Inspiration
24
+
25
+ * https://github.com/bkuzmic/pdf417-js
26
+ * http://www.tcpdf.org/
27
+
23
28
  ## License
24
29
 
25
30
  This software is licensed under terms of the MIT License.
@@ -1,7 +1,7 @@
1
1
  require "constants"
2
2
 
3
3
  module Enumerable
4
- def use
4
+ def probe
5
5
  out = nil
6
6
  each_with_index {|val, i| out = yield(val, i) and break}
7
7
  out
@@ -10,8 +10,8 @@ end
10
10
 
11
11
  class PDF417
12
12
  def initialize(str=nil)
13
- @tall = 4 # row height in module units
14
- @wbyh = 2 # barcode's width/height
13
+ @tall = 2 # row height in module units
14
+ @wbyh = 3 # barcode's width/height
15
15
  @pads = 2 # padding around barcode
16
16
 
17
17
  @str = str # string to encode
@@ -21,25 +21,24 @@ class PDF417
21
21
 
22
22
  def encode(str=nil)
23
23
  str = str ? (@str = str) : @str
24
- all = str.split(//)
24
+ all = str.split('')
25
25
  max = all.size - 1
26
- use = 0
27
- ary = TEXT_MODE[use]
28
-
29
- # map to the four text submodes
30
- out = all.map.with_index.inject([]) do |out,(chr,pos)|
31
- if val = ary.index(ord = chr.ord)
32
- out << val
33
- elsif now = TEXT_MODE.use {|chk, now| now if (now != use) && (val = chk.index(ord)) }
34
- if (pos == max || ary.index(all[pos + 1].ord)) && (now == 3 || (now == 0 && use == 1))
35
- out.push(now == 3 ? 29 : 27) # shift modes only for the next character
36
- else
37
- out.concat(TEXT_JUMP["#{use}#{now}"]) # jump to new mode
38
- ary = TEXT_MODE[use = now]
26
+ ary = TEXT_MODE[cur = nxt = 0]
27
+ out = []
28
+
29
+ # map to text submodes
30
+ all.each_with_index do |chr, pos|
31
+ unless val = ary.index(ord = chr.ord)
32
+ if nxt = TEXT_MODE.probe {|row, nxt| nxt if (nxt != cur) && (val = row.index(ord)) }
33
+ if (nxt == 3 || (nxt == 0 && cur == 1)) && (pos == max || ary.index(all[pos + 1].ord))
34
+ out.push(nxt == 3 ? 29 : 27) # only shift modes for the next character
35
+ else
36
+ out.concat(TEXT_JUMP["#{cur}#{nxt}"]) # jump to new mode
37
+ ary = TEXT_MODE[cur = nxt]
38
+ end
39
39
  end
40
- out << val
41
40
  end
42
- out
41
+ out.push val
43
42
  end
44
43
  out.push(29) unless out.size.even?
45
44
 
@@ -135,14 +134,14 @@ class PDF417
135
134
  end]) + rbar
136
135
 
137
136
  # add a row
138
- all = out.split(//); @tall.times { bar << all }
137
+ @tall.times { bar << out }
139
138
 
140
139
  # next cluster
141
140
  cid = (cid += 1) % 3
142
141
  end
143
142
 
144
143
  # top and bottom quiet zones
145
- zone = ['0'] * (col * 17 + 69 + 2 * @pads) # pad, start, lri, cols, rri, stop, pad
144
+ zone = '0' * (col * 17 + 69 + 2 * @pads) # pad, start, lri, cols, rri, stop, pad
146
145
  @pads.times { bar.unshift zone } # top quiet zone
147
146
  @pads.times { bar.push zone } # bottom quiet zone
148
147
 
@@ -166,7 +165,7 @@ class PDF417
166
165
  canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)
167
166
 
168
167
  x, y = opts[:margin], opts[:margin]
169
- dots = ary.map {|l| l.map {|c| c == '1' }}
168
+ dots = ary.map {|l| l.split('').map {|c| c == '1' }}
170
169
  dots.each do |line|
171
170
  line.each do |bar|
172
171
  if bar
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pdf-417"
5
- s.version = "0.9.3"
5
+ s.version = "0.9.4"
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary = "Generate PDF-417 barcodes"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-417
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.6.11
61
+ rubygems_version: 2.6.13
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Generate PDF-417 barcodes