barby 0.6.5 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/CHANGELOG +8 -0
  4. data/Gemfile +5 -0
  5. data/README.md +21 -20
  6. data/Rakefile +15 -0
  7. data/barby.gemspec +31 -0
  8. data/lib/barby/barcode/codabar.rb +82 -0
  9. data/lib/barby/barcode.rb +3 -3
  10. data/lib/barby/outputter/cairo_outputter.rb +11 -3
  11. data/lib/barby/outputter/png_outputter.rb +43 -11
  12. data/lib/barby/outputter/prawn_outputter.rb +12 -9
  13. data/lib/barby/outputter/rmagick_outputter.rb +38 -11
  14. data/lib/barby/outputter/svg_outputter.rb +11 -18
  15. data/lib/barby/outputter.rb +1 -1
  16. data/lib/barby/version.rb +2 -2
  17. data/test/barcodes.rb +20 -0
  18. data/test/bookland_test.rb +54 -0
  19. data/test/codabar_test.rb +58 -0
  20. data/test/code_128_test.rb +470 -0
  21. data/test/code_25_iata_test.rb +19 -0
  22. data/test/code_25_interleaved_test.rb +116 -0
  23. data/test/code_25_test.rb +110 -0
  24. data/test/code_39_test.rb +210 -0
  25. data/test/code_93_test.rb +144 -0
  26. data/test/data_matrix_test.rb +30 -0
  27. data/test/ean13_test.rb +169 -0
  28. data/test/ean8_test.rb +100 -0
  29. data/test/outputter/cairo_outputter_test.rb +129 -0
  30. data/test/outputter/html_outputter_test.rb +68 -0
  31. data/test/outputter/pdfwriter_outputter_test.rb +37 -0
  32. data/test/outputter/png_outputter_test.rb +49 -0
  33. data/test/outputter/prawn_outputter_test.rb +79 -0
  34. data/test/outputter/rmagick_outputter_test.rb +83 -0
  35. data/test/outputter/svg_outputter_test.rb +89 -0
  36. data/test/outputter_test.rb +134 -0
  37. data/test/pdf_417_test.rb +45 -0
  38. data/test/qr_code_test.rb +78 -0
  39. data/test/test_helper.rb +24 -0
  40. data/test/upc_supplemental_test.rb +109 -0
  41. metadata +157 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf63b4cabe71e145f367917c72ddd3a87b44655d
4
- data.tar.gz: 978466b7b734651b5f9362b67136033bdcf572a7
2
+ SHA256:
3
+ metadata.gz: 64d74091ea1f3aa79457c34878fc3b0d6f4c805dbb985d12eb372f29a7837e36
4
+ data.tar.gz: a8a61c1af0a401a1b36bc675653d2063e569443d434a57b5a2d95c7abfc1d193
5
5
  SHA512:
6
- metadata.gz: 8152a2ea8b9b84264e904f5d50f61c6712fd238580041b5cc0852eacdce210b9e4d6a345ea753c3c4d58c62439d69ab7882006643caa31607eefedcc6226268d
7
- data.tar.gz: 0b9e1005bc39a1ea0e8ecd6c57947be36f35e8d1a5529c48073f7d505bc82fa92a7ca1c67d987eb9f94507edd4f5b501cf58c4f994fd8339687fd1659f665404
6
+ metadata.gz: 99143c0bf41695fa1416956073bcb6c9d7257c677fa36337638f890681665bacd51c4b04cd3412008592c8f23e4130fec74363eb425c776f8c827bf360d07c5b
7
+ data.tar.gz: d1b1f6aa2a63484b00f79bd184bef605b75850152dd54600b7eb25434f114c45c6994ce725af7535edefb8a536fc93f3e42c7d4bd2547c6f88d8da90d0947f8f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ * 0.6.7
2
+
3
+ * RMagick outputter should use line command for lines [joshuaflanagan]
4
+
5
+ * 0.6.6
6
+
7
+ * Add support for Codabar symbology [labocho]
8
+
1
9
  * 0.6.1
2
10
 
3
11
  * Fix single-pixel error with RMagick [James Brink]
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/README.md CHANGED
@@ -12,7 +12,8 @@ lines or squares, outputters will do that for you.
12
12
  Likewise, you can easily add an outputter for a format that doesn't have one
13
13
  yet, and it will work with all existing symbologies.
14
14
 
15
- For more information, check out [the Barby wiki] [wiki].
15
+ For more information, check out [the Barby wiki][wiki].
16
+
16
17
 
17
18
  ### New require policy
18
19
 
@@ -51,24 +52,24 @@ puts barcode.to_ascii #Implicitly uses the AsciiOutputter
51
52
  require 'barby/barcode/<filename>'
52
53
  ```
53
54
 
54
- | Name | Filename | Dependencies |
55
- | ----------------------------------- | --------------------- | ------------- |
56
- | Code 25 | `code_25` | ─ |
57
- | ├─ Interleaved | `code_25_interleaved` | ─ |
58
- | └─ IATA | `code_25_iata` | ─ |
59
- | Code 39 | `code_39` | ─ |
60
- | └─ Extended | `code_39` | ─ |
61
- | Code 93 | `code_93` | ─ |
62
- | Code 128 (A, B, and C) | `code_128` | ─ |
63
- | └─ GS1 128 | `gs1_128` | ─ |
64
- | EAN-13 | `ean_13` | ─ |
65
- | ├─ Bookland | `bookland` | ─ |
66
- | └─ UPC-A | `ean_13` | ─ |
67
- | EAN-8 | `ean_8` | ─ |
68
- | UPC/EAN supplemental, 2 & 5 digits | `upc_supplemental` | ─ |
69
- | QR Code | `qr_code` | `rqrcode` |
70
- | DataMatrix (Semacode) | `data_matrix` | `semacode` |
71
- | PDF417 | `pdf_417` | JRuby |
55
+ | Name | Filename | Dependencies |
56
+ | ----------------------------------- | --------------------- | ---------------------------------- |
57
+ | Code 25 | `code_25` | ─ |
58
+ | ├─ Interleaved | `code_25_interleaved` | ─ |
59
+ | └─ IATA | `code_25_iata` | ─ |
60
+ | Code 39 | `code_39` | ─ |
61
+ | └─ Extended | `code_39` | ─ |
62
+ | Code 93 | `code_93` | ─ |
63
+ | Code 128 (A, B, and C) | `code_128` | ─ |
64
+ | └─ GS1 128 | `gs1_128` | ─ |
65
+ | EAN-13 | `ean_13` | ─ |
66
+ | ├─ Bookland | `bookland` | ─ |
67
+ | └─ UPC-A | `ean_13` | ─ |
68
+ | EAN-8 | `ean_8` | ─ |
69
+ | UPC/EAN supplemental, 2 & 5 digits | `upc_supplemental` | ─ |
70
+ | QR Code | `qr_code` | `rqrcode` |
71
+ | DataMatrix (Semacode) | `data_matrix` | `semacode` or `semacode-ruby19` |
72
+ | PDF417 | `pdf_417` | JRuby |
72
73
 
73
74
 
74
75
  ## Outputters
@@ -99,7 +100,7 @@ require 'barby/outputter/<filename>_outputter'
99
100
 
100
101
  ---
101
102
 
102
- For more information, check out [the Barby wiki] [wiki].
103
+ For more information, check out [the Barby wiki][wiki].
103
104
 
104
105
 
105
106
  [wiki]: https://github.com/toretore/barby/wiki
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs = ['lib','test']
7
+ t.test_files = Dir.glob("test/**/*_test.rb").sort
8
+ t.verbose = true
9
+ end
10
+
11
+ RDoc::Task.new do |rdoc|
12
+ rdoc.main = "README"
13
+ rdoc.rdoc_files.include("README", "lib")
14
+ rdoc.rdoc_dir = 'doc'
15
+ end
data/barby.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "barby/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "barby"
6
+ s.version = Barby::VERSION::STRING
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = "The Ruby barcode generator"
9
+ s.email = "toredarell@gmail.com"
10
+ s.homepage = "http://toretore.github.com/barby"
11
+ s.description = "Barby creates barcodes."
12
+ s.authors = ['Tore Darell']
13
+
14
+ s.rubyforge_project = "barby"
15
+
16
+ s.extra_rdoc_files = ["README.md"]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.test_files.delete("test/outputter/rmagick_outputter_test.rb")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency "minitest", "~> 5.11"
25
+ s.add_development_dependency "bundler", "~> 1.16"
26
+ s.add_development_dependency "rake", "~> 10.0"
27
+ s.add_development_dependency "semacode-ruby19", "~> 0.7"
28
+ s.add_development_dependency "rqrcode", "~> 0.10"
29
+ s.add_development_dependency "prawn", "~> 2.2"
30
+ s.add_development_dependency "cairo", "~> 1.15"
31
+ end
@@ -0,0 +1,82 @@
1
+ require "barby/barcode"
2
+
3
+ module Barby
4
+ # https://en.wikipedia.org/wiki/Codabar
5
+ class Codabar < Barcode1D
6
+ BLACK_NARROW_WIDTH = 1
7
+ WHITE_NARROW_WIDTH = 2
8
+ WIDE_WIDTH_RATE = 3
9
+ SPACING = 5 # must be equal to or wider than white narrow width
10
+ CHARACTERS = "0123456789-$:/.+ABCD".freeze
11
+ # even: black, odd: white
12
+ # 0: narrow, 1: wide
13
+ BINARY_EXPRESSION = [
14
+ "0000011", # 0
15
+ "0000110", # 1
16
+ "0001001", # 2
17
+ "1100000", # 3
18
+ "0010010", # 4
19
+ "1000010", # 5
20
+ "0100001", # 6
21
+ "0100100", # 7
22
+ "0110000", # 8
23
+ "1001000", # 9
24
+ "0001100", # -
25
+ "0011000", # $
26
+ "1000101", # :
27
+ "1010001", # /
28
+ "1010100", # .
29
+ "0010101", # +
30
+ "0011010", # A
31
+ "0101001", # B
32
+ "0001011", # C
33
+ "0001110", # D
34
+ ].each(&:freeze)
35
+ CHARACTER_TO_BINARY = Hash[CHARACTERS.chars.zip(BINARY_EXPRESSION)].freeze
36
+ FORMAT = /\A[ABCD][0123456789\-\$:\/\.\+]+[ABCD]\z/.freeze
37
+ ONE = "1".freeze
38
+ ZERO = "0".freeze
39
+
40
+ attr_accessor :data, :black_narrow_width, :white_narrow_width, :wide_width_rate, :spacing
41
+
42
+ def initialize(data)
43
+ self.data = data
44
+ raise ArgumentError, 'data not valid' unless valid?
45
+
46
+ self.black_narrow_width = BLACK_NARROW_WIDTH
47
+ self.white_narrow_width = WHITE_NARROW_WIDTH
48
+ self.wide_width_rate = WIDE_WIDTH_RATE
49
+ self.spacing = SPACING
50
+ end
51
+
52
+ def encoding
53
+ data.chars.map{|c| binary_to_bars(CHARACTER_TO_BINARY[c]) }.join(ZERO * spacing)
54
+ end
55
+
56
+ def valid?
57
+ data =~ FORMAT
58
+ end
59
+
60
+ private
61
+ def binary_to_bars(bin)
62
+ bin.chars.each_with_index.map{|c, i|
63
+ black = i % 2 == 0
64
+ narrow = c == ZERO
65
+
66
+ if black
67
+ if narrow
68
+ ONE * black_narrow_width
69
+ else
70
+ ONE * (black_narrow_width * wide_width_rate).to_i
71
+ end
72
+ else
73
+ if narrow
74
+ ZERO * white_narrow_width
75
+ else
76
+ ZERO * (white_narrow_width * wide_width_rate).to_i
77
+ end
78
+ end
79
+ }.join
80
+ end
81
+ end
82
+ end
data/lib/barby/barcode.rb CHANGED
@@ -17,7 +17,7 @@ module Barby
17
17
  # '101100111000111100001'
18
18
  # end
19
19
  # end
20
- #
20
+ #
21
21
  # require 'barby/outputter/ascii_outputter'
22
22
  # puts StaticBarcode.new.to_ascii(:height => 3)
23
23
  #
@@ -33,8 +33,8 @@ module Barby
33
33
  # end
34
34
  # end
35
35
  class Barcode
36
-
37
-
36
+
37
+
38
38
  #Every barcode must have an encoding method. This method returns
39
39
  #a string containing a series of 1 and 0, representing bars and
40
40
  #spaces. One digit is the width of one "module" or X dimension.
@@ -4,9 +4,17 @@ require 'stringio'
4
4
 
5
5
  module Barby
6
6
 
7
- #Uses Cairo to render a barcode to a number of formats: PNG, PS, EPS, PDF and SVG
7
+ # Uses Cairo to render a barcode to a number of formats: PNG, PS, EPS, PDF and SVG
8
8
  #
9
- #Registers methods render_to_cairo_context, to_png, to_ps, to_eps, to_pdf and to_svg
9
+ # Registers methods render_to_cairo_context, to_png, to_ps, to_eps, to_pdf and to_svg
10
+ #
11
+ # Options:
12
+ #
13
+ # * xdim
14
+ # * ydim - (2D only)
15
+ # * height - (1D only)
16
+ # * foreground - Cairo::Color::Base or Cairo::Color.parse(value)
17
+ # * background - ^
10
18
  class CairoOutputter < Outputter
11
19
 
12
20
  register :render_to_cairo_context
@@ -42,7 +50,7 @@ module Barby
42
50
  _height = height(options)
43
51
  original_current_x = current_x
44
52
  context.save do
45
- context.set_source_color(:black)
53
+ context.set_source_color(options[:foreground] || :black)
46
54
  context.fill do
47
55
  if barcode.two_dimensional?
48
56
  boolean_groups.each do |groups|
@@ -3,24 +3,30 @@ require 'chunky_png'
3
3
 
4
4
  module Barby
5
5
 
6
- #Renders the barcode to a PNG image using chunky_png (gem install chunky_png)
6
+ # Renders the barcode to a PNG image using chunky_png (gem install chunky_png)
7
+ #
8
+ # Registers the to_png, to_datastream and to_canvas methods
9
+ #
10
+ # Options:
11
+ #
12
+ # * xdim: X dimension - bar width [1]
13
+ # * ydim: Y dimension - bar height (2D only) [1]
14
+ # * height: Height of bars (1D only) [100]
15
+ # * margin: Size of margin around barcode [0]
16
+ # * foreground: Foreground color (see ChunkyPNG::Color - can be HTML color name) [black]
17
+ # * background: Background color (see ChunkyPNG::Color - can be HTML color name) [white]
7
18
  #
8
- #Registers the to_png, to_datastream and to_canvas methods
9
19
  class PngOutputter < Outputter
10
20
 
11
21
  register :to_png, :to_image, :to_datastream
12
22
 
13
- attr_writer :xdim, :ydim, :width, :height, :margin
23
+ attr_writer :xdim, :ydim, :height, :margin
14
24
 
15
- def initialize(*)
16
- super
17
- @xdim, @height, @margin = nil
18
- end
19
25
 
20
- #Creates a PNG::Canvas object and renders the barcode on it
26
+ #Creates a ChunkyPNG::Image object and renders the barcode on it
21
27
  def to_image(opts={})
22
28
  with_options opts do
23
- canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)
29
+ canvas = ChunkyPNG::Image.new(full_width, full_height, background)
24
30
 
25
31
  if barcode.two_dimensional?
26
32
  x, y = margin, margin
@@ -29,7 +35,7 @@ module Barby
29
35
  if bar
30
36
  x.upto(x+(xdim-1)) do |xx|
31
37
  y.upto y+(ydim-1) do |yy|
32
- canvas[xx,yy] = ChunkyPNG::Color::BLACK
38
+ canvas[xx,yy] = foreground
33
39
  end
34
40
  end
35
41
  end
@@ -44,7 +50,7 @@ module Barby
44
50
  if bar
45
51
  x.upto(x+(xdim-1)) do |xx|
46
52
  y.upto y+(height-1) do |yy|
47
- canvas[xx,yy] = ChunkyPNG::Color::BLACK
53
+ canvas[xx,yy] = foreground
48
54
  end
49
55
  end
50
56
  end
@@ -101,6 +107,32 @@ module Barby
101
107
  @margin || 10
102
108
  end
103
109
 
110
+
111
+ def background=(c)
112
+ @background = if c.is_a?(String) || c.is_a?(Symbol)
113
+ ChunkyPNG::Color.html_color(c.to_sym)
114
+ else
115
+ c
116
+ end
117
+ end
118
+
119
+ def background
120
+ @background || ChunkyPNG::Color::WHITE
121
+ end
122
+
123
+ def foreground=(c)
124
+ @foreground = if c.is_a?(String) || c.is_a?(Symbol)
125
+ ChunkyPNG::Color.html_color(c.to_sym)
126
+ else
127
+ c
128
+ end
129
+ end
130
+
131
+ def foreground
132
+ @foreground || ChunkyPNG::Color::BLACK
133
+ end
134
+
135
+
104
136
  def length
105
137
  barcode.two_dimensional? ? encoding.first.length : encoding.length
106
138
  end
@@ -7,13 +7,7 @@ module Barby
7
7
 
8
8
  register :to_pdf, :annotate_pdf
9
9
 
10
- attr_writer :xdim, :ydim, :x, :y, :height, :margin, :unbleed
11
-
12
-
13
- def initialize(*)
14
- super
15
- @xdim, @ydim, @x, @y, @height, @margin, @unbleed = nil
16
- end
10
+ attr_writer :xdim, :ydim, :x, :y, :height, :margin, :unbleed, :color
17
11
 
18
12
  def to_pdf(opts={})
19
13
  doc_opts = opts.delete(:document) || {}
@@ -26,6 +20,9 @@ module Barby
26
20
  with_options opts do
27
21
  xpos, ypos = x, y
28
22
  orig_xpos = xpos
23
+ orig_color = pdf.fill_color
24
+
25
+ pdf.fill_color = color if color
29
26
 
30
27
  if barcode.two_dimensional?
31
28
  boolean_groups.reverse_each do |groups|
@@ -55,9 +52,11 @@ module Barby
55
52
  end
56
53
  xpos += (xdim*amount)
57
54
  end
58
- end
55
+ end#if
59
56
 
60
- end
57
+ pdf.fill_color = orig_color
58
+
59
+ end#with_options
61
60
 
62
61
  pdf
63
62
  end
@@ -113,6 +112,10 @@ module Barby
113
112
  @unbleed || 0
114
113
  end
115
114
 
115
+ def color
116
+ @color
117
+ end
118
+
116
119
 
117
120
  private
118
121
 
@@ -4,21 +4,25 @@ require 'rmagick'
4
4
  module Barby
5
5
 
6
6
 
7
- #Renders images from barcodes using RMagick
7
+ # Renders images from barcodes using RMagick
8
8
  #
9
- #Registers the to_png, to_gif, to_jpg and to_image methods
9
+ # Registers the to_png, to_gif, to_jpg and to_image methods
10
+ #
11
+ # Options:
12
+ #
13
+ # * xdim -
14
+ # * ydim - 2D only
15
+ # * height - 1D only
16
+ # * margin -
17
+ # * foreground - RMagick "colorspec"
18
+ # * background - ^
10
19
  class RmagickOutputter < Outputter
11
20
 
12
21
  register :to_png, :to_gif, :to_jpg, :to_image
13
22
 
14
- attr_writer :height, :xdim, :ydim, :margin
23
+ attr_writer :height, :xdim, :ydim, :margin, :foreground, :background
15
24
 
16
25
 
17
- def initialize(*)
18
- super
19
- @height, @xdim, @ydim, @margin = nil
20
- end
21
-
22
26
  #Returns a string containing a PNG image
23
27
  def to_png(*a)
24
28
  to_blob('png', *a)
@@ -48,8 +52,10 @@ module Barby
48
52
  #Returns an instance of Magick::Image
49
53
  def to_image(opts={})
50
54
  with_options opts do
51
- canvas = Magick::Image.new(full_width, full_height)
55
+ b = background #Capture locally because Magick::Image.new block uses instance_eval
56
+ canvas = Magick::Image.new(full_width, full_height){ self.background_color = b }
52
57
  bars = Magick::Draw.new
58
+ bars.fill = foreground
53
59
 
54
60
  x1 = margin
55
61
  y1 = margin
@@ -64,7 +70,14 @@ module Barby
64
70
  if x1 == x2 && y1 == y2
65
71
  bars.point(x1,y1)
66
72
  else
67
- bars.rectangle(x1, y1, x2, y2)
73
+ # For single pixel lines, use line
74
+ if x1 == x2
75
+ bars.line(x1, y1, x1, y2)
76
+ elsif y1 == y2
77
+ bars.line(x1, y1, x2, y1)
78
+ else
79
+ bars.rectangle(x1, y1, x2, y2)
80
+ end
68
81
  end
69
82
  end
70
83
  x1 += xdim
@@ -77,7 +90,12 @@ module Barby
77
90
  if bar
78
91
  x2 = x1+(xdim-1)
79
92
  y2 = y1+(height-1)
80
- bars.rectangle(x1, y1, x2, y2)
93
+ # For single pixel width, use line
94
+ if x1 == x2
95
+ bars.line(x1, y1, x1, y2)
96
+ else
97
+ bars.rectangle(x1, y1, x2, y2)
98
+ end
81
99
  end
82
100
  x1 += xdim
83
101
  end
@@ -134,6 +152,15 @@ module Barby
134
152
  end
135
153
 
136
154
 
155
+ def foreground
156
+ @foreground || 'black'
157
+ end
158
+
159
+ def background
160
+ @background || 'white'
161
+ end
162
+
163
+
137
164
  end
138
165
 
139
166
 
@@ -19,14 +19,9 @@ module Barby
19
19
 
20
20
  register :to_svg, :bars_to_rects, :bars_to_path
21
21
 
22
- attr_writer :title, :xdim, :ydim, :height, :rmargin, :lmargin, :tmargin, :bmargin, :xmargin, :ymargin, :margin
22
+ attr_writer :title, :xdim, :ydim, :height, :rmargin, :lmargin, :tmargin, :bmargin, :xmargin, :ymargin, :margin, :foreground, :background
23
23
 
24
24
 
25
- def initialize(*)
26
- super
27
- @title, @xdim, @ydim, @height, @rmargin, @lmargin, @tmargin, @bmargin, @xmargin, @ymargin, @margin = nil
28
- end
29
-
30
25
  def to_svg(opts={})
31
26
  with_options opts do
32
27
  case opts[:use]
@@ -39,11 +34,11 @@ module Barby
39
34
 
40
35
  <<-"EOT"
41
36
  <?xml version="1.0" encoding="UTF-8"?>
42
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="#{svg_width(opts)}px" height="#{svg_height(opts)}px" viewBox="0 0 #{svg_width(opts)} #{svg_height(opts)}" version="1.1">
37
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="#{svg_width(opts)}px" height="#{svg_height(opts)}px" viewBox="0 0 #{svg_width(opts)} #{svg_height(opts)}" version="1.1" preserveAspectRatio="none" >
43
38
  <title>#{escape title}</title>
44
39
  <g id="canvas" #{transform(opts)}>
45
- <rect x="0" y="0" width="#{full_width}px" height="#{full_height}px" fill="white" />
46
- <g id="barcode" fill="black">
40
+ <rect x="0" y="0" width="#{full_width}px" height="#{full_height}px" fill="#{background}" />
41
+ <g id="barcode" fill="#{foreground}">
47
42
  #{bars}
48
43
  </g></g>
49
44
  </svg>
@@ -51,7 +46,6 @@ EOT
51
46
  end
52
47
  end
53
48
 
54
-
55
49
  def bars_to_rects(opts={})
56
50
  rects = ''
57
51
  with_options opts do
@@ -85,14 +79,12 @@ EOT
85
79
  rects
86
80
  end
87
81
 
88
-
89
82
  def bars_to_path(opts={})
90
83
  with_options opts do
91
84
  %Q|<path stroke="black" stroke-width="#{xdim}" d="#{bars_to_path_data(opts)}" />|
92
85
  end
93
86
  end
94
87
 
95
-
96
88
  def bars_to_path_data(opts={})
97
89
  path_data = ''
98
90
  with_options opts do
@@ -124,12 +116,10 @@ EOT
124
116
  path_data
125
117
  end
126
118
 
127
-
128
119
  def title
129
120
  @title || barcode.to_s
130
121
  end
131
122
 
132
-
133
123
  def width
134
124
  length * xdim
135
125
  end
@@ -189,6 +179,13 @@ EOT
189
179
  barcode.two_dimensional? ? encoding.first.length : encoding.length
190
180
  end
191
181
 
182
+ def foreground
183
+ @foreground || '#000'
184
+ end
185
+
186
+ def background
187
+ @background || '#fff'
188
+ end
192
189
 
193
190
  def svg_width(opts={})
194
191
  opts[:rot] ? full_height : full_width
@@ -198,12 +195,10 @@ EOT
198
195
  opts[:rot] ? full_width : full_height
199
196
  end
200
197
 
201
-
202
198
  def transform(opts={})
203
199
  opts[:rot] ? %Q|transform="rotate(-90) translate(-#{full_width}, 0)"| : nil
204
200
  end
205
201
 
206
-
207
202
  private
208
203
 
209
204
  def _xmargin
@@ -223,8 +218,6 @@ EOT
223
218
  str.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;')
224
219
  end
225
220
 
226
-
227
221
  end
228
222
 
229
-
230
223
  end
@@ -28,7 +28,7 @@ module Barby
28
28
  self.barcode = barcode
29
29
  end
30
30
 
31
-
31
+
32
32
  #Register one or more handler methods with this outputter
33
33
  #Barcodes will then be able to use these methods to get the output
34
34
  #from the outputter. For example, if you have an ImageOutputter,
data/lib/barby/version.rb CHANGED
@@ -2,8 +2,8 @@ module Barby #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 6
5
- TINY = 5
5
+ TINY = 8
6
6
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
7
+ STRING = [MAJOR, MINOR, TINY].join('.').freeze
8
8
  end
9
9
  end
data/test/barcodes.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'code_128_test'
2
+
3
+ require 'code_25_test'
4
+ require 'code_25_interleaved_test'
5
+ require 'code_25_iata_test'
6
+
7
+ require 'code_39_test'
8
+ require 'code_93_test'
9
+
10
+ require 'codabar_test'
11
+
12
+ require 'ean13_test'
13
+ require 'ean8_test'
14
+ require 'bookland_test'
15
+ require 'upc_supplemental_test'
16
+
17
+ require 'data_matrix_test'
18
+ require 'qr_code_test'
19
+
20
+ #require 'pdf_417_test'