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