barby 0.4.2 → 0.4.3
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 +51 -0
- data/LICENSE +23 -0
- data/bin/barby +6 -5
- data/lib/barby.rb +1 -0
- data/lib/barby/barcode/code_39.rb +2 -1
- data/lib/barby/barcode/ean_13.rb +8 -0
- data/lib/barby/barcode/upc_supplemental.rb +140 -0
- data/lib/barby/outputter/ascii_outputter.rb +1 -1
- data/lib/barby/outputter/png_outputter.rb +20 -10
- data/lib/barby/version.rb +1 -1
- data/vendor/rqrcode/CHANGELOG +5 -0
- data/vendor/rqrcode/README +0 -2
- data/vendor/rqrcode/Rakefile +4 -6
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb +7 -5
- data/vendor/rqrcode/test/runtest.rb +21 -1
- metadata +10 -11
- data/lib/barby/outputter/chunky_png_outputter.rb +0 -107
data/CHANGELOG
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
* 0.4.3
|
2
|
+
|
3
|
+
* 2- and 5-digit UPC supplements
|
4
|
+
* Use ChunkyPNG for PngOutputter
|
5
|
+
|
6
|
+
* 0.4.2
|
7
|
+
|
8
|
+
* ChunkyPngOutputter now renders 2D barcodes not upside down [Thanks Scient]
|
9
|
+
|
10
|
+
* 0.4.1
|
11
|
+
|
12
|
+
* ChunkyPngOutputter - ChunkyPNG is a pure-Ruby PNG library
|
13
|
+
|
14
|
+
* 0.4.0
|
15
|
+
|
16
|
+
* Can you tell I'm just making up version numbers as I go along?
|
17
|
+
* DataMatrix (not required automatically, requires the 'semacode' gem)
|
18
|
+
* Refactored PrawnOutputter a little. No more stupid options hashes + unbleed attribute
|
19
|
+
|
20
|
+
* 0.3.2
|
21
|
+
|
22
|
+
* Fix bug where Code128 extras choke on newlines [Wayne Conrad]
|
23
|
+
* Don't allow Code128 with empty data strings [Wayne Conrad]
|
24
|
+
* Allow custom :size for QrCodes
|
25
|
+
|
26
|
+
* 0.3.1
|
27
|
+
|
28
|
+
* Add support for PDF417, using Pdf417lib (JRuby only) [Aslak Hellesøy]
|
29
|
+
|
30
|
+
* 0.3.0
|
31
|
+
|
32
|
+
* Make compatible with Ruby 1.9 [Chris Mowforth]
|
33
|
+
* Add SvgOutputter for outputting SVGs without dependencies [Peter H. Li]
|
34
|
+
|
35
|
+
* 0.2.1
|
36
|
+
|
37
|
+
* Allow QR Codes with sizes up to 40
|
38
|
+
|
39
|
+
* 0.2.0
|
40
|
+
|
41
|
+
* Added support for 2D barcodes
|
42
|
+
* Updated all outputters to support 2D barcodes
|
43
|
+
* Added support for QR Code
|
44
|
+
|
45
|
+
* 0.1.2
|
46
|
+
|
47
|
+
* Added CairoOutputter [Kouhei Sutou]
|
48
|
+
|
49
|
+
* 0.1.1
|
50
|
+
|
51
|
+
* Added PngOutputter that uses "png" gem
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2008 Tore Darell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/bin/barby
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#encoding: UTF-8
|
2
3
|
require 'optparse'
|
3
4
|
require 'rubygems'
|
4
5
|
|
@@ -6,8 +7,8 @@ require 'rubygems'
|
|
6
7
|
require 'barby'
|
7
8
|
|
8
9
|
options = {
|
9
|
-
:outputter => '
|
10
|
-
:outputter_method => '
|
10
|
+
:outputter => 'Ascii',
|
11
|
+
:outputter_method => 'to_ascii',
|
11
12
|
:barcode => 'Code128B'
|
12
13
|
}
|
13
14
|
|
@@ -20,8 +21,8 @@ ARGV.options do |o|
|
|
20
21
|
o.separator ''
|
21
22
|
|
22
23
|
o.on('-b', '--barcode=ClassName', String, 'Barcode type (Code128B)'){|v| options[:barcode] = v }
|
23
|
-
o.on('-o', '--outputter=ClassName', String, 'Outputter (
|
24
|
-
o.on('-m', '--method=method_name', String, 'Outputter method (
|
24
|
+
o.on('-o', '--outputter=ClassName', String, 'Outputter (Ascii)'){|v| options[:outputter] = v }
|
25
|
+
o.on('-m', '--method=method_name', String, 'Outputter method (to_ascii)'){|v| options[:outputter_method] = v }
|
25
26
|
|
26
27
|
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
|
27
28
|
|
@@ -34,7 +35,7 @@ end
|
|
34
35
|
require "barby/outputter/#{options[:outputter].gsub(/[A-Z]/){|c| '_'+c.downcase }[1..-1]}_outputter"
|
35
36
|
|
36
37
|
barcode_class = Barby.const_get(options[:barcode])
|
37
|
-
barcode = barcode_class.new($*.empty? ? STDIN.read.chomp : $*)
|
38
|
+
barcode = barcode_class.new($*.empty? ? STDIN.read.chomp : $*[0])
|
38
39
|
outputter_class = Barby.const_get("#{options[:outputter]}Outputter")
|
39
40
|
outputter = outputter_class.new(barcode)
|
40
41
|
|
data/lib/barby.rb
CHANGED
@@ -8,6 +8,7 @@ require 'barby/barcode/code_39'
|
|
8
8
|
require 'barby/barcode/code_93'
|
9
9
|
require 'barby/barcode/ean_13'
|
10
10
|
require 'barby/barcode/ean_8'
|
11
|
+
require 'barby/barcode/upc_supplemental'
|
11
12
|
require 'barby/barcode/bookland'
|
12
13
|
require 'barby/barcode/qr_code'
|
13
14
|
require 'barby/barcode/code_25'
|
@@ -88,7 +88,8 @@ module Barby
|
|
88
88
|
|
89
89
|
attr_accessor :data, :spacing, :narrow_width, :wide_width, :extended, :include_checksum
|
90
90
|
|
91
|
-
|
91
|
+
# Do not surround "data" with the mandatory "*" as is this is done automically for you.
|
92
|
+
# So instead of passing "*123456*" as "data", just pass "123456".
|
92
93
|
def initialize(data, extended=false)
|
93
94
|
self.data = data
|
94
95
|
self.extended = extended
|
data/lib/barby/barcode/ean_13.rb
CHANGED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'barby/barcode'
|
2
|
+
require 'barby/barcode/ean_13'
|
3
|
+
|
4
|
+
module Barby
|
5
|
+
|
6
|
+
|
7
|
+
class UPCSupplemental < Barby::Barcode1D
|
8
|
+
|
9
|
+
attr_accessor :data
|
10
|
+
|
11
|
+
FORMAT = /^\d\d\d\d\d$|^\d\d$/
|
12
|
+
|
13
|
+
START = '1011'
|
14
|
+
SEPARATOR = '01'
|
15
|
+
|
16
|
+
ODD = :odd
|
17
|
+
EVEN = :even
|
18
|
+
|
19
|
+
PARITY_MAPS = {
|
20
|
+
2 => {
|
21
|
+
0 => [ODD, ODD],
|
22
|
+
1 => [ODD, EVEN],
|
23
|
+
2 => [EVEN, ODD],
|
24
|
+
3 => [EVEN, EVEN]
|
25
|
+
},
|
26
|
+
5 => {
|
27
|
+
0 => [EVEN, EVEN, ODD, ODD, ODD],
|
28
|
+
1 => [EVEN, ODD, EVEN, ODD, ODD],
|
29
|
+
2 => [EVEN, ODD, ODD, EVEN, ODD],
|
30
|
+
3 => [EVEN, ODD, ODD, ODD, EVEN],
|
31
|
+
4 => [ODD, EVEN, EVEN, ODD, ODD],
|
32
|
+
5 => [ODD, ODD, EVEN, EVEN, ODD],
|
33
|
+
6 => [ODD, ODD, ODD, EVEN, EVEN],
|
34
|
+
7 => [ODD, EVEN, ODD, EVEN, ODD],
|
35
|
+
8 => [ODD, EVEN, ODD, ODD, EVEN],
|
36
|
+
9 => [ODD, ODD, EVEN, ODD, EVEN]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
ENCODINGS = {
|
41
|
+
ODD => EAN13::LEFT_ENCODINGS_ODD,
|
42
|
+
EVEN => EAN13::LEFT_ENCODINGS_EVEN
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
def initialize(data)
|
47
|
+
self.data = data
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def size
|
52
|
+
data.size
|
53
|
+
end
|
54
|
+
|
55
|
+
def two_digit?
|
56
|
+
size == 2
|
57
|
+
end
|
58
|
+
|
59
|
+
def five_digit?
|
60
|
+
size == 5
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def characters
|
65
|
+
data.split(//)
|
66
|
+
end
|
67
|
+
|
68
|
+
def digits
|
69
|
+
characters.map{|c| c.to_i }
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
#Odd and even methods are only useful for 5 digits
|
74
|
+
def odd_digits
|
75
|
+
alternater = false
|
76
|
+
digits.reverse.select{ alternater = !alternater }
|
77
|
+
end
|
78
|
+
|
79
|
+
def even_digits
|
80
|
+
alternater = true
|
81
|
+
digits.reverse.select{ alternater = !alternater }
|
82
|
+
end
|
83
|
+
|
84
|
+
def odd_sum
|
85
|
+
odd_digits.inject(0){|s,d| s + d * 3 }
|
86
|
+
end
|
87
|
+
|
88
|
+
def even_sum
|
89
|
+
even_digits.inject(0){|s,d| s + d * 9 }
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
#Checksum is different for 2 and 5 digits
|
94
|
+
#2-digits don't really have a checksum, just a remainder to look up the parity
|
95
|
+
def checksum
|
96
|
+
if two_digit?
|
97
|
+
data.to_i % 4
|
98
|
+
elsif five_digit?
|
99
|
+
(odd_sum + even_sum) % 10
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
#Parity maps are different for 2 and 5 digits
|
105
|
+
def parity_map
|
106
|
+
PARITY_MAPS[size][checksum]
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def encoded_characters
|
111
|
+
parity_map.zip(digits).map do |parity, digit|
|
112
|
+
ENCODINGS[parity][digit]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def encoding
|
118
|
+
START + encoded_characters.join(SEPARATOR)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def valid?
|
123
|
+
data =~ FORMAT
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def to_s
|
128
|
+
data
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
NO_PRICE = new('90000') #The book doesn't have a suggested retail price
|
133
|
+
COMPLIMENTARY = new('99991') #The book is complimentary (~free)
|
134
|
+
USED = new('99990') #The book is marked as used
|
135
|
+
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
require 'barby/outputter'
|
2
|
-
require '
|
2
|
+
require 'chunky_png'
|
3
3
|
|
4
4
|
module Barby
|
5
5
|
|
6
|
-
#Renders the barcode to a PNG image using
|
6
|
+
#Renders the barcode to a PNG image using chunky_png (gem install chunky_png)
|
7
7
|
#
|
8
|
-
#Registers the to_png and to_canvas methods
|
8
|
+
#Registers the to_png, to_datastream and to_canvas methods
|
9
9
|
class PngOutputter < Outputter
|
10
10
|
|
11
|
-
register :to_png, :
|
11
|
+
register :to_png, :to_image, :to_datastream
|
12
12
|
|
13
13
|
attr_accessor :xdim, :ydim, :width, :height, :margin
|
14
14
|
|
15
15
|
|
16
16
|
#Creates a PNG::Canvas object and renders the barcode on it
|
17
|
-
def
|
17
|
+
def to_image(opts={})
|
18
18
|
with_options opts do
|
19
|
-
canvas =
|
19
|
+
canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)
|
20
20
|
|
21
21
|
if barcode.two_dimensional?
|
22
22
|
x, y = margin, margin
|
23
|
-
booleans.
|
23
|
+
booleans.each do |line|
|
24
24
|
line.each do |bar|
|
25
25
|
if bar
|
26
26
|
x.upto(x+(xdim-1)) do |xx|
|
27
27
|
y.upto y+(ydim-1) do |yy|
|
28
|
-
canvas[xx,yy] =
|
28
|
+
canvas[xx,yy] = ChunkyPNG::Color::BLACK
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -40,7 +40,7 @@ module Barby
|
|
40
40
|
if bar
|
41
41
|
x.upto(x+(xdim-1)) do |xx|
|
42
42
|
y.upto y+(height-1) do |yy|
|
43
|
-
canvas[xx,yy] =
|
43
|
+
canvas[xx,yy] = ChunkyPNG::Color::BLACK
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -53,9 +53,19 @@ module Barby
|
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
+
#Create a ChunkyPNG::Datastream containing the barcode image
|
57
|
+
#
|
58
|
+
# :constraints - Value is passed on to ChunkyPNG::Image#to_datastream
|
59
|
+
# E.g. to_datastream(:constraints => {:color_mode => ChunkyPNG::COLOR_GRAYSCALE})
|
60
|
+
def to_datastream(*a)
|
61
|
+
constraints = a.first && a.first[:constraints] ? [a.first[:constraints]] : []
|
62
|
+
to_image(*a).to_datastream(*constraints)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
56
66
|
#Renders the barcode to a PNG image
|
57
67
|
def to_png(*a)
|
58
|
-
|
68
|
+
to_datastream(*a).to_s
|
59
69
|
end
|
60
70
|
|
61
71
|
|
data/lib/barby/version.rb
CHANGED
data/vendor/rqrcode/CHANGELOG
CHANGED
data/vendor/rqrcode/README
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
|
4
4
|
|
5
|
-
RubyForge Project Page http://rubyforge.org/projects/rqrcode/
|
6
|
-
|
7
5
|
== An Overview
|
8
6
|
|
9
7
|
Let's clear up some rQRCode stuff.
|
data/vendor/rqrcode/Rakefile
CHANGED
@@ -6,17 +6,15 @@ require 'rake/rdoctask'
|
|
6
6
|
require 'rake/testtask'
|
7
7
|
|
8
8
|
NAME = "rqrcode"
|
9
|
-
VERS = "0.3.
|
9
|
+
VERS = "0.3.3"
|
10
10
|
CLEAN.include ['pkg', 'rdoc']
|
11
11
|
|
12
|
-
Gem::manage_gems
|
13
|
-
|
14
12
|
spec = Gem::Specification.new do |s|
|
15
13
|
s.name = NAME
|
16
|
-
s.version
|
14
|
+
s.version = VERS
|
17
15
|
s.author = "Duncan Robertson"
|
18
|
-
s.email
|
19
|
-
s.homepage = "http://
|
16
|
+
s.email = "duncan@whomwah.com"
|
17
|
+
s.homepage = "http://whomwah.github.com/rqrcode/"
|
20
18
|
s.platform = Gem::Platform::RUBY
|
21
19
|
s.summary = "A library to encode QR Codes"
|
22
20
|
s.rubyforge_project = NAME
|
@@ -69,18 +69,21 @@ module RQRCode #:nodoc:
|
|
69
69
|
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
|
70
70
|
#
|
71
71
|
|
72
|
-
|
72
|
+
def initialize( *args )
|
73
73
|
raise QRCodeArgumentError unless args.first.kind_of?( String )
|
74
74
|
|
75
75
|
@data = args.shift
|
76
76
|
options = args.extract_options!
|
77
77
|
level = options[:level] || :h
|
78
|
+
|
79
|
+
raise QRCodeArgumentError unless %w(l m q h).include?(level.to_s)
|
80
|
+
|
78
81
|
@error_correct_level = QRERRORCORRECTLEVEL[ level.to_sym ]
|
79
82
|
@type_number = options[:size] || 4
|
80
83
|
@module_count = @type_number * 4 + 17
|
81
|
-
@modules =
|
82
|
-
@data_cache = nil
|
84
|
+
@modules = Array.new( @module_count )
|
83
85
|
@data_list = QR8bitByte.new( @data )
|
86
|
+
@data_cache = nil
|
84
87
|
|
85
88
|
self.make
|
86
89
|
end
|
@@ -149,7 +152,6 @@ module RQRCode #:nodoc:
|
|
149
152
|
|
150
153
|
|
151
154
|
def make_impl( test, mask_pattern ) #:nodoc:
|
152
|
-
@modules = Array.new( @module_count )
|
153
155
|
|
154
156
|
( 0...@module_count ).each do |row|
|
155
157
|
@modules[row] = Array.new( @module_count )
|
@@ -292,7 +294,7 @@ module RQRCode #:nodoc:
|
|
292
294
|
|
293
295
|
if @modules[row][ col - c ].nil?
|
294
296
|
dark = false
|
295
|
-
if byte_index < data.size
|
297
|
+
if byte_index < data.size && !data[byte_index].nil?
|
296
298
|
dark = (( (data[byte_index]).rszf( bit_index ) & 1) == 1 )
|
297
299
|
end
|
298
300
|
mask = QRUtil.get_mask( mask_pattern, row, col - c )
|
@@ -72,7 +72,27 @@ class QRCodeTest < Test::Unit::TestCase
|
|
72
72
|
def test_to_s
|
73
73
|
qr = RQRCode::QRCode.new( 'duncan', :size => 1 )
|
74
74
|
assert_equal qr.to_s[0..21], "xxxxxxx xx x xxxxxxx\n"
|
75
|
-
assert_equal qr.to_s( :true => 'q', :false => 'n' )[0..21],
|
75
|
+
assert_equal qr.to_s( :true => 'q', :false => 'n' )[0..21],
|
76
|
+
"qqqqqqqnqqnqnnqqqqqqq\n"
|
76
77
|
assert_equal qr.to_s( :true => '@' )[0..21], "@@@@@@@ @@ @ @@@@@@@\n"
|
77
78
|
end
|
79
|
+
|
80
|
+
def test_rszf_error_not_thrown
|
81
|
+
assert RQRCode::QRCode.new('2 1058 657682')
|
82
|
+
assert RQRCode::QRCode.new("40952", :size => 1, :level => :h)
|
83
|
+
assert RQRCode::QRCode.new("40932", :size => 1, :level => :h)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_levels
|
87
|
+
assert RQRCode::QRCode.new("duncan", :level => :l)
|
88
|
+
assert RQRCode::QRCode.new("duncan", :level => :m)
|
89
|
+
assert RQRCode::QRCode.new("duncan", :level => :q)
|
90
|
+
assert RQRCode::QRCode.new("duncan", :level => :h)
|
91
|
+
assert_raise(RQRCode::QRCodeArgumentError) {
|
92
|
+
%w(a b c d e f g i j k n o p r s t u v w x y z).each do |ltr|
|
93
|
+
RQRCode::QRCode.new( "duncan", :level => ltr.to_sym )
|
94
|
+
end
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
78
98
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
8
|
+
- 3
|
9
|
+
version: 0.4.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Tore Darell
|
@@ -15,19 +14,22 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-05-10 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
22
21
|
description: Barby creates barcodes.
|
23
22
|
email: toredarell@gmail.com
|
24
|
-
executables:
|
25
|
-
|
23
|
+
executables:
|
24
|
+
- barby
|
26
25
|
extensions: []
|
27
26
|
|
28
27
|
extra_rdoc_files:
|
29
28
|
- README
|
30
29
|
files:
|
30
|
+
- CHANGELOG
|
31
|
+
- README
|
32
|
+
- LICENSE
|
31
33
|
- lib/barby/barcode/bookland.rb
|
32
34
|
- lib/barby/barcode/code_128.rb
|
33
35
|
- lib/barby/barcode/code_25.rb
|
@@ -41,10 +43,10 @@ files:
|
|
41
43
|
- lib/barby/barcode/gs1_128.rb
|
42
44
|
- lib/barby/barcode/pdf_417.rb
|
43
45
|
- lib/barby/barcode/qr_code.rb
|
46
|
+
- lib/barby/barcode/upc_supplemental.rb
|
44
47
|
- lib/barby/barcode.rb
|
45
48
|
- lib/barby/outputter/ascii_outputter.rb
|
46
49
|
- lib/barby/outputter/cairo_outputter.rb
|
47
|
-
- lib/barby/outputter/chunky_png_outputter.rb
|
48
50
|
- lib/barby/outputter/pdfwriter_outputter.rb
|
49
51
|
- lib/barby/outputter/png_outputter.rb
|
50
52
|
- lib/barby/outputter/prawn_outputter.rb
|
@@ -54,7 +56,6 @@ files:
|
|
54
56
|
- lib/barby/vendor.rb
|
55
57
|
- lib/barby/version.rb
|
56
58
|
- lib/barby.rb
|
57
|
-
- bin/barby
|
58
59
|
- vendor/Pdf417lib-java-0.91/lib/Pdf417lib.jar
|
59
60
|
- vendor/Pdf417lib-java-0.91/lib/Pdf417lib.java
|
60
61
|
- vendor/rqrcode/CHANGELOG
|
@@ -77,7 +78,7 @@ files:
|
|
77
78
|
- vendor/rqrcode/README
|
78
79
|
- vendor/rqrcode/test/runtest.rb
|
79
80
|
- vendor/rqrcode/test/test_data.rb
|
80
|
-
-
|
81
|
+
- bin/barby
|
81
82
|
has_rdoc: true
|
82
83
|
homepage: http://toretore.github.com/barby
|
83
84
|
licenses: []
|
@@ -92,7 +93,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
requirements:
|
93
94
|
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
|
-
hash: 3
|
96
96
|
segments:
|
97
97
|
- 0
|
98
98
|
version: "0"
|
@@ -101,7 +101,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
hash: 3
|
105
104
|
segments:
|
106
105
|
- 0
|
107
106
|
version: "0"
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'barby/outputter'
|
2
|
-
require 'chunky_png'
|
3
|
-
|
4
|
-
module Barby
|
5
|
-
|
6
|
-
#Renders the barcode to a PNG image using the "png" gem (gem install png)
|
7
|
-
#
|
8
|
-
#Registers the to_png, to_datastream and to_canvas methods
|
9
|
-
class ChunkyPngOutputter < Outputter
|
10
|
-
|
11
|
-
register :to_png, :to_image, :to_datastream
|
12
|
-
|
13
|
-
attr_accessor :xdim, :ydim, :width, :height, :margin
|
14
|
-
|
15
|
-
|
16
|
-
#Creates a PNG::Canvas object and renders the barcode on it
|
17
|
-
def to_image(opts={})
|
18
|
-
with_options opts do
|
19
|
-
canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)
|
20
|
-
|
21
|
-
if barcode.two_dimensional?
|
22
|
-
x, y = margin, margin
|
23
|
-
booleans.each do |line|
|
24
|
-
line.each do |bar|
|
25
|
-
if bar
|
26
|
-
x.upto(x+(xdim-1)) do |xx|
|
27
|
-
y.upto y+(ydim-1) do |yy|
|
28
|
-
canvas[xx,yy] = ChunkyPNG::Color::BLACK
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
x += xdim
|
33
|
-
end
|
34
|
-
y += ydim
|
35
|
-
x = margin
|
36
|
-
end
|
37
|
-
else
|
38
|
-
x, y = margin, margin
|
39
|
-
booleans.each do |bar|
|
40
|
-
if bar
|
41
|
-
x.upto(x+(xdim-1)) do |xx|
|
42
|
-
y.upto y+(height-1) do |yy|
|
43
|
-
canvas[xx,yy] = ChunkyPNG::Color::BLACK
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
x += xdim
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
canvas
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
#Create a ChunkyPNG::Datastream containing the barcode image
|
57
|
-
#
|
58
|
-
# :constraints - Value is passed on to ChunkyPNG::Image#to_datastream
|
59
|
-
# E.g. to_datastream(:constraints => {:color_mode => ChunkyPNG::COLOR_GRAYSCALE})
|
60
|
-
def to_datastream(*a)
|
61
|
-
constraints = a.first && a.first[:constraints] ? [a.first[:constraints]] : []
|
62
|
-
to_image(*a).to_datastream(*constraints)
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
#Renders the barcode to a PNG image
|
67
|
-
def to_png(*a)
|
68
|
-
to_datastream(*a).to_s
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def width
|
73
|
-
length * xdim
|
74
|
-
end
|
75
|
-
|
76
|
-
def height
|
77
|
-
barcode.two_dimensional? ? (ydim * encoding.length) : (@height || 100)
|
78
|
-
end
|
79
|
-
|
80
|
-
def full_width
|
81
|
-
width + (margin * 2)
|
82
|
-
end
|
83
|
-
|
84
|
-
def full_height
|
85
|
-
height + (margin * 2)
|
86
|
-
end
|
87
|
-
|
88
|
-
def xdim
|
89
|
-
@xdim || 1
|
90
|
-
end
|
91
|
-
|
92
|
-
def ydim
|
93
|
-
@ydim || xdim
|
94
|
-
end
|
95
|
-
|
96
|
-
def margin
|
97
|
-
@margin || 10
|
98
|
-
end
|
99
|
-
|
100
|
-
def length
|
101
|
-
barcode.two_dimensional? ? encoding.first.length : encoding.length
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|