parent
d848178bfe
commit
086fd5fad9
|
|
@ -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,11 +198,15 @@ 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
|
||||
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
|
||||
Squib.logger.debug {"After convert_units: #{opts}"}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
|||
# Place on multiple pages over the PDF, with bleed beeing trimmed off
|
||||
save_pdf file: 'save-pdf.pdf', margin: 75, gap: 5, trim: 37
|
||||
|
||||
# PDFs also support arbitrary paper sizes, in pixels or any other supported units
|
||||
save_pdf file: 'save-pdf-small.pdf',
|
||||
width: '7in', height: '5in',
|
||||
range: 0..1
|
||||
|
||||
# Note that our PNGs still are not trimmed even though the pdf ones were
|
||||
save_png range: 1, prefix: 'saves_notrim_'
|
||||
|
||||
|
|
|
|||
|
|
@ -542,6 +542,10 @@ cairo: set_source([MockDouble, -37, -37])
|
|||
cairo: paint([])
|
||||
cairo: set_source([MockDouble, 1650, 75])
|
||||
cairo: paint([])
|
||||
cairo: set_source([MockDouble, 75, 75])
|
||||
cairo: paint([])
|
||||
cairo: set_source([MockDouble, 175, 75])
|
||||
cairo: paint([])
|
||||
surface: write_to_png(["_output/saves_notrim_01.png"])
|
||||
cairo: set_source([MockDouble, -37, -37])
|
||||
cairo: paint([])
|
||||
|
|
|
|||
|
|
@ -176,6 +176,13 @@ describe Squib::InputHelpers do
|
|||
expect(opts).to eq({:x => [236.2204722] }) #assume 300dpi default
|
||||
end
|
||||
|
||||
it 'handles non-expading singletons' do
|
||||
args = {margin: '1in', trim: '1in', gap: '1in'}
|
||||
needed_params = [:margin, :trim, :gap]
|
||||
opts = @deck.send(:convert_units, args, needed_params)
|
||||
expect(opts).to eq({margin: 300, trim: 300, gap: 300}) #assume 300dpi default
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#rowify' do
|
||||
|
|
|
|||
Loading…
Reference in New Issue