Class: Barby::PDFWriterOutputter

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

Overview

Annotates a PDFWriter document with the barcode

Registers the annotate_pdf method

Instance Attribute Summary collapse

Attributes inherited from Outputter

#barcode

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#xdimObject

Returns the value of attribute xdim.



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

def xdim
  @xdim
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

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

Annotate a PDFWriter document with the barcode

Valid options are:

x, y - The point in the document to start rendering from height - The height of the bars in PDF units xdim - The X dimension in PDF units



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
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 22

def annotate_pdf(pdf, options={})
  with_options options do

    xpos, ypos = x, y
    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).
              line_to(xpos, ypos+xdim).
              line_to(xpos+(xdim*amount), ypos+xdim).
              line_to(xpos+(xdim*amount), ypos).
              line_to(xpos, ypos).
              fill
          end
          xpos += (xdim*amount)
        end
        xpos = orig_xpos
        ypos += xdim
      end
    else
      boolean_groups.each do |bar,amount|
        if bar
          pdf.move_to(xpos, ypos).
            line_to(xpos, ypos+height).
            line_to(xpos+(xdim*amount), ypos+height).
            line_to(xpos+(xdim*amount), ypos).
            line_to(xpos, ypos).
            fill
        end
        xpos += (xdim*amount)
      end
    end

  end

  pdf
end