| Class | Barby::PrawnOutputter |
| In: |
lib/barby/outputter/prawn_outputter.rb
|
| Parent: | Outputter |
# File lib/barby/outputter/prawn_outputter.rb, line 17
17: def annotate_pdf(pdf, opts={})
18: opts = options(opts)
19: xpos, ypos, height, xdim = opts[:x], opts[:y], opts[:height], opts[:xdim]
20: ydim = opts[:ydim] || xdim
21: orig_xpos = xpos
22:
23: if barcode.two_dimensional?
24: boolean_groups.reverse_each do |groups|
25: groups.each do |bar,amount|
26: if bar
27: pdf.move_to(xpos, ypos)
28: pdf.line_to(xpos, ypos+ydim)
29: pdf.line_to(xpos+(xdim*amount), ypos+ydim)
30: pdf.line_to(xpos+(xdim*amount), ypos)
31: pdf.line_to(xpos, ypos)
32: pdf.fill
33: end
34: xpos += (xdim*amount)
35: end
36: xpos = orig_xpos
37: ypos += ydim
38: end
39: else
40: boolean_groups.each do |bar,amount|
41: if bar
42: pdf.move_to(xpos, ypos)
43: pdf.line_to(xpos, ypos+height)
44: pdf.line_to(xpos+(xdim*amount), ypos+height)
45: pdf.line_to(xpos+(xdim*amount), ypos)
46: pdf.line_to(xpos, ypos)
47: pdf.fill
48: end
49: xpos += (xdim*amount)
50: end
51: end
52:
53: pdf
54: end
# File lib/barby/outputter/prawn_outputter.rb, line 11
11: def to_pdf(opts={})
12: opts = options(opts)
13: annotate_pdf(Prawn::Document.new(opts[:document]), opts).render
14: end
# File lib/barby/outputter/prawn_outputter.rb, line 59
59: def default_options
60: @default_options ||= {
61: :margin => 5,
62: :height => 100,
63: :xdim => 1
64: }
65: end
# File lib/barby/outputter/prawn_outputter.rb, line 76
76: def document_options(opts, doc_opts)
77: o = doc_opts.dup
78: #o[:page_size] ||= page_size(opts[:xdim], opts[:height], opts[:margin])
79: #%w(left right top bottom).each{|s| o[:"#{s}_margin"] ||= opts[:margin] }
80: o[:page_size] ||= 'A4' #Prawn doesn't currently support custom page sizes
81: o
82: end
# File lib/barby/outputter/prawn_outputter.rb, line 92
92: def height(height, margin)
93: height + (margin * 2)
94: end
# File lib/barby/outputter/prawn_outputter.rb, line 67
67: def options(opts={})
68: doc_opts = opts.delete(:document) || {}
69: opts = default_options.merge(opts)
70: opts[:x] ||= opts[:margin]
71: opts[:y] ||= opts[:margin]
72: opts[:document] = document_options(opts, doc_opts)
73: opts
74: end
# File lib/barby/outputter/prawn_outputter.rb, line 84
84: def page_size(xdim, height, margin)
85: [width(xdim,margin), height(height,margin)]
86: end