barby 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'png'
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
|
5
|
+
class PngOutputter < Outputter
|
6
|
+
|
7
|
+
register :to_png, :to_canvas
|
8
|
+
|
9
|
+
attr_accessor :xdim, :width, :height, :margin
|
10
|
+
|
11
|
+
|
12
|
+
def to_canvas(opts={})
|
13
|
+
orig_opts = opts.inject({}){|h,p| send("#{p.first}=", p.last) if respond_to?("#{p.first}="); h.update(p.first => p.last) }
|
14
|
+
canvas = PNG::Canvas.new(full_width, full_height, PNG::Color::White)
|
15
|
+
|
16
|
+
x, y = margin, margin
|
17
|
+
booleans.each do |bar|
|
18
|
+
if bar
|
19
|
+
x.upto(x+(xdim-1)) do |xx|
|
20
|
+
y.upto y+(height-1) do |yy|
|
21
|
+
canvas[xx,yy] = PNG::Color::Black
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
x += xdim
|
26
|
+
end
|
27
|
+
|
28
|
+
orig_opts.each{|k,v| send("#{k}=", v) if respond_to?("#{k}=") }
|
29
|
+
canvas
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def to_png(*a)
|
34
|
+
PNG.new(to_canvas(*a)).to_blob
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def width
|
39
|
+
barcode.encoding.length * xdim
|
40
|
+
end
|
41
|
+
|
42
|
+
def height
|
43
|
+
@height || 100
|
44
|
+
end
|
45
|
+
|
46
|
+
def full_width
|
47
|
+
width + (margin * 2)
|
48
|
+
end
|
49
|
+
|
50
|
+
def full_height
|
51
|
+
height + (margin * 2)
|
52
|
+
end
|
53
|
+
|
54
|
+
def xdim
|
55
|
+
@xdim || 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def margin
|
59
|
+
@margin || 10
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tore Darell
|
@@ -9,7 +9,7 @@ autorequire: barby
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-04-25 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/barby/outputter/ascii_outputter.rb
|
38
38
|
- lib/barby/outputter/pdfwriter_outputter.rb
|
39
39
|
- lib/barby/outputter/rmagick_outputter.rb
|
40
|
+
- lib/barby/outputter/png_outputter.rb
|
40
41
|
- lib/barby/version.rb
|
41
42
|
- README
|
42
43
|
has_rdoc: true
|
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
requirements: []
|
62
63
|
|
63
64
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.1.1
|
65
66
|
signing_key:
|
66
67
|
specification_version: 2
|
67
68
|
summary: A pure-Ruby barcode generator
|