Class: Barby::PrawnOutputter
- Defined in:
- lib/barby/outputter/prawn_outputter.rb
Instance Attribute Summary collapse
- #color ⇒ Object
- #height ⇒ Object
-
#margin ⇒ Object
Margin is used for x and y if not given explicitly, effectively placing the barcode <margin> points from the [left,bottom] of the page.
-
#unbleed ⇒ Object
Defines an amount to reduce black bars/squares by to account for “ink bleed” If xdim = 3, unbleed = 0.2, a single/width black bar will be 2.6 wide For 2D, both x and y dimensions are reduced.
- #x ⇒ Object
- #xdim ⇒ Object
- #y ⇒ Object
- #ydim ⇒ Object
Attributes inherited from Outputter
Instance Method Summary collapse
- #annotate_pdf(pdf, opts = {}) ⇒ Object
- #full_height ⇒ Object
- #full_width ⇒ Object
- #length ⇒ Object
- #to_pdf(opts = {}) ⇒ Object
- #width ⇒ Object
Methods inherited from Outputter
#boolean_groups, #booleans, #encoding, #initialize, register, #two_dimensional?
Constructor Details
This class inherits a constructor from Barby::Outputter
Instance Attribute Details
#color ⇒ Object
115 116 117 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 115 def color @color end |
#height ⇒ Object
73 74 75 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 73 def height two_dimensional? ? (ydim * encoding.length) : (@height || 50) end |
#margin ⇒ Object
Margin is used for x and y if not given explicitly, effectively placing the barcode <margin> points from the [left,bottom] of the page. If you define x and y, there will be no margin. And if you don’t define margin, it’s 0.
88 89 90 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 88 def margin @margin || 0 end |
#unbleed ⇒ Object
Defines an amount to reduce black bars/squares by to account for “ink bleed” If xdim = 3, unbleed = 0.2, a single/width black bar will be 2.6 wide For 2D, both x and y dimensions are reduced.
111 112 113 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 111 def unbleed @unbleed || 0 end |
#x ⇒ Object
92 93 94 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 92 def x @x || margin end |
#xdim ⇒ Object
100 101 102 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 100 def xdim @xdim || 1 end |
#y ⇒ Object
96 97 98 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 96 def y @y || margin end |
#ydim ⇒ Object
104 105 106 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 104 def ydim @ydim || xdim end |
Instance Method Details
#annotate_pdf(pdf, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 19 def annotate_pdf(pdf, opts={}) opts do xpos, ypos = x, y orig_xpos = xpos orig_color = pdf.fill_color pdf.fill_color = color if color if .two_dimensional? boolean_groups.reverse_each do |groups| groups.each do |,amount| if pdf.move_to(xpos+unbleed, ypos+unbleed) pdf.line_to(xpos+unbleed, ypos+ydim-unbleed) pdf.line_to(xpos+(xdim*amount)-unbleed, ypos+ydim-unbleed) pdf.line_to(xpos+(xdim*amount)-unbleed, ypos+unbleed) pdf.line_to(xpos+unbleed, ypos+unbleed) pdf.fill end xpos += (xdim*amount) end xpos = orig_xpos ypos += ydim end else boolean_groups.each do |,amount| if pdf.move_to(xpos+unbleed, ypos) pdf.line_to(xpos+unbleed, ypos+height) pdf.line_to(xpos+(xdim*amount)-unbleed, ypos+height) pdf.line_to(xpos+(xdim*amount)-unbleed, ypos) pdf.line_to(xpos+unbleed, ypos) pdf.fill end xpos += (xdim*amount) end end#if pdf.fill_color = orig_color end#with_options pdf end |
#full_height ⇒ Object
81 82 83 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 81 def full_height height + (margin * 2) end |
#full_width ⇒ Object
77 78 79 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 77 def full_width width + (margin * 2) end |
#length ⇒ Object
65 66 67 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 65 def length two_dimensional? ? encoding.first.length : encoding.length end |
#to_pdf(opts = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 12 def to_pdf(opts={}) doc_opts = opts.delete(:document) || {} doc_opts[:page_size] ||= 'A4' annotate_pdf(Prawn::Document.new(doc_opts), opts).render end |
#width ⇒ Object
69 70 71 |
# File 'lib/barby/outputter/prawn_outputter.rb', line 69 def width length * xdim end |