barby 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/barby/outputter/chunky_png_outputter.rb +102 -0
- data/lib/barby/version.rb +1 -1
- metadata +5 -4
@@ -0,0 +1,102 @@
|
|
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.reverse_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
|
+
def to_datastream(*a)
|
57
|
+
to_image.to_datastream
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
#Renders the barcode to a PNG image
|
62
|
+
def to_png(*a)
|
63
|
+
to_datastream.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def width
|
68
|
+
length * xdim
|
69
|
+
end
|
70
|
+
|
71
|
+
def height
|
72
|
+
barcode.two_dimensional? ? (ydim * encoding.length) : (@height || 100)
|
73
|
+
end
|
74
|
+
|
75
|
+
def full_width
|
76
|
+
width + (margin * 2)
|
77
|
+
end
|
78
|
+
|
79
|
+
def full_height
|
80
|
+
height + (margin * 2)
|
81
|
+
end
|
82
|
+
|
83
|
+
def xdim
|
84
|
+
@xdim || 1
|
85
|
+
end
|
86
|
+
|
87
|
+
def ydim
|
88
|
+
@ydim || xdim
|
89
|
+
end
|
90
|
+
|
91
|
+
def margin
|
92
|
+
@margin || 10
|
93
|
+
end
|
94
|
+
|
95
|
+
def length
|
96
|
+
barcode.two_dimensional? ? encoding.first.length : encoding.length
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/lib/barby/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tore Darell
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/barby/barcode.rb
|
45
45
|
- lib/barby/outputter/ascii_outputter.rb
|
46
46
|
- lib/barby/outputter/cairo_outputter.rb
|
47
|
+
- lib/barby/outputter/chunky_png_outputter.rb
|
47
48
|
- lib/barby/outputter/pdfwriter_outputter.rb
|
48
49
|
- lib/barby/outputter/png_outputter.rb
|
49
50
|
- lib/barby/outputter/prawn_outputter.rb
|