Unit conversion on save_pdf, and arbitrary paper sizes
Closes #21 and #20
This commit is contained in:
@@ -62,7 +62,7 @@ module Squib
|
||||
# @api public
|
||||
def showcase(opts = {})
|
||||
opts = {file: 'showcase.png', fill_color: :white}.merge(opts)
|
||||
opts = needs(opts,[:range, :trim, :trim_radius, :creatable_dir, :file_to_save, :face])
|
||||
opts = needs(opts,[:range, :margin, :trim, :trim_radius, :creatable_dir, :file_to_save, :face])
|
||||
render_showcase(opts[:range], opts[:trim], opts[:trim_radius],
|
||||
opts[:scale], opts[:offset], opts[:fill_color],
|
||||
opts[:reflect_offset], opts[:reflect_percent], opts[:reflect_strength],
|
||||
|
||||
@@ -128,10 +128,15 @@ module Squib
|
||||
# value: the user-facing API key (e.g. radius: '1in')
|
||||
UNIT_CONVERSION_PARAMS = {
|
||||
:circle_radius => :radius,
|
||||
:gap => :gap,
|
||||
:height => :height,
|
||||
:margin => :margin,
|
||||
:paper_width => :width,
|
||||
:paper_height => :height,
|
||||
:rect_radius => :radius,
|
||||
:spacing => :spacing,
|
||||
:stroke_width => :stroke_width,
|
||||
:trim => :trim,
|
||||
:width => :width,
|
||||
:x => :x,
|
||||
:x1 => :x1,
|
||||
|
||||
@@ -8,16 +8,17 @@ module Squib
|
||||
#
|
||||
# @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
|
||||
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
|
||||
# @option opts margin [Integer] (75) the margin around the outside of the page
|
||||
# @option opts gap [Integer] (0) the space in pixels between the cards
|
||||
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
|
||||
# @option opts width [Integer] (3300) the height of the page in pixels. Default is 11in * 300dpi. Supports unit conversion.
|
||||
# @option opts height [Integer] (2550) the height of the page in pixels. Default is 8.5in * 300dpi. Supports unit conversion.
|
||||
# @option opts margin [Integer] (75) the margin around the outside of the page. Supports unit conversion.
|
||||
# @option opts gap [Integer] (0) the space in pixels between the cards. Supports unit conversion.
|
||||
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports unit conversion.
|
||||
# @return [nil]
|
||||
# @api public
|
||||
def save_pdf(opts = {})
|
||||
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))
|
||||
opts = {width: 3300, height: 2550}.merge(opts)
|
||||
p = needs(opts, [:range, :paper_width, :paper_height, :file_to_save, :creatable_dir, :margin, :gap, :trim])
|
||||
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", p[:width], p[:height]))
|
||||
x = p[:margin]
|
||||
y = p[:margin]
|
||||
@progress_bar.start("Saving PDF to #{p[:dir]}/#{p[:file]}", p[:range].size) do |bar|
|
||||
@@ -27,10 +28,10 @@ module Squib
|
||||
cc.paint
|
||||
bar.increment
|
||||
x += surface.width + p[:gap]
|
||||
if x > (width - surface.width - p[:margin])
|
||||
if x > (p[:width] - surface.width - p[:margin])
|
||||
x = p[:margin]
|
||||
y += surface.height + p[:gap]
|
||||
if y > (height - surface.height - p[:margin])
|
||||
if y > (p[:height] - surface.height - p[:margin])
|
||||
x = p[:margin]
|
||||
y = p[:margin]
|
||||
cc.show_page #next page
|
||||
@@ -51,7 +52,7 @@ module Squib
|
||||
# @option opts [String] prefix (card_) the prefix of the file name(s)
|
||||
# @option opts [String] count_format (%02d) the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for Kernel::sprintf for specifics)
|
||||
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
|
||||
# @option opts margin [Integer] (0) the margin around the outside of the page
|
||||
# @option opts margin [Integer] (0) the margin around the outside of the page.
|
||||
# @option opts gap [Integer] (0) the space in pixels between the cards
|
||||
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
|
||||
# @return [nil]
|
||||
|
||||
@@ -198,10 +198,14 @@ module Squib
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def convert_units(opts, needed_params)
|
||||
Squib::UNIT_CONVERSION_PARAMS.each_pair do |param_name, api_param|
|
||||
UNIT_CONVERSION_PARAMS.each_pair do |param_name, api_param|
|
||||
if needed_params.include? param_name
|
||||
opts[api_param].each_with_index do |arg, i|
|
||||
opts[api_param][i] = Args::UnitConversion.parse(arg, @dpi)
|
||||
if EXPANDING_PARAMS.include? param_name
|
||||
opts[api_param].each_with_index do |arg, i|
|
||||
opts[api_param][i] = Args::UnitConversion.parse(arg, @dpi)
|
||||
end
|
||||
else #not an expanding param
|
||||
opts[api_param] = Args::UnitConversion.parse(opts[api_param], @dpi)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user