barby-chunky_png 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +29 -0
- data/bin/barby +41 -0
- data/lib/barby/barcode/bookland.rb +37 -0
- data/lib/barby/barcode/code_128.rb +410 -0
- data/lib/barby/barcode/code_25.rb +193 -0
- data/lib/barby/barcode/code_25_iata.rb +23 -0
- data/lib/barby/barcode/code_25_interleaved.rb +73 -0
- data/lib/barby/barcode/code_39.rb +233 -0
- data/lib/barby/barcode/code_93.rb +230 -0
- data/lib/barby/barcode/data_matrix.rb +46 -0
- data/lib/barby/barcode/ean_13.rb +178 -0
- data/lib/barby/barcode/ean_8.rb +32 -0
- data/lib/barby/barcode/gs1_128.rb +42 -0
- data/lib/barby/barcode/pdf_417.rb +76 -0
- data/lib/barby/barcode/qr_code.rb +101 -0
- data/lib/barby/barcode.rb +116 -0
- data/lib/barby/outputter/ascii_outputter.rb +41 -0
- data/lib/barby/outputter/cairo_outputter.rb +185 -0
- data/lib/barby/outputter/pdfwriter_outputter.rb +83 -0
- data/lib/barby/outputter/png_outputter.rb +97 -0
- data/lib/barby/outputter/prawn_outputter.rb +99 -0
- data/lib/barby/outputter/rmagick_outputter.rb +126 -0
- data/lib/barby/outputter/svg_outputter.rb +225 -0
- data/lib/barby/outputter.rb +132 -0
- data/lib/barby/vendor.rb +3 -0
- data/lib/barby/version.rb +9 -0
- data/lib/barby.rb +17 -0
- data/vendor/Pdf417lib-java-0.91/lib/Pdf417lib.jar +0 -0
- data/vendor/Pdf417lib-java-0.91/lib/Pdf417lib.java +1471 -0
- data/vendor/rqrcode/CHANGELOG +29 -0
- data/vendor/rqrcode/COPYING +19 -0
- data/vendor/rqrcode/README +98 -0
- data/vendor/rqrcode/Rakefile +65 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/array/behavior.rb +9 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/array.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/integer/bitwise.rb +11 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/integer.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_8bit_byte.rb +37 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb +56 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb +421 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_math.rb +63 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_polynomial.rb +78 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_rs_block.rb +313 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_util.rb +254 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode.rb +4 -0
- data/vendor/rqrcode/lib/rqrcode.rb +13 -0
- data/vendor/rqrcode/test/runtest.rb +78 -0
- data/vendor/rqrcode/test/test_data.rb +21 -0
- metadata +129 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'barby/barcode'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
|
5
|
+
class Code93 < Barcode1D
|
6
|
+
|
7
|
+
SHIFT_DOLLAR = "\301" # ($)
|
8
|
+
SHIFT_PERCENT = "\302" # (%)
|
9
|
+
SHIFT_SLASH = "\303" # (/)
|
10
|
+
SHIFT_PLUS = "\304" # (+)
|
11
|
+
|
12
|
+
SHIFT_CHARACTERS = [SHIFT_DOLLAR, SHIFT_PERCENT, SHIFT_SLASH, SHIFT_PLUS]
|
13
|
+
|
14
|
+
ENCODINGS = {
|
15
|
+
"0" => "100010100", "1" => "101001000",
|
16
|
+
"2" => "101000100", "3" => "101000010",
|
17
|
+
"4" => "100101000", "5" => "100100100",
|
18
|
+
"6" => "100100010", "7" => "101010000",
|
19
|
+
"8" => "100010010", "9" => "100001010",
|
20
|
+
"A" => "110101000", "B" => "110100100",
|
21
|
+
"C" => "110100010", "D" => "110010100",
|
22
|
+
"E" => "110010010", "F" => "110001010",
|
23
|
+
"G" => "101101000", "H" => "101100100",
|
24
|
+
"I" => "101100010", "J" => "100110100",
|
25
|
+
"K" => "100011010", "L" => "101011000",
|
26
|
+
"M" => "101001100", "N" => "101000110",
|
27
|
+
"O" => "100101100", "P" => "100010110",
|
28
|
+
"Q" => "110110100", "R" => "110110010",
|
29
|
+
"S" => "110101100", "T" => "110100110",
|
30
|
+
"U" => "110010110", "V" => "110011010",
|
31
|
+
"W" => "101101100", "X" => "101100110",
|
32
|
+
"Y" => "100110110", "Z" => "100111010",
|
33
|
+
"-" => "100101110", "." => "111010100",
|
34
|
+
" " => "111010010", "$" => "111001010",
|
35
|
+
"/" => "101101110", "+" => "101110110",
|
36
|
+
"%" => "110101110",
|
37
|
+
SHIFT_DOLLAR => "100100110",
|
38
|
+
SHIFT_PERCENT => "111011010",
|
39
|
+
SHIFT_SLASH => "111010110",
|
40
|
+
SHIFT_PLUS => "100110010"
|
41
|
+
}
|
42
|
+
|
43
|
+
EXTENDED_MAPPING = {
|
44
|
+
"\000" => "\302U", " " => " ", "@" => "\302V", "`" => "\302W",
|
45
|
+
"\001" => "\301A", "!" => "\303A", "A" => "A", "a" => "\304A",
|
46
|
+
"\002" => "\301B", '"' => "\303B", "B" => "B", "b" => "\304B",
|
47
|
+
"\003" => "\301C", "#" => "\303C", "C" => "C", "c" => "\304C",
|
48
|
+
"\004" => "\301D", "$" => "\303D", "D" => "D", "d" => "\304D",
|
49
|
+
"\005" => "\301E", "%" => "\303E", "E" => "E", "e" => "\304E",
|
50
|
+
"\006" => "\301F", "&" => "\303F", "F" => "F", "f" => "\304F",
|
51
|
+
"\007" => "\301G", "'" => "\303G", "G" => "G", "g" => "\304G",
|
52
|
+
"\010" => "\301H", "(" => "\303H", "H" => "H", "h" => "\304H",
|
53
|
+
"\011" => "\301I", ")" => "\303I", "I" => "I", "i" => "\304I",
|
54
|
+
"\012" => "\301J", "*" => "\303J", "J" => "J", "j" => "\304J",
|
55
|
+
"\013" => "\301K", "/" => "\303K", "K" => "K", "k" => "\304K",
|
56
|
+
"\014" => "\301L", "," => "\303L", "L" => "L", "l" => "\304L",
|
57
|
+
"\015" => "\301M", "-" => "-", "M" => "M", "m" => "\304M",
|
58
|
+
"\016" => "\301N", "." => ".", "N" => "N", "n" => "\304N",
|
59
|
+
"\017" => "\301O", "+" => "\303O", "O" => "O", "o" => "\304O",
|
60
|
+
"\020" => "\301P", "0" => "0", "P" => "P", "p" => "\304P",
|
61
|
+
"\021" => "\301Q", "1" => "1", "Q" => "Q", "q" => "\304Q",
|
62
|
+
"\022" => "\301R", "2" => "2", "R" => "R", "r" => "\304R",
|
63
|
+
"\023" => "\301S", "3" => "3", "S" => "S", "s" => "\304S",
|
64
|
+
"\024" => "\301T", "4" => "4", "T" => "T", "t" => "\304T",
|
65
|
+
"\025" => "\301U", "5" => "5", "U" => "U", "u" => "\304U",
|
66
|
+
"\026" => "\301V", "6" => "6", "V" => "V", "v" => "\304V",
|
67
|
+
"\027" => "\301W", "7" => "7", "W" => "W", "w" => "\304W",
|
68
|
+
"\030" => "\301X", "8" => "8", "X" => "X", "x" => "\304X",
|
69
|
+
"\031" => "\301Y", "9" => "9", "Y" => "Y", "y" => "\304Y",
|
70
|
+
"\032" => "\301Z", ":" => "\303Z", "Z" => "Z", "z" => "\304Z",
|
71
|
+
"\033" => "\302A", ";" => "\302F", "[" => "\302K", "{" => "\302P",
|
72
|
+
"\034" => "\302B", "<" => "\302G", "\\" => "\302L", "|" => "\302Q",
|
73
|
+
"\035" => "\302C", "=" => "\302H", "]" => "\302M", "}" => "\302R",
|
74
|
+
"\036" => "\302D", ">" => "\302I", "^" => "\302N", "~" => "\302S",
|
75
|
+
"\037" => "\302E", "?" => "\302J", "_" => "\302O", "\177" => "\302T"
|
76
|
+
}
|
77
|
+
|
78
|
+
EXTENDED_CHARACTERS = EXTENDED_MAPPING.keys - ENCODINGS.keys
|
79
|
+
|
80
|
+
CHARACTERS = {
|
81
|
+
0 => "0", 1 => "1", 2 => "2", 3 => "3",
|
82
|
+
4 => "4", 5 => "5", 6 => "6", 7 => "7",
|
83
|
+
8 => "8", 9 => "9", 10 => "A", 11 => "B",
|
84
|
+
12 => "C", 13 => "D", 14 => "E", 15 => "F",
|
85
|
+
16 => "G", 17 => "H", 18 => "I", 19 => "J",
|
86
|
+
20 => "K", 21 => "L", 22 => "M", 23 => "N",
|
87
|
+
24 => "O", 25 => "P", 26 => "Q", 27 => "R",
|
88
|
+
28 => "S", 29 => "T", 30 => "U", 31 => "V",
|
89
|
+
32 => "W", 33 => "X", 34 => "Y", 35 => "Z",
|
90
|
+
36 => "-", 37 => ".", 38 => " ", 39 => "$",
|
91
|
+
40 => "/", 41 => "+", 42 => "%",
|
92
|
+
43 => SHIFT_DOLLAR, 44 => SHIFT_PERCENT,
|
93
|
+
45 => SHIFT_SLASH, 46 => SHIFT_PLUS
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUES = CHARACTERS.invert
|
97
|
+
|
98
|
+
START_ENCODING = '101011110' # *
|
99
|
+
STOP_ENCODING = '101011110'
|
100
|
+
TERMINATE_ENCODING = '1'
|
101
|
+
|
102
|
+
attr_accessor :data
|
103
|
+
|
104
|
+
|
105
|
+
def initialize(data)
|
106
|
+
self.data = data
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def extended?
|
111
|
+
raw_characters.any?{|c| EXTENDED_CHARACTERS.include?(c) }
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def raw_characters
|
116
|
+
data.split(//)
|
117
|
+
end
|
118
|
+
|
119
|
+
def characters
|
120
|
+
raw_characters.map{|c| EXTENDED_MAPPING[c].split(//) }.flatten
|
121
|
+
end
|
122
|
+
|
123
|
+
def encoded_characters
|
124
|
+
characters.map{|c| ENCODINGS[c] }
|
125
|
+
end
|
126
|
+
alias character_encodings encoded_characters
|
127
|
+
|
128
|
+
|
129
|
+
def start_encoding
|
130
|
+
START_ENCODING
|
131
|
+
end
|
132
|
+
|
133
|
+
#The stop encoding includes the termination bar
|
134
|
+
def stop_encoding
|
135
|
+
STOP_ENCODING+TERMINATE_ENCODING
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def encoding
|
140
|
+
start_encoding+data_encoding_with_checksums+stop_encoding
|
141
|
+
end
|
142
|
+
|
143
|
+
def data_encoding
|
144
|
+
character_encodings.join
|
145
|
+
end
|
146
|
+
|
147
|
+
def data_encoding_with_checksums
|
148
|
+
(character_encodings + checksum_encodings).join
|
149
|
+
end
|
150
|
+
|
151
|
+
def checksum_encodings
|
152
|
+
checksum_characters.map{|c| ENCODINGS[c] }
|
153
|
+
end
|
154
|
+
|
155
|
+
def checksum_encoding
|
156
|
+
checksum_encodings.join
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
def checksums
|
161
|
+
[c_checksum, k_checksum]
|
162
|
+
end
|
163
|
+
|
164
|
+
def checksum_characters
|
165
|
+
checksums.map{|s| CHARACTERS[s] }
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
#Returns the values used for computing the C checksum
|
170
|
+
#in the "right" order (i.e. reversed)
|
171
|
+
def checksum_values
|
172
|
+
characters.map{|c| VALUES[c] }.reverse
|
173
|
+
end
|
174
|
+
|
175
|
+
#Returns the normal checksum plus the c_checksum
|
176
|
+
#This is used for calculating the k_checksum
|
177
|
+
def checksum_values_with_c_checksum
|
178
|
+
[c_checksum] + checksum_values
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
#Calculates the C checksum based on checksum_values
|
183
|
+
def c_checksum
|
184
|
+
sum = 0
|
185
|
+
checksum_values.each_with_index do |value, index|
|
186
|
+
sum += ((index % 20) + 1) * value
|
187
|
+
end
|
188
|
+
sum % 47
|
189
|
+
end
|
190
|
+
|
191
|
+
def c_checksum_character
|
192
|
+
CHARACTERS[c_checksum]
|
193
|
+
end
|
194
|
+
|
195
|
+
def c_checksum_encoding
|
196
|
+
ENCODINGS[c_checksum_character]
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
#Calculates the K checksum based on checksum_values_with_c_checksum
|
201
|
+
def k_checksum
|
202
|
+
sum = 0
|
203
|
+
checksum_values_with_c_checksum.each_with_index do |value, index|
|
204
|
+
sum += ((index % 15) + 1) * value
|
205
|
+
end
|
206
|
+
sum % 47
|
207
|
+
end
|
208
|
+
|
209
|
+
def k_checksum_character
|
210
|
+
CHARACTERS[k_checksum]
|
211
|
+
end
|
212
|
+
|
213
|
+
def k_checksum_encoding
|
214
|
+
ENCODINGS[k_checksum_character]
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
def valid?
|
219
|
+
characters.all?{|c| ENCODINGS.include?(c) }
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
def to_s
|
224
|
+
data
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'semacode'
|
2
|
+
require 'barby/barcode'
|
3
|
+
|
4
|
+
module Barby
|
5
|
+
|
6
|
+
|
7
|
+
#Uses the semacode library (gem install semacode) to encode DataMatrix barcodes
|
8
|
+
class DataMatrix < Barcode2D
|
9
|
+
|
10
|
+
attr_accessor :data
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(data)
|
14
|
+
self.data = data
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def data=(data)
|
19
|
+
@data = data
|
20
|
+
@encoder = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def encoder
|
24
|
+
@encoder ||= ::DataMatrix::Encoder.new(data)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def encoding
|
29
|
+
encoder.data.map{|a| a.map{|b| b ? '1' : '0' }.join }
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def semacode?
|
34
|
+
#TODO: Not sure if this is right
|
35
|
+
data =~ /^http:\/\//
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
data
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'barby/barcode'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
|
5
|
+
#EAN-13, aka UPC-A, barcodes are the ones you can see at your local
|
6
|
+
#supermarket, in your house and, well, everywhere..
|
7
|
+
#
|
8
|
+
#To use this for a UPC barcode, just add a 0 to the front
|
9
|
+
class EAN13 < Barcode1D
|
10
|
+
|
11
|
+
LEFT_ENCODINGS_ODD = {
|
12
|
+
0 => '0001101', 1 => '0011001', 2 => '0010011',
|
13
|
+
3 => '0111101', 4 => '0100011', 5 => '0110001',
|
14
|
+
6 => '0101111', 7 => '0111011', 8 => '0110111',
|
15
|
+
9 => '0001011'
|
16
|
+
}
|
17
|
+
|
18
|
+
LEFT_ENCODINGS_EVEN = {
|
19
|
+
0 => '0100111', 1 => '0110011', 2 => '0011011',
|
20
|
+
3 => '0100001', 4 => '0011101', 5 => '0111001',
|
21
|
+
6 => '0000101', 7 => '0010001', 8 => '0001001',
|
22
|
+
9 => '0010111'
|
23
|
+
}
|
24
|
+
|
25
|
+
RIGHT_ENCODINGS = {
|
26
|
+
0 => '1110010', 1 => '1100110', 2 => '1101100',
|
27
|
+
3 => '1000010', 4 => '1011100', 5 => '1001110',
|
28
|
+
6 => '1010000', 7 => '1000100', 8 => '1001000',
|
29
|
+
9 => '1110100'
|
30
|
+
}
|
31
|
+
|
32
|
+
#Describes whether the left-hand encoding should use
|
33
|
+
#LEFT_ENCODINGS_ODD or LEFT_ENCODINGS_EVEN, based on the
|
34
|
+
#first digit in the number system (and the barcode as a whole)
|
35
|
+
LEFT_PARITY_MAPS = {
|
36
|
+
0 => [:odd, :odd, :odd, :odd, :odd, :odd], #UPC-A
|
37
|
+
1 => [:odd, :odd, :even, :odd, :even, :even],
|
38
|
+
2 => [:odd, :odd, :even, :even, :odd, :even],
|
39
|
+
3 => [:odd, :odd, :even, :even, :even, :odd],
|
40
|
+
4 => [:odd, :even, :odd, :odd, :even, :even],
|
41
|
+
5 => [:odd, :even, :even, :odd, :odd, :even],
|
42
|
+
6 => [:odd, :even, :even, :even, :odd, :odd],
|
43
|
+
7 => [:odd, :even, :odd, :even, :odd, :even],
|
44
|
+
8 => [:odd, :even, :odd, :even, :even, :odd],
|
45
|
+
9 => [:odd, :even, :even, :odd, :even, :odd]
|
46
|
+
}
|
47
|
+
|
48
|
+
#These are the lines that "stick down" in the graphical representation
|
49
|
+
START = '101'
|
50
|
+
CENTER = '01010'
|
51
|
+
STOP = '101'
|
52
|
+
|
53
|
+
#EAN-13 barcodes have 12 digits + check digit
|
54
|
+
FORMAT = /^\d{12}$/
|
55
|
+
|
56
|
+
attr_accessor :data
|
57
|
+
|
58
|
+
|
59
|
+
def initialize(data)
|
60
|
+
self.data = data
|
61
|
+
raise ArgumentError, 'data not valid' unless valid?
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def characters
|
66
|
+
data.split(//)
|
67
|
+
end
|
68
|
+
|
69
|
+
def numbers
|
70
|
+
characters.map{|s| s.to_i }
|
71
|
+
end
|
72
|
+
|
73
|
+
def odd_and_even_numbers
|
74
|
+
alternater = false
|
75
|
+
numbers.reverse.partition{ alternater = !alternater }
|
76
|
+
end
|
77
|
+
|
78
|
+
#Numbers that are encoded to the left of the center
|
79
|
+
#The first digit is not included
|
80
|
+
def left_numbers
|
81
|
+
numbers[1,6]
|
82
|
+
end
|
83
|
+
|
84
|
+
#Numbers that are encoded to the right of the center
|
85
|
+
#The checksum is included here
|
86
|
+
def right_numbers
|
87
|
+
numbers_with_checksum[7,6]
|
88
|
+
end
|
89
|
+
|
90
|
+
def numbers_with_checksum
|
91
|
+
numbers + [checksum]
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def data_with_checksum
|
96
|
+
data + checksum.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def left_encodings
|
101
|
+
left_parity_map.zip(left_numbers).map do |parity,number|
|
102
|
+
parity == :odd ? LEFT_ENCODINGS_ODD[number] : LEFT_ENCODINGS_EVEN[number]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def right_encodings
|
107
|
+
right_numbers.map{|n| RIGHT_ENCODINGS[n] }
|
108
|
+
end
|
109
|
+
|
110
|
+
def left_encoding
|
111
|
+
left_encodings.join
|
112
|
+
end
|
113
|
+
|
114
|
+
def right_encoding
|
115
|
+
right_encodings.join
|
116
|
+
end
|
117
|
+
|
118
|
+
def encoding
|
119
|
+
start_encoding+left_encoding+center_encoding+right_encoding+stop_encoding
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#The parities to use for encoding left-hand numbers
|
124
|
+
def left_parity_map
|
125
|
+
LEFT_PARITY_MAPS[numbers.first]
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def weighted_sum
|
130
|
+
odds, evens = odd_and_even_numbers
|
131
|
+
odds.map!{|n| n * 3 }
|
132
|
+
sum = (odds+evens).inject(0){|s,n| s+n }
|
133
|
+
end
|
134
|
+
|
135
|
+
#Mod10
|
136
|
+
def checksum
|
137
|
+
mod = weighted_sum % 10
|
138
|
+
mod.zero? ? 0 : 10-mod
|
139
|
+
end
|
140
|
+
|
141
|
+
def checksum_encoding
|
142
|
+
RIGHT_ENCODINGS[checksum]
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
def valid?
|
147
|
+
data =~ FORMAT
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def to_s
|
152
|
+
data_with_checksum
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
#Is this a UPC-A barcode?
|
157
|
+
#UPC barcodes are EAN codes that start with 0
|
158
|
+
def upc?
|
159
|
+
numbers.first.zero?
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def start_encoding
|
164
|
+
START
|
165
|
+
end
|
166
|
+
|
167
|
+
def center_encoding
|
168
|
+
CENTER
|
169
|
+
end
|
170
|
+
|
171
|
+
def stop_encoding
|
172
|
+
STOP
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'barby/barcode/ean_13'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
|
5
|
+
#EAN-8 is a sub-set of EAN-13, with only 7 (8) digits
|
6
|
+
class EAN8 < EAN13
|
7
|
+
|
8
|
+
FORMAT = /^\d{7}$/
|
9
|
+
|
10
|
+
|
11
|
+
def left_numbers
|
12
|
+
numbers[0,4]
|
13
|
+
end
|
14
|
+
|
15
|
+
def right_numbers
|
16
|
+
numbers_with_checksum[4,4]
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
#Left-hand digits are all encoded using odd parity
|
21
|
+
def left_parity_map
|
22
|
+
[:odd, :odd, :odd, :odd]
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def valid?
|
27
|
+
data =~ FORMAT
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'barby/barcode/code_128'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
|
5
|
+
|
6
|
+
#AKA EAN-128, UCC-128
|
7
|
+
class GS1128 < Code128
|
8
|
+
|
9
|
+
attr_accessor :application_identifier
|
10
|
+
|
11
|
+
def initialize(data, type, ai)
|
12
|
+
self.application_identifier = ai
|
13
|
+
super(data, type)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
#TODO: Not sure this is entirely right
|
18
|
+
def data
|
19
|
+
FNC1+application_identifier+super
|
20
|
+
end
|
21
|
+
|
22
|
+
def partial_data
|
23
|
+
@data
|
24
|
+
end
|
25
|
+
|
26
|
+
def application_identifier_number
|
27
|
+
values[application_identifier]
|
28
|
+
end
|
29
|
+
|
30
|
+
def application_identifier_encoding
|
31
|
+
encodings[application_identifier_number]
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"(#{application_identifier}) #{partial_data}"
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'barby/barcode'
|
2
|
+
require 'java'
|
3
|
+
require 'Pdf417lib'
|
4
|
+
import 'Pdf417lib'
|
5
|
+
|
6
|
+
module Barby
|
7
|
+
class Pdf417 < Barcode2D
|
8
|
+
DEFAULT_OPTIONS = {
|
9
|
+
:options => 0,
|
10
|
+
:y_height => 3,
|
11
|
+
:aspect_ratio => 0.5,
|
12
|
+
:error_level => 0,
|
13
|
+
:len_codewords => 0,
|
14
|
+
:code_rows => 0,
|
15
|
+
:code_columns => 0
|
16
|
+
}
|
17
|
+
|
18
|
+
# Creates a new Pdf417 barcode. The +options+ argument
|
19
|
+
# can use the same keys as DEFAULT_OPTIONS. Please consult
|
20
|
+
# the source code of Pdf417lib.java for details about values
|
21
|
+
# that can be used.
|
22
|
+
def initialize(data, options={})
|
23
|
+
@pdf417 = Java::Pdf417lib.new
|
24
|
+
self.data = data
|
25
|
+
DEFAULT_OPTIONS.merge(options).each{|k,v| send("#{k}=", v) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def options=(options)
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
def y_height=(y_height)
|
33
|
+
@pdf417.setYHeight(y_height)
|
34
|
+
end
|
35
|
+
|
36
|
+
def aspect_ratio=(aspect_ratio)
|
37
|
+
@pdf417.setAspectRatio(aspect_ratio)
|
38
|
+
end
|
39
|
+
|
40
|
+
def error_level=(error_level)
|
41
|
+
@pdf417.setErrorLevel(error_level)
|
42
|
+
end
|
43
|
+
|
44
|
+
def len_codewords=(len_codewords)
|
45
|
+
@pdf417.setLenCodewords(len_codewords)
|
46
|
+
end
|
47
|
+
|
48
|
+
def code_rows=(code_rows)
|
49
|
+
@pdf417.setCodeRows(code_rows)
|
50
|
+
end
|
51
|
+
|
52
|
+
def code_columns=(code_columns)
|
53
|
+
@pdf417.setCodeColumns(code_columns)
|
54
|
+
end
|
55
|
+
|
56
|
+
def data=(data)
|
57
|
+
@pdf417.setText(data)
|
58
|
+
end
|
59
|
+
|
60
|
+
def encoding
|
61
|
+
@pdf417.paintCode()
|
62
|
+
|
63
|
+
cols = (@pdf417.getBitColumns() - 1) / 8 + 1
|
64
|
+
enc = []
|
65
|
+
row = nil
|
66
|
+
@pdf417.getOutBits.each_with_index do |byte, n|
|
67
|
+
if n%cols == 0
|
68
|
+
row = ""
|
69
|
+
enc << row
|
70
|
+
end
|
71
|
+
row << sprintf("%08b", (byte & 0xff) | 0x100)
|
72
|
+
end
|
73
|
+
enc
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|