barby 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,8 +53,8 @@ module Barby
53
53
  widths = []
54
54
  count = nil
55
55
 
56
- booleans.inject nil do |last,current|
57
- if current != last
56
+ booleans.inject nil do |previous,current|
57
+ if current != previous
58
58
  widths << count if count
59
59
  count = [current]
60
60
  else
@@ -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
@@ -37,7 +37,7 @@ module Barby
37
37
  y = margin
38
38
  booleans.each do |bar|
39
39
  if bar
40
- bars.rectangle(x, y, x+(xdim-1), y+height)
40
+ bars.rectangle(x, y, x+(xdim-1), y+(height-1))
41
41
  end
42
42
  x += xdim
43
43
  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: "0.1"
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-03-17 00:00:00 +01:00
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.0.1
65
+ rubygems_version: 1.1.1
65
66
  signing_key:
66
67
  specification_version: 2
67
68
  summary: A pure-Ruby barcode generator