sprues: better handling of trim args
parent
3bf5eeb102
commit
aee8884a9e
|
|
@ -44,7 +44,12 @@ gap
|
||||||
trim
|
trim
|
||||||
default: ``0``
|
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
|
crop_marks
|
||||||
default: ``false``
|
default: ``false``
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,12 @@ gap
|
||||||
trim
|
trim
|
||||||
default ``0``
|
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
|
rtl
|
||||||
default ``false``
|
default ``false``
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ module Squib
|
||||||
else
|
else
|
||||||
tmpl = Sprue.load sprue_file.sprue, dpi
|
tmpl = Sprue.load sprue_file.sprue, dpi
|
||||||
Graphics::SaveSpruePNG.
|
Graphics::SaveSpruePNG.
|
||||||
new(self, tmpl, batch).
|
new(self, tmpl, sheet).
|
||||||
render_sheet(range)
|
render_sheet(range)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ module Squib
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
{
|
{
|
||||||
|
count_format: '%02d',
|
||||||
crop_margin_bottom: 0,
|
crop_margin_bottom: 0,
|
||||||
crop_margin_left: 0,
|
crop_margin_left: 0,
|
||||||
crop_margin_right: 0,
|
crop_margin_right: 0,
|
||||||
|
|
@ -35,6 +36,7 @@ module Squib
|
||||||
gap: 0,
|
gap: 0,
|
||||||
height: 2550,
|
height: 2550,
|
||||||
margin: 75,
|
margin: 75,
|
||||||
|
prefix: 'sheet_',
|
||||||
rows: :infinite,
|
rows: :infinite,
|
||||||
columns: 5,
|
columns: 5,
|
||||||
trim_radius: 38,
|
trim_radius: 38,
|
||||||
|
|
@ -91,8 +93,12 @@ module Squib
|
||||||
(count.to_f / columns.to_f).ceil
|
(count.to_f / columns.to_f).ceil
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_filename
|
def full_filename(i=nil)
|
||||||
|
if i.nil?
|
||||||
"#{dir}/#{file}"
|
"#{dir}/#{file}"
|
||||||
|
else
|
||||||
|
"#{dir}/#{prefix}#{count_format % i}.png"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def crop_coords(x, y, deck_w, deck_h)
|
def crop_coords(x, y, deck_w, deck_h)
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ module Squib
|
||||||
module Graphics
|
module Graphics
|
||||||
# Helper class to generate templated sheet.
|
# Helper class to generate templated sheet.
|
||||||
class SaveSprue
|
class SaveSprue
|
||||||
def initialize(deck, tmpl, save_args)
|
def initialize(deck, tmpl, sheet_args)
|
||||||
@deck = deck
|
@deck = deck
|
||||||
@tmpl = tmpl
|
@tmpl = tmpl
|
||||||
@page_number = 1
|
@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|
|
@overlay_lines = @tmpl.crop_lines.select do |line|
|
||||||
line['overlay_on_cards']
|
line['overlay_on_cards']
|
||||||
end
|
end
|
||||||
|
|
@ -32,7 +32,7 @@ module Squib
|
||||||
draw_card cc, card,
|
draw_card cc, card,
|
||||||
slot['x'], slot['y'],
|
slot['x'], slot['y'],
|
||||||
slot['rotate'],
|
slot['rotate'],
|
||||||
@save_args.trim[i], @save_args.trim_radius[i]
|
@sheet_args.trim, @sheet_args.trim_radius
|
||||||
|
|
||||||
bar.increment
|
bar.increment
|
||||||
end
|
end
|
||||||
|
|
@ -122,15 +122,11 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_oversized_card
|
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 {
|
Squib.logger.warn {
|
||||||
'Card size is larger than sprue\'s expected card size. '\
|
"Card size is larger than sprue's expected card size "\
|
||||||
'Cards may overlap.'
|
"of #{@tmpl.card_width}x#{@tmpl.card_height}. Cards may overlap."
|
||||||
} unless all_fit
|
} if (@deck.width - 2.0 * @sheet_args.trim) > @tmpl.card_width ||
|
||||||
|
(@deck.height - 2.0 * @sheet_args.trim) > @tmpl.card_height
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_card(cc, card, x, y, angle, trim, trim_radius)
|
def draw_card(cc, card, x, y, angle, trim, trim_radius)
|
||||||
|
|
@ -182,7 +178,7 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_filename
|
def full_filename
|
||||||
@save_args.full_filename
|
@sheet_args.full_filename
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -202,7 +198,7 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_filename
|
def full_filename
|
||||||
@save_args.full_filename @page_number
|
@sheet_args.full_filename @page_number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
require 'squib'
|
require_relative '../../lib/squib'
|
||||||
|
|
||||||
# This is a more advanced example of Sprues
|
# This is a more advanced example of Sprues
|
||||||
# (mostly so we can have a torturous regression test)
|
# (mostly so we can have a torturous regression test)
|
||||||
# - Uses a custom sprue
|
# - Uses a custom sprue
|
||||||
# - Weird rotations
|
# - Weird rotations
|
||||||
# - Center-positioned
|
# - Center-positioned
|
||||||
# - Uses per-card trim and trim_radius
|
|
||||||
# - Multiple pages
|
# - Multiple pages
|
||||||
Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do
|
Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do
|
||||||
background color: :blue #blue never shows up! Yay clipping...
|
background color: :blue #blue never shows up! Yay clipping...
|
||||||
|
|
@ -19,15 +18,7 @@ Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do
|
||||||
font: 'Sans 32', align: :center, valign: :middle,
|
font: 'Sans 32', align: :center, valign: :middle,
|
||||||
height: :deck, width: :deck
|
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',
|
save_sheet sprue: 'my_sprues/weird_sprue.yml',
|
||||||
trim: trims, trim_radius: trim_radii,
|
trim: '0.2in', trim_radius: '10pt',
|
||||||
prefix: "advanced_sprues_"
|
prefix: "advanced_sprues_"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue