From 5fc122e085066c1ca5798e59019b3db7a15f92ac Mon Sep 17 00:00:00 2001 From: Tore Darell Date: Wed, 18 Aug 2010 13:47:10 +0200 Subject: [PATCH] Add unbleed attribute to PrawnOutputter --- lib/barby/outputter/prawn_outputter.rb | 29 ++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/barby/outputter/prawn_outputter.rb b/lib/barby/outputter/prawn_outputter.rb index 2e9ab2d..9e422c3 100644 --- a/lib/barby/outputter/prawn_outputter.rb +++ b/lib/barby/outputter/prawn_outputter.rb @@ -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={}) @@ -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) @@ -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) @@ -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