Refactoring
parent
39a23ea12b
commit
70a1b540c4
|
|
@ -14,14 +14,15 @@ module Squib
|
|||
# @return [nil]
|
||||
# @api public
|
||||
def save_pdf(opts = {})
|
||||
p = needs(opts, [:file_to_save, :creatable_dir, :margin, :gap, :trim])
|
||||
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too
|
||||
p = needs(opts, [:range, :file_to_save, :creatable_dir, :margin, :gap, :trim])
|
||||
width = 11 * @dpi
|
||||
height = 8.5 * @dpi #TODO: allow this to be specified too
|
||||
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height))
|
||||
x = p[:margin] ; y = p[:margin]
|
||||
|
||||
x = p[:margin]
|
||||
y = p[:margin]
|
||||
@progress_bar.start("Saving PDF to #{p[:dir]}/#{p[:file]}", p[:range].size) do |bar|
|
||||
@cards.each_with_index do |card, i|
|
||||
surface = trim(card.cairo_surface, p[:trim], @width, @height)
|
||||
p[:range].each do |i|
|
||||
surface = trim(@cards[i].cairo_surface, p[:trim], @width, @height)
|
||||
cc.set_source(surface, x, y)
|
||||
cc.paint
|
||||
bar.increment
|
||||
|
|
@ -30,7 +31,8 @@ module Squib
|
|||
x = p[:margin]
|
||||
y += surface.height + p[:gap]
|
||||
if y > (height - surface.height - p[:margin])
|
||||
x = p[:margin] ; y = p[:margin]
|
||||
x = p[:margin]
|
||||
y = p[:margin]
|
||||
cc.show_page #next page
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ module Squib
|
|||
# :nodoc:
|
||||
# @api private
|
||||
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
|
||||
width=@width if width==:native; height=@height if height==:native
|
||||
width = @width if width == :native
|
||||
height = @height if height == :native
|
||||
use_cairo do |cc|
|
||||
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
||||
cc.set_source_color(stroke_color)
|
||||
|
|
|
|||
Loading…
Reference in New Issue