barby 0.6.2 → 0.6.8
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 +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG +8 -0
- data/Gemfile +5 -0
- data/README.md +108 -0
- data/Rakefile +15 -0
- data/barby.gemspec +31 -0
- data/lib/barby/barcode.rb +3 -3
- data/lib/barby/barcode/bookland.rb +0 -1
- data/lib/barby/barcode/codabar.rb +82 -0
- data/lib/barby/barcode/code_128.rb +22 -20
- data/lib/barby/barcode/code_25.rb +6 -3
- data/lib/barby/barcode/code_25_interleaved.rb +2 -2
- data/lib/barby/barcode/code_39.rb +2 -1
- data/lib/barby/barcode/data_matrix.rb +1 -1
- data/lib/barby/barcode/ean_13.rb +1 -1
- data/lib/barby/barcode/gs1_128.rb +5 -1
- data/lib/barby/barcode/qr_code.rb +2 -1
- data/lib/barby/outputter.rb +1 -1
- data/lib/barby/outputter/cairo_outputter.rb +16 -3
- data/lib/barby/outputter/png_outputter.rb +43 -7
- data/lib/barby/outputter/prawn_outputter.rb +12 -4
- data/lib/barby/outputter/rmagick_outputter.rb +43 -11
- data/lib/barby/outputter/svg_outputter.rb +11 -13
- data/lib/barby/version.rb +2 -2
- data/test/barcodes.rb +20 -0
- data/test/bookland_test.rb +54 -0
- data/test/codabar_test.rb +58 -0
- data/test/code_128_test.rb +470 -0
- data/test/code_25_iata_test.rb +19 -0
- data/test/code_25_interleaved_test.rb +116 -0
- data/test/code_25_test.rb +110 -0
- data/test/code_39_test.rb +210 -0
- data/test/code_93_test.rb +144 -0
- data/test/data_matrix_test.rb +30 -0
- data/test/ean13_test.rb +169 -0
- data/test/ean8_test.rb +100 -0
- data/test/outputter/cairo_outputter_test.rb +129 -0
- data/test/outputter/html_outputter_test.rb +68 -0
- data/test/outputter/pdfwriter_outputter_test.rb +37 -0
- data/test/outputter/png_outputter_test.rb +49 -0
- data/test/outputter/prawn_outputter_test.rb +79 -0
- data/test/outputter/rmagick_outputter_test.rb +83 -0
- data/test/outputter/svg_outputter_test.rb +89 -0
- data/test/outputter_test.rb +134 -0
- data/test/pdf_417_test.rb +45 -0
- data/test/qr_code_test.rb +78 -0
- data/test/test_helper.rb +24 -0
- data/test/upc_supplemental_test.rb +109 -0
- metadata +160 -19
- data/README +0 -93
- data/lib/barby/outputter/point_matrix.rb +0 -211
data/README
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
*** NEW REQUIRE POLICY ***
|
2
|
-
|
3
|
-
Barcode symbologies are no longer requires automatically, so you'll have to
|
4
|
-
require the ones you need. If you need EAN-13, require 'barby/barcode/ean_13'.
|
5
|
-
Full list of symbologies and filenames below.
|
6
|
-
|
7
|
-
***
|
8
|
-
|
9
|
-
For more information, check out the Barby wiki at https://github.com/toretore/barby/wiki
|
10
|
-
|
11
|
-
Barby is a Ruby library that generates barcodes in a variety of symbologies.
|
12
|
-
Its functionality is split into barcode and "outputter" objects. Barcode
|
13
|
-
objects turn data into a binary representation for a given symbology.
|
14
|
-
Outputters then take this representation and turns it into images, PDF, etc.
|
15
|
-
|
16
|
-
You can easily add a symbology without having to worry about graphical
|
17
|
-
representation. If it can be represented as the usual 1D or 2D matrix of
|
18
|
-
lines or squares, outputters will do that for you.
|
19
|
-
|
20
|
-
Likewise, you can easily add an outputter for a format that doesn't have one
|
21
|
-
yet, and it will work with all existing symbologies.
|
22
|
-
|
23
|
-
See Barby::Barcode and Barby::Outputter for more information.
|
24
|
-
|
25
|
-
require 'barby'
|
26
|
-
require 'barby/barcode/code_128'
|
27
|
-
require 'barby/outputter/ascii_outputter'
|
28
|
-
|
29
|
-
barcode = Barby::Code128B.new('BARBY')
|
30
|
-
|
31
|
-
puts barcode.to_ascii #Implicitly uses the AsciiOutputter
|
32
|
-
|
33
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
34
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
35
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
36
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
37
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
38
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
39
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
40
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
41
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
42
|
-
## # # # # ## # # ## ## # ### # # ## ### ## # ## ### ### ## ### # ##
|
43
|
-
B A R B Y
|
44
|
-
|
45
|
-
|
46
|
-
Supported symbologies:
|
47
|
-
|
48
|
-
Name - filename - dependencies
|
49
|
-
|
50
|
-
require 'barby/barcode/<filename>'
|
51
|
-
|
52
|
-
* Code 25 - code_25
|
53
|
-
* Interleaved - code_25_interleaved
|
54
|
-
* IATA - code_25_iata
|
55
|
-
* Code 39 - code_39
|
56
|
-
* Code 93 - code_93
|
57
|
-
* Code 128 - code_128
|
58
|
-
* GS1 128 - gs1_128
|
59
|
-
* EAN-13 - ean_13
|
60
|
-
* Bookland - bookland
|
61
|
-
* UPC-A - ean_13
|
62
|
-
* EAN-8 - ean_8
|
63
|
-
* UPC/EAN supplemental, 2 & 5 digits - upc_supplemental
|
64
|
-
|
65
|
-
* QR Code - qr_code - rqrcode
|
66
|
-
* DataMatrix (Semacode) - data_matrix - semacode
|
67
|
-
* PDF417 - pdf_417 - java (JRuby)
|
68
|
-
|
69
|
-
|
70
|
-
Formats supported by outputters:
|
71
|
-
|
72
|
-
* Text (mostly for testing)
|
73
|
-
* PNG, JPEG, GIF
|
74
|
-
* PS, EPS
|
75
|
-
* SVG
|
76
|
-
* PDF
|
77
|
-
* HTML
|
78
|
-
|
79
|
-
|
80
|
-
Outputters:
|
81
|
-
|
82
|
-
filename (dependencies)
|
83
|
-
|
84
|
-
require 'barby/outputter/<filename>_outputter'
|
85
|
-
|
86
|
-
* ascii
|
87
|
-
* cairo (cairo)
|
88
|
-
* html
|
89
|
-
* pdfwriter
|
90
|
-
* png (chunky_png)
|
91
|
-
* prawn (prawn)
|
92
|
-
* rmagick (RMagick)
|
93
|
-
* svg
|
@@ -1,211 +0,0 @@
|
|
1
|
-
require 'barby/outputter'
|
2
|
-
|
3
|
-
module Barby
|
4
|
-
|
5
|
-
class Outputter
|
6
|
-
|
7
|
-
|
8
|
-
#A collection of rows - an array of arrays
|
9
|
-
class PointMatrix < Array
|
10
|
-
|
11
|
-
DEFAULT_XDIM = 1.0
|
12
|
-
DEFAULT_YDIM = 1.0
|
13
|
-
|
14
|
-
attr_writer :xdim, :ydim
|
15
|
-
|
16
|
-
|
17
|
-
def initialize(*a, &b)
|
18
|
-
# new([[t,f,t,f], [f,t,f,t], ...])
|
19
|
-
if a[0].is_a?(Array) && a[0][0].is_a?(Array) && [true,false].include?(a[0][0][0])
|
20
|
-
a[0] = a[0].map{|r| PointRow.new(self, r) }
|
21
|
-
# new(['1010', '0101', ...])
|
22
|
-
elsif a[0].is_a?(Array) && a[0][0].is_a?(String)
|
23
|
-
a[0] = a[0].map{|s| PointRow.new(self, s) }
|
24
|
-
end
|
25
|
-
|
26
|
-
super(*a, &b)
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def xdim
|
31
|
-
@xdim || DEFAULT_XDIM
|
32
|
-
end
|
33
|
-
|
34
|
-
def ydim
|
35
|
-
@ydim || DEFAULT_YDIM
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
def width
|
40
|
-
inject(0){|m,r| r.width > m ? r.width : m }
|
41
|
-
end
|
42
|
-
|
43
|
-
def height
|
44
|
-
inject(0){|s,r| s + r.height }
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def to_s
|
49
|
-
map{|r| r.to_s }
|
50
|
-
end
|
51
|
-
|
52
|
-
def inspect
|
53
|
-
to_s
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
def dup
|
58
|
-
self.class.new(map{|r| r.dup })
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
class PointRow < Array
|
66
|
-
|
67
|
-
attr_reader :matrix
|
68
|
-
attr_accessor :xdim, :ydim
|
69
|
-
|
70
|
-
|
71
|
-
def initialize(*a, &b)
|
72
|
-
raise ArgumentError, 'PointRow must belong to a PointMatrix' unless a[0].is_a?(PointMatrix)
|
73
|
-
@matrix = a.shift
|
74
|
-
|
75
|
-
#Assume called with [t,f,t,f,..]
|
76
|
-
if a[0].is_a?(Array) && [true, false].include?(a[0][0])
|
77
|
-
a[0] = a[0].map{|b| Point.new(self, b) }
|
78
|
-
#Assume called with '1010..'
|
79
|
-
elsif a[0].is_a?(String)
|
80
|
-
a[0] = a[0].split(//).map{|s| Point.new(self, s == '1') }
|
81
|
-
end
|
82
|
-
|
83
|
-
super(*a, &b)
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
def booleans
|
88
|
-
map{|p| p.active? }
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def xdim
|
93
|
-
@xdim || matrix.xdim
|
94
|
-
end
|
95
|
-
|
96
|
-
def ydim
|
97
|
-
@ydim || matrix.ydim
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
def width
|
102
|
-
inject(0){|s,p| s + p.width }
|
103
|
-
end
|
104
|
-
|
105
|
-
def height
|
106
|
-
inject(0){|m,p| p.height > m ? p.height : m }
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
def to_s
|
111
|
-
inject(''){|s,p| s << (p.active ? '1' : '0') }
|
112
|
-
end
|
113
|
-
|
114
|
-
def inspect
|
115
|
-
to_s
|
116
|
-
end
|
117
|
-
|
118
|
-
def ==(other)
|
119
|
-
super #Just to say explicitly that equality should behave like in an array
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
def dup
|
124
|
-
self.class.new(matrix, map{|p| p.dup })
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
class Point
|
131
|
-
|
132
|
-
attr_reader :row, :active
|
133
|
-
attr_writer :width, :height, :color, :active
|
134
|
-
alias active? active
|
135
|
-
|
136
|
-
|
137
|
-
def initialize(row, active, opts={})
|
138
|
-
@row = row
|
139
|
-
self.active = active
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
def color
|
144
|
-
@color || (active ? Color.new(0,0,0) : nil)
|
145
|
-
end
|
146
|
-
|
147
|
-
def width
|
148
|
-
@width || row.xdim
|
149
|
-
end
|
150
|
-
|
151
|
-
def height
|
152
|
-
@height || row.ydim
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
def ==(other)
|
157
|
-
active == other.active &&
|
158
|
-
width == other.width &&
|
159
|
-
height == other.height &&
|
160
|
-
color == other.color
|
161
|
-
end
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
|
167
|
-
#TODO Add alpha
|
168
|
-
class Color
|
169
|
-
|
170
|
-
MIN_VALUE = 0
|
171
|
-
MAX_VALUE = 255
|
172
|
-
|
173
|
-
attr_reader :red, :blue, :green
|
174
|
-
|
175
|
-
def initialize(r, b, g)
|
176
|
-
self.red, self.blue, self.green = r, b, g
|
177
|
-
end
|
178
|
-
|
179
|
-
|
180
|
-
def red=(r)
|
181
|
-
set_color(:red, r)
|
182
|
-
end
|
183
|
-
|
184
|
-
def blue=(b)
|
185
|
-
set_color(:blue, b)
|
186
|
-
end
|
187
|
-
|
188
|
-
def green=(g)
|
189
|
-
set_color(:green, g)
|
190
|
-
end
|
191
|
-
|
192
|
-
|
193
|
-
def ==(other)
|
194
|
-
other.red == red && other.blue == blue && other.green == green
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
private
|
199
|
-
|
200
|
-
def set_color(name, value)
|
201
|
-
raise ArgumentError, "Value must be between 0-255" if value < MIN_VALUE || value > MAX_VALUE
|
202
|
-
instance_variable_set("@#{name}", value)
|
203
|
-
end
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|