Class: Barby::PrawnOutputter

Inherits:
Outputter show all
Defined in:
lib/barby/outputter/prawn_outputter.rb

Instance Attribute Summary

Attributes inherited from Outputter

#barcode

Instance Method Summary collapse

Methods inherited from Outputter

#initialize, register

Constructor Details

This class inherits a constructor from Barby::Outputter

Instance Method Details

#annotate_pdf(pdf, opts = {}) ⇒ Object



17
18
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
# File 'lib/barby/outputter/prawn_outputter.rb', line 17

def annotate_pdf(pdf, opts={})
  opts = options(opts)
  xpos, ypos, height, xdim = opts[:x], opts[:y], opts[:height], opts[:xdim]
  ydim = opts[:ydim] || xdim
  orig_xpos = xpos

  if barcode.two_dimensional?
    boolean_groups.reverse_each do |groups|
      groups.each do |bar,amount|
        if bar
          pdf.move_to(xpos, ypos)
          pdf.line_to(xpos, ypos+ydim)
          pdf.line_to(xpos+(xdim*amount), ypos+ydim)
          pdf.line_to(xpos+(xdim*amount), ypos)
          pdf.line_to(xpos, ypos)
          pdf.fill
        end
        xpos += (xdim*amount)
      end
      xpos = orig_xpos
      ypos += ydim
    end
  else
    boolean_groups.each do |bar,amount|
      if bar
        pdf.move_to(xpos, ypos)
        pdf.line_to(xpos, ypos+height)
        pdf.line_to(xpos+(xdim*amount), ypos+height)
        pdf.line_to(xpos+(xdim*amount), ypos)
        pdf.line_to(xpos, ypos)
        pdf.fill
      end
      xpos += (xdim*amount)
    end
  end

  pdf
end

#to_pdf(opts = {}) ⇒ Object



11
12
13
14
# File 'lib/barby/outputter/prawn_outputter.rb', line 11

def to_pdf(opts={})
  opts = options(opts)
  annotate_pdf(Prawn::Document.new(opts[:document]), opts).render
end