Class | Barby::PngOutputter |
In: |
lib/barby/outputter/png_outputter.rb
|
Parent: | Outputter |
height | [RW] | |
margin | [RW] | |
width | [RW] | |
xdim | [RW] | |
ydim | [RW] |
# File lib/barby/outputter/png_outputter.rb, line 74 74: def full_height 75: height + (margin * 2) 76: end
# File lib/barby/outputter/png_outputter.rb, line 70 70: def full_width 71: width + (margin * 2) 72: end
# File lib/barby/outputter/png_outputter.rb, line 66 66: def height 67: barcode.two_dimensional? ? (ydim * encoding.length) : (@height || 100) 68: end
# File lib/barby/outputter/png_outputter.rb, line 90 90: def length 91: barcode.two_dimensional? ? encoding.first.length : encoding.length 92: end
Creates a PNG::Canvas object and renders the barcode on it
# File lib/barby/outputter/png_outputter.rb, line 17 17: def to_canvas(opts={}) 18: with_options opts do 19: canvas = PNG::Canvas.new(full_width, full_height, PNG::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] = PNG::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] = PNG::Color::Black 44: end 45: end 46: end 47: x += xdim 48: end 49: end 50: 51: canvas 52: end 53: end
Renders the barcode to a PNG image
# File lib/barby/outputter/png_outputter.rb, line 57 57: def to_png(*a) 58: PNG.new(to_canvas(*a)).to_blob 59: end