diff --git a/docs/dsl/save_pdf.rst b/docs/dsl/save_pdf.rst index a3015f1..b4a3d43 100644 --- a/docs/dsl/save_pdf.rst +++ b/docs/dsl/save_pdf.rst @@ -44,7 +44,12 @@ gap trim default: ``0`` - the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports :doc:`/units`. + the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports :doc:`/units`. Must be the same for all cards. + +trim_radius + default: ``0`` + + the rounded rectangle radius around the card to trim before saving. Supports :doc:`/units`. Must be the same for all cards. crop_marks default: ``false`` diff --git a/docs/dsl/save_sheet.rst b/docs/dsl/save_sheet.rst index 1877f41..d2bfc40 100644 --- a/docs/dsl/save_sheet.rst +++ b/docs/dsl/save_sheet.rst @@ -54,7 +54,12 @@ gap trim default ``0`` - the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports :doc:`/units`. + the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play). Supports :doc:`/units`. Must be the same for all cards. + +trim_radius + default: ``0`` + + the rounded rectangle radius around the card to trim before saving. Supports :doc:`/units`. Must be the same for all cards. rtl default ``false`` diff --git a/lib/squib/api/save.rb b/lib/squib/api/save.rb index e0fc42f..bee6157 100644 --- a/lib/squib/api/save.rb +++ b/lib/squib/api/save.rb @@ -58,7 +58,7 @@ module Squib else tmpl = Sprue.load sprue_file.sprue, dpi Graphics::SaveSpruePNG. - new(self, tmpl, batch). + new(self, tmpl, sheet). render_sheet(range) end end diff --git a/lib/squib/args/sheet.rb b/lib/squib/args/sheet.rb index 12af8e1..274646e 100644 --- a/lib/squib/args/sheet.rb +++ b/lib/squib/args/sheet.rb @@ -21,6 +21,7 @@ module Squib def self.parameters { + count_format: '%02d', crop_margin_bottom: 0, crop_margin_left: 0, crop_margin_right: 0, @@ -35,6 +36,7 @@ module Squib gap: 0, height: 2550, margin: 75, + prefix: 'sheet_', rows: :infinite, columns: 5, trim_radius: 38, @@ -91,8 +93,12 @@ module Squib (count.to_f / columns.to_f).ceil end - def full_filename - "#{dir}/#{file}" + def full_filename(i=nil) + if i.nil? + "#{dir}/#{file}" + else + "#{dir}/#{prefix}#{count_format % i}.png" + end end def crop_coords(x, y, deck_w, deck_h) diff --git a/lib/squib/graphics/save_sprue.rb b/lib/squib/graphics/save_sprue.rb index 7c9211a..8135fab 100644 --- a/lib/squib/graphics/save_sprue.rb +++ b/lib/squib/graphics/save_sprue.rb @@ -2,11 +2,11 @@ module Squib module Graphics # Helper class to generate templated sheet. class SaveSprue - def initialize(deck, tmpl, save_args) + def initialize(deck, tmpl, sheet_args) @deck = deck @tmpl = tmpl @page_number = 1 - @save_args = save_args #might be Args::Sheet or Args::SaveBatch + @sheet_args = sheet_args # might be Args::Sheet or Args::SaveBatch @overlay_lines = @tmpl.crop_lines.select do |line| line['overlay_on_cards'] end @@ -32,7 +32,7 @@ module Squib draw_card cc, card, slot['x'], slot['y'], slot['rotate'], - @save_args.trim[i], @save_args.trim_radius[i] + @sheet_args.trim, @sheet_args.trim_radius bar.increment end @@ -122,15 +122,11 @@ module Squib end def check_oversized_card - all_fit = @save_args.trim.inject(true) do |fits, trim| - fits && - (@deck.width - 2.0 * trim) <= @tmpl.card_width && - (@deck.height - 2.0 * trim) <= @tmpl.card_height - end Squib.logger.warn { - 'Card size is larger than sprue\'s expected card size. '\ - 'Cards may overlap.' - } unless all_fit + "Card size is larger than sprue's expected card size "\ + "of #{@tmpl.card_width}x#{@tmpl.card_height}. Cards may overlap." + } if (@deck.width - 2.0 * @sheet_args.trim) > @tmpl.card_width || + (@deck.height - 2.0 * @sheet_args.trim) > @tmpl.card_height end def draw_card(cc, card, x, y, angle, trim, trim_radius) @@ -182,7 +178,7 @@ module Squib end def full_filename - @save_args.full_filename + @sheet_args.full_filename end end @@ -202,7 +198,7 @@ module Squib end def full_filename - @save_args.full_filename @page_number + @sheet_args.full_filename @page_number end end end diff --git a/samples/sprues/_advanced_sprues.rb b/samples/sprues/_advanced_sprues.rb index 4dd454a..08a5997 100644 --- a/samples/sprues/_advanced_sprues.rb +++ b/samples/sprues/_advanced_sprues.rb @@ -1,11 +1,10 @@ -require 'squib' +require_relative '../../lib/squib' # This is a more advanced example of Sprues # (mostly so we can have a torturous regression test) # - Uses a custom sprue # - Weird rotations # - Center-positioned -# - Uses per-card trim and trim_radius # - Multiple pages Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do background color: :blue #blue never shows up! Yay clipping... @@ -18,16 +17,8 @@ Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do text str: (0..9).map{ |i| "Card #{i}\n\n" }, font: 'Sans 32', align: :center, valign: :middle, height: :deck, width: :deck - - # Per-card trims just for funsies - trims = ['0.2in'] * 9 - trims[0] = '0.3in' - trims[3] = '0.4in' - trim_radii = ['10pt'] * 9 - trim_radii[1] = '0.2in' - trim_radii[3] = '0.75in' save_sheet sprue: 'my_sprues/weird_sprue.yml', - trim: trims, trim_radius: trim_radii, + trim: '0.2in', trim_radius: '10pt', prefix: "advanced_sprues_" end