Skip to content

Commit

Permalink
Add unbleed attribute to PrawnOutputter
Browse files Browse the repository at this point in the history
  • Loading branch information
toretore committed Aug 18, 2010
1 parent fc7c8c3 commit 5fc122e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/barby/outputter/prawn_outputter.rb
Expand Up @@ -7,7 +7,7 @@ class PrawnOutputter < Outputter

register :to_pdf, :annotate_pdf

attr_accessor :xdim, :ydim, :x, :y, :height, :margin
attr_accessor :xdim, :ydim, :x, :y, :height, :margin, :unbleed


def to_pdf(opts={})
Expand All @@ -26,11 +26,11 @@ def annotate_pdf(pdf, opts={})
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.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)
Expand All @@ -41,11 +41,11 @@ def annotate_pdf(pdf, opts={})
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.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)
Expand Down Expand Up @@ -101,6 +101,13 @@ def ydim
@ydim || xdim
end

#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.
def unbleed
@unbleed || 0
end


private

Expand Down

0 comments on commit 5fc122e

Please sign in to comment.