pdf-417 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +5 -0
- data/lib/pdf-417.rb +21 -22
- data/pdf-417.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b1f485fbbdc619f2ffd1b092c2f96229566265
|
4
|
+
data.tar.gz: 99b81ab01e2b8fbae68921347437dd4a9a9d4b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 751c8ecdc7c66abb2e08073989070e9ba5781274201c450152a2c6154d46586fe5cb1cc6a28c46bf449de1b1f40e3e6b8f1d94d17d9954bf07cdca7edf2e5d1e
|
7
|
+
data.tar.gz: d7f28a5a25c8aced0747c9c7ebf0f412f51ca963cc98e0f71d45862d594371e2d4ea1b1e8384752eda0975cfbfbb2281862ac7e270673fa8d0cb81a351f600b1
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.4
|
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.
|
data/lib/pdf-417.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "constants"
|
2
2
|
|
3
3
|
module Enumerable
|
4
|
-
def
|
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 =
|
14
|
-
@wbyh =
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# map to
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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 =
|
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
|
data/pdf-417.gemspec
CHANGED
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.
|
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-
|
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.
|
61
|
+
rubygems_version: 2.6.13
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Generate PDF-417 barcodes
|