partway through the conversion
parent
70b3c0b136
commit
77a694f797
|
|
@ -40,7 +40,7 @@ crop_height
|
||||||
|
|
||||||
Height of the cropped image. Supports :doc:`/units`.
|
Height of the cropped image. Supports :doc:`/units`.
|
||||||
|
|
||||||
flip_horiztonal
|
flip_horizontal
|
||||||
default: ``false``
|
default: ``false``
|
||||||
|
|
||||||
Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,6 @@ file
|
||||||
|
|
||||||
.. include:: /args/xy.rst
|
.. include:: /args/xy.rst
|
||||||
|
|
||||||
range
|
|
||||||
default: ``all``
|
|
||||||
|
|
||||||
the range of cards over which this will be rendered. See :doc:`/arrays`
|
|
||||||
|
|
||||||
data
|
data
|
||||||
default: ``nil``
|
default: ``nil``
|
||||||
|
|
||||||
|
|
@ -106,7 +101,7 @@ crop_height
|
||||||
|
|
||||||
ive): Height of the cropped image. Supports :doc:`/units`
|
ive): Height of the cropped image. Supports :doc:`/units`
|
||||||
|
|
||||||
flip_horiztonal
|
flip_horizontal
|
||||||
default: ``false``
|
default: ``false``
|
||||||
|
|
||||||
Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
require_relative '../args/card_range'
|
|
||||||
require_relative '../args/paint'
|
|
||||||
require_relative '../args/scale_box'
|
|
||||||
require_relative '../args/transform'
|
|
||||||
require_relative '../args/input_file'
|
|
||||||
require_relative '../args/svg_special'
|
|
||||||
|
|
||||||
module Squib
|
|
||||||
class Deck
|
|
||||||
|
|
||||||
# DSL method. See http://squib.readthedocs.io
|
|
||||||
def png(opts = {})
|
|
||||||
Dir.chdir(img_dir) do
|
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
|
||||||
paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
|
|
||||||
box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
trans = Args::Transform.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
@progress_bar.start('Loading PNG(s)', range.size) do |bar|
|
|
||||||
range.each do |i|
|
|
||||||
@cards[i].png(ifile[i].file, box[i], paint[i], trans[i])
|
|
||||||
bar.increment
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# DSL method. See http://squib.readthedocs.io
|
|
||||||
def svg(opts = {})
|
|
||||||
Dir.chdir(img_dir) do
|
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
|
||||||
paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
|
|
||||||
box = Args::ScaleBox.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
trans = Args::Transform.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
svg_args = Args::SvgSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
@progress_bar.start('Loading SVG(s)', range.size) do |bar|
|
|
||||||
range.each do |i|
|
|
||||||
if svg_args.render?(i)
|
|
||||||
@cards[i].svg(ifile[i].file, svg_args[i], box[i], paint[i], trans[i])
|
|
||||||
end
|
|
||||||
bar.increment
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -21,7 +21,7 @@ module Squib
|
||||||
# DSL method. See http://squib.readthedocs.io
|
# DSL method. See http://squib.readthedocs.io
|
||||||
def save_pdf(opts = {})
|
def save_pdf(opts = {})
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||||
sheet = Args::Sheet.new(custom_colors, { file: 'output.pdf' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
sheet = Args::Sheet.new({ file: 'output.pdf' }).extract!(opts, self)
|
||||||
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
|
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
|
||||||
|
|
||||||
if sprue_file.sprue.nil?
|
if sprue_file.sprue.nil?
|
||||||
|
|
@ -50,7 +50,7 @@ module Squib
|
||||||
def save_sheet(opts = {})
|
def save_sheet(opts = {})
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||||
batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||||
sheet = Args::Sheet.new(custom_colors, { margin: 0 }, size).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
sheet = Args::Sheet.new({ margin: 0 }).extract! opts, self
|
||||||
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
|
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
|
||||||
|
|
||||||
if sprue_file.sprue.nil?
|
if sprue_file.sprue.nil?
|
||||||
|
|
@ -63,19 +63,11 @@ module Squib
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DSL method. See http://squib.readthedocs.io
|
|
||||||
def showcase(opts = {})
|
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
|
||||||
showcase = Args::ShowcaseSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
sheet = Args::Sheet.new(custom_colors, { file: 'showcase.png' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
|
||||||
render_showcase(range, sheet, showcase)
|
|
||||||
end
|
|
||||||
|
|
||||||
# DSL method. See http://squib.readthedocs.io
|
# DSL method. See http://squib.readthedocs.io
|
||||||
def hand(opts = {})
|
def hand(opts = {})
|
||||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||||
hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||||
sheet = Args::Sheet.new(custom_colors, { file: 'hand.png', trim_radius: 0 }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
sheet = Args::Sheet.new({ file: 'hand.png', trim_radius: 0 }).extract!(opts, self)
|
||||||
render_hand(range, sheet, hand)
|
render_hand(range, sheet, hand)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ module Squib::Args::ArgLoader
|
||||||
|
|
||||||
# wrapper for compatibility
|
# wrapper for compatibility
|
||||||
def extract!(args, deck)
|
def extract!(args, deck)
|
||||||
|
@deck = deck
|
||||||
load!(args, expand_by: deck.size, layout: deck.layout, dpi: deck.dpi)
|
load!(args, expand_by: deck.size, layout: deck.layout, dpi: deck.dpi)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_input_file(opts, deck, dsl_method_default = {})
|
||||||
module Args
|
InputFile.new(dsl_method_default).extract!(opts, deck)
|
||||||
|
end
|
||||||
|
|
||||||
class InputFile
|
class InputFile
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
@ -30,8 +31,5 @@ module Squib
|
||||||
raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg)
|
raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg)
|
||||||
File.expand_path(arg)
|
File.expand_path(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@ require 'cairo'
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
require_relative 'color_validator'
|
require_relative 'color_validator'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_paint(opts, deck)
|
||||||
module Args
|
Paint.new(deck.custom_colors).extract!(opts, deck)
|
||||||
|
end
|
||||||
class Paint
|
class Paint
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
include ColorValidator
|
include ColorValidator
|
||||||
|
|
||||||
|
def initialize(custom_colors)
|
||||||
|
@custom_colors = custom_colors
|
||||||
|
end
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
{ alpha: 1.0,
|
{ alpha: 1.0,
|
||||||
blend: :none,
|
blend: :none,
|
||||||
|
|
@ -16,7 +21,6 @@ module Squib
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.expanding_parameters
|
def self.expanding_parameters
|
||||||
parameters.keys # all of them are expandable
|
parameters.keys # all of them are expandable
|
||||||
end
|
end
|
||||||
|
|
@ -25,10 +29,6 @@ module Squib
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(custom_colors)
|
|
||||||
@custom_colors = custom_colors
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_alpha(arg, _i)
|
def validate_alpha(arg, _i)
|
||||||
raise 'alpha must respond to to_f' unless arg.respond_to? :to_f
|
raise 'alpha must respond to to_f' unless arg.respond_to? :to_f
|
||||||
arg.to_f
|
arg.to_f
|
||||||
|
|
@ -38,7 +38,5 @@ module Squib
|
||||||
colorify(arg, @custom_colors)
|
colorify(arg, @custom_colors)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_scale_box(opts, deck)
|
||||||
module Args
|
ScaleBox.new.extract!(opts, deck)
|
||||||
|
end
|
||||||
|
|
||||||
class ScaleBox
|
class ScaleBox
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
||||||
def initialize(deck)
|
|
||||||
@deck = deck
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
{ x: 0, y: 0,
|
{
|
||||||
|
x: 0, y: 0,
|
||||||
width: :native, height: :native
|
width: :native, height: :native
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -50,4 +48,3 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,18 @@ require_relative 'arg_loader'
|
||||||
require_relative 'color_validator'
|
require_relative 'color_validator'
|
||||||
require_relative 'dir_validator'
|
require_relative 'dir_validator'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_sheet(opts, deck, dsl_method_defaults = {})
|
||||||
module Args
|
Sheet.new(dsl_method_defaults).extract! opts, deck
|
||||||
|
end
|
||||||
|
|
||||||
class Sheet
|
class Sheet
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
include ColorValidator
|
include ColorValidator
|
||||||
include DirValidator
|
include DirValidator
|
||||||
|
|
||||||
def initialize(custom_colors = {}, dsl_method_defaults = {}, deck_size = 1, dpi = 300)
|
def initialize(dsl_method_defaults = {})
|
||||||
@custom_colors = custom_colors
|
|
||||||
@dsl_method_defaults = dsl_method_defaults
|
@dsl_method_defaults = dsl_method_defaults
|
||||||
@deck_size = deck_size
|
|
||||||
@dpi = dpi
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
|
|
@ -60,7 +58,7 @@ module Squib
|
||||||
|
|
||||||
def validate_crop_stroke_dash(arg)
|
def validate_crop_stroke_dash(arg)
|
||||||
arg.to_s.split.collect do |x|
|
arg.to_s.split.collect do |x|
|
||||||
UnitConversion.parse(x, @dpi).to_f
|
UnitConversion.parse(x, @deck.dpi).to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -69,7 +67,7 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_fill_color(arg)
|
def validate_fill_color(arg)
|
||||||
colorify(arg, @custom_colors)
|
colorify(arg, @deck.custom_colors)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_dir(arg)
|
def validate_dir(arg)
|
||||||
|
|
@ -84,7 +82,7 @@ module Squib
|
||||||
def validate_rows(arg)
|
def validate_rows(arg)
|
||||||
raise 'columns must be an integer' unless columns.respond_to? :to_i
|
raise 'columns must be an integer' unless columns.respond_to? :to_i
|
||||||
count = if range == :all
|
count = if range == :all
|
||||||
@deck_size
|
@deck.size
|
||||||
else
|
else
|
||||||
count = range.to_a.length
|
count = range.to_a.length
|
||||||
end
|
end
|
||||||
|
|
@ -169,4 +167,3 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ require 'cairo'
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
require_relative 'dir_validator'
|
require_relative 'dir_validator'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_showcase_special(opts, deck)
|
||||||
module Args
|
ShowcaseSpecial.new.extract! opts, deck
|
||||||
|
end
|
||||||
|
|
||||||
class ShowcaseSpecial
|
class ShowcaseSpecial
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
@ -38,4 +39,3 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_svg_special(opts, deck)
|
||||||
module Args
|
SvgSpecial.new.extract! opts, deck
|
||||||
|
end
|
||||||
|
|
||||||
class SvgSpecial
|
class SvgSpecial
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
@ -34,4 +35,3 @@ module Squib
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
require_relative 'arg_loader'
|
require_relative 'arg_loader'
|
||||||
|
|
||||||
module Squib
|
module Squib::Args
|
||||||
# @api private
|
module_function def extract_transform(opts, deck)
|
||||||
module Args
|
Transform.new.extract!(opts, deck)
|
||||||
|
end
|
||||||
|
|
||||||
class Transform
|
class Transform
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
||||||
def initialize(deck = nil)
|
|
||||||
@deck = deck
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
{ angle: 0,
|
{ angle: 0,
|
||||||
crop_x: 0,
|
crop_x: 0,
|
||||||
|
|
@ -54,8 +51,5 @@ module Squib
|
||||||
return crop_corner_radius[i] unless crop_corner_radius[i].nil?
|
return crop_corner_radius[i] unless crop_corner_radius[i].nil?
|
||||||
arg
|
arg
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ module Squib
|
||||||
require_relative 'dsl/background'
|
require_relative 'dsl/background'
|
||||||
require_relative 'api/data'
|
require_relative 'api/data'
|
||||||
require_relative 'api/groups'
|
require_relative 'api/groups'
|
||||||
require_relative 'api/image'
|
|
||||||
require_relative 'api/save'
|
require_relative 'api/save'
|
||||||
require_relative 'api/settings'
|
require_relative 'api/settings'
|
||||||
require_relative 'api/shapes'
|
require_relative 'api/shapes'
|
||||||
|
|
@ -117,6 +116,9 @@ module Squib
|
||||||
###################
|
###################
|
||||||
require_relative 'dsl/background'
|
require_relative 'dsl/background'
|
||||||
require_relative 'dsl/grid'
|
require_relative 'dsl/grid'
|
||||||
|
require_relative 'dsl/png'
|
||||||
|
require_relative 'dsl/showcase'
|
||||||
|
require_relative 'dsl/svg'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
require_relative '../errors_warnings/warn_unexpected_params'
|
||||||
|
require_relative '../args/card_range'
|
||||||
|
require_relative '../args/paint'
|
||||||
|
require_relative '../args/scale_box'
|
||||||
|
require_relative '../args/transform'
|
||||||
|
require_relative '../args/input_file'
|
||||||
|
|
||||||
|
module Squib
|
||||||
|
class Deck
|
||||||
|
def png(opts = {})
|
||||||
|
DSL::PNG.new(self, __callee__).run(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module DSL
|
||||||
|
class PNG
|
||||||
|
include WarnUnexpectedParams
|
||||||
|
attr_reader :dsl_method, :deck
|
||||||
|
|
||||||
|
def initialize(deck, dsl_method)
|
||||||
|
@deck = deck
|
||||||
|
@dsl_method = dsl_method
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.accepted_params
|
||||||
|
%i(
|
||||||
|
file
|
||||||
|
x y width height
|
||||||
|
alpha blend mask angle
|
||||||
|
crop_x crop_y crop_width crop_height
|
||||||
|
crop_corner_radius crop_corner_x_radius crop_corner_y_radius
|
||||||
|
flip_horizontal flip_vertical
|
||||||
|
range layout
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(opts)
|
||||||
|
warn_if_unexpected opts
|
||||||
|
Dir.chdir(deck.img_dir) do
|
||||||
|
range = Args.extract_range opts, deck
|
||||||
|
paint = Args.extract_paint opts, deck
|
||||||
|
box = Args.extract_scale_box opts, deck
|
||||||
|
trans = Args.extract_transform opts, deck
|
||||||
|
ifile = Args.extract_input_file opts, deck
|
||||||
|
deck.progress_bar.start('Loading PNG(s)', range.size) do |bar|
|
||||||
|
range.each do |i|
|
||||||
|
deck.cards[i].png(ifile[i].file, box[i], paint[i], trans[i])
|
||||||
|
bar.increment
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
require_relative '../errors_warnings/warn_unexpected_params'
|
||||||
|
require_relative '../args/card_range'
|
||||||
|
require_relative '../args/showcase_special'
|
||||||
|
require_relative '../args/sheet'
|
||||||
|
|
||||||
|
module Squib
|
||||||
|
class Deck
|
||||||
|
def showcase(opts = {})
|
||||||
|
DSL::Showcase.new(self, __callee__).run(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module DSL
|
||||||
|
class Showcase
|
||||||
|
include WarnUnexpectedParams
|
||||||
|
attr_reader :dsl_method, :deck
|
||||||
|
|
||||||
|
def initialize(deck, dsl_method)
|
||||||
|
@deck = deck
|
||||||
|
@dsl_method = dsl_method
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.accepted_params
|
||||||
|
%i(
|
||||||
|
file dir
|
||||||
|
trim trim_radius
|
||||||
|
scale offset fill_color
|
||||||
|
reflect_offset reflect_strength reflect_percent
|
||||||
|
face margin
|
||||||
|
range
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(opts)
|
||||||
|
warn_if_unexpected opts
|
||||||
|
range = Args.extract_range opts, deck
|
||||||
|
showcase = Args.extract_showcase_special opts, deck
|
||||||
|
sheet = Args.extract_sheet opts, deck, { file: 'showcase.png' }
|
||||||
|
deck.render_showcase(range, sheet, showcase)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
require_relative '../errors_warnings/warn_unexpected_params'
|
||||||
|
require_relative '../args/card_range'
|
||||||
|
require_relative '../args/paint'
|
||||||
|
require_relative '../args/scale_box'
|
||||||
|
require_relative '../args/transform'
|
||||||
|
require_relative '../args/input_file'
|
||||||
|
require_relative '../args/svg_special'
|
||||||
|
|
||||||
|
module Squib
|
||||||
|
class Deck
|
||||||
|
def svg(opts = {})
|
||||||
|
DSL::SVG.new(self, __callee__).run(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module DSL
|
||||||
|
class SVG
|
||||||
|
include WarnUnexpectedParams
|
||||||
|
attr_reader :dsl_method, :deck
|
||||||
|
|
||||||
|
def initialize(deck, dsl_method)
|
||||||
|
@deck = deck
|
||||||
|
@dsl_method = dsl_method
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.accepted_params
|
||||||
|
%i(
|
||||||
|
file
|
||||||
|
x y width height
|
||||||
|
blend mask
|
||||||
|
crop_x crop_y crop_width crop_height
|
||||||
|
crop_corner_radius crop_corner_x_radius crop_corner_y_radius
|
||||||
|
flip_horizontal flip_vertical angle
|
||||||
|
id force_id data
|
||||||
|
range layout
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(opts)
|
||||||
|
warn_if_unexpected opts
|
||||||
|
Dir.chdir(deck.img_dir) do
|
||||||
|
range = Args.extract_range opts, deck
|
||||||
|
paint = Args.extract_paint opts, deck
|
||||||
|
box = Args.extract_scale_box opts, deck
|
||||||
|
trans = Args.extract_transform opts, deck
|
||||||
|
ifile = Args.extract_input_file opts, deck
|
||||||
|
svg_args = Args.extract_svg_special opts, deck
|
||||||
|
deck.progress_bar.start('Loading PNG(s)', range.size) do |bar|
|
||||||
|
range.each do |i|
|
||||||
|
if svg_args.render?(i)
|
||||||
|
deck.cards[i].svg(ifile[i].file, svg_args[i], box[i], paint[i],
|
||||||
|
trans[i])
|
||||||
|
end
|
||||||
|
bar.increment
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -107,18 +107,19 @@ describe Squib::Args::Box do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'validation' do
|
context 'validation' do
|
||||||
|
let(:deck) { OpenStruct.new(width: 123, height: 456, size: 1) }
|
||||||
|
|
||||||
it 'replaces with deck width and height' do
|
it 'replaces with deck width and height' do
|
||||||
args = { width: :deck, height: :deck }
|
args = { width: :deck, height: :deck }
|
||||||
deck = OpenStruct.new(width: 123, height: 456)
|
box = Squib::Args::Box.new
|
||||||
box = Squib::Args::Box.new(deck)
|
box.extract! args, deck
|
||||||
box.load!(args, expand_by: 1)
|
|
||||||
expect(box).to have_attributes(width: [123], height: [456])
|
expect(box).to have_attributes(width: [123], height: [456])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has radius override x_radius and y_radius' do
|
it 'has radius override x_radius and y_radius' do
|
||||||
args = { x_radius: 1, y_radius: 2, radius: 3 }
|
args = { x_radius: 1, y_radius: 2, radius: 3 }
|
||||||
box.load!(args, expand_by: 2)
|
box.extract! args, deck
|
||||||
expect(box).to have_attributes(x_radius: [3, 3], y_radius: [3, 3])
|
expect(box).to have_attributes(x_radius: [3], y_radius: [3])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
||||||
require 'squib/args/scale_box'
|
require 'squib/args/scale_box'
|
||||||
|
|
||||||
describe Squib::Args::ScaleBox do
|
describe Squib::Args::ScaleBox do
|
||||||
subject(:box) { Squib::Args::ScaleBox.new({}) }
|
subject(:box) { Squib::Args::ScaleBox.new }
|
||||||
|
|
||||||
context 'unit conversion' do
|
context 'unit conversion' do
|
||||||
it 'converts units on all args' do
|
it 'converts units on all args' do
|
||||||
|
|
|
||||||
|
|
@ -2,58 +2,60 @@ require 'spec_helper'
|
||||||
require 'squib/args/sheet'
|
require 'squib/args/sheet'
|
||||||
|
|
||||||
describe Squib::Args::Sheet do
|
describe Squib::Args::Sheet do
|
||||||
|
let(:deck) { OpenStruct.new(size: 4, custom_colors: {}) }
|
||||||
|
|
||||||
context 'dsl overrides' do
|
context 'dsl overrides' do
|
||||||
subject(:sheet) { Squib::Args::Sheet.new({}, { file: 'foo' }) }
|
subject(:sheet) { Squib::Args::Sheet.new({ file: 'foo' }) }
|
||||||
|
|
||||||
it 'works when specified' do
|
it 'works when specified' do
|
||||||
sheet.load!({}) # go right to defaults
|
opts = {}
|
||||||
|
sheet.extract! opts, deck # go right to defaults
|
||||||
expect(sheet.file).to eq('foo') # dsl method default override
|
expect(sheet.file).to eq('foo') # dsl method default override
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'rows and colums' do
|
context 'rows and colums' do
|
||||||
subject(:sheet) { Squib::Args::Sheet.new({}, {}, 4) }
|
subject(:sheet) { Squib::Args::Sheet.new }
|
||||||
|
|
||||||
it 'does nothing on a perfect fit' do
|
it 'does nothing on a perfect fit' do
|
||||||
opts = { columns: 2, rows: 2 }
|
opts = { columns: 2, rows: 2 }
|
||||||
sheet.load! opts
|
sheet.extract! opts, deck
|
||||||
expect(sheet).to have_attributes(columns: 2, rows: 2)
|
expect(sheet).to have_attributes(columns: 2, rows: 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'keeps both if specified' do
|
it 'keeps both if specified' do
|
||||||
opts = { columns: 1, rows: 1 }
|
opts = { columns: 1, rows: 1 }
|
||||||
sheet.load! opts
|
sheet.extract! opts, deck
|
||||||
expect(sheet).to have_attributes(columns: 1, rows: 1)
|
expect(sheet).to have_attributes(columns: 1, rows: 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'computes properly on non-integer' do
|
it 'computes properly on non-integer' do
|
||||||
opts = { columns: 1, rows: :infinite }
|
opts = { columns: 1, rows: :infinite }
|
||||||
sheet.load! opts
|
sheet.extract! opts, deck
|
||||||
expect(sheet).to have_attributes(columns: 1, rows: 4)
|
expect(sheet).to have_attributes(columns: 1, rows: 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'computes properly on unspecified rows' do
|
it 'computes properly on unspecified rows' do
|
||||||
opts = { columns: 1 }
|
opts = { columns: 1 }
|
||||||
sheet.load! opts
|
sheet.extract! opts, deck
|
||||||
expect(sheet).to have_attributes(columns: 1, rows: 4)
|
expect(sheet).to have_attributes(columns: 1, rows: 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'computes properly on unspecified, too-big column' do
|
it 'computes properly on unspecified, too-big column' do
|
||||||
opts = {}
|
opts = {}
|
||||||
sheet.load! opts
|
sheet.extract! opts, deck
|
||||||
expect(sheet).to have_attributes(columns: 5, rows: 1)
|
expect(sheet).to have_attributes(columns: 5, rows: 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails on a non-integer column' do
|
it 'fails on a non-integer column' do
|
||||||
opts = { columns: :infinite }
|
opts = { columns: :infinite }
|
||||||
expect { sheet.load!(opts) }.to raise_error('columns must be an integer')
|
expect { sheet.extract!(opts, deck) }.to raise_error('columns must be an integer')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'crop marks' do
|
context 'crop marks' do
|
||||||
subject(:sheet) { Squib::Args::Sheet.new({}, {}, 4) }
|
subject(:sheet) { Squib::Args::Sheet.new }
|
||||||
|
|
||||||
it 'computes crop marks properly' do
|
it 'computes crop marks properly' do
|
||||||
opts = {
|
opts = {
|
||||||
|
|
@ -65,7 +67,7 @@ describe Squib::Args::Sheet do
|
||||||
crop_margin_right: 40,
|
crop_margin_right: 40,
|
||||||
crop_margin_bottom: 50,
|
crop_margin_bottom: 50,
|
||||||
}
|
}
|
||||||
expect(sheet.load!(opts).crop_coords(3,4, 300, 400)).to eq(
|
expect(sheet.extract!(opts, deck).crop_coords(3,4, 300, 400)).to eq(
|
||||||
[ {:x1=>43, :y1=>0, :x2=>43, :y2=>74},
|
[ {:x1=>43, :y1=>0, :x2=>43, :y2=>74},
|
||||||
{:x1=>253, :y1=>0, :x2=>253, :y2=>74},
|
{:x1=>253, :y1=>0, :x2=>253, :y2=>74},
|
||||||
{:x1=>43, :y1=>1100, :x2=>43, :y2=>1026},
|
{:x1=>43, :y1=>1100, :x2=>43, :y2=>1026},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'squib/args/box'
|
require 'squib/args/box'
|
||||||
|
require 'squib/args/svg_special'
|
||||||
|
|
||||||
describe Squib::Args::SvgSpecial do
|
describe Squib::Args::SvgSpecial do
|
||||||
subject(:svgargs) { Squib::Args::SvgSpecial.new }
|
subject(:svgargs) { Squib::Args::SvgSpecial.new }
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,16 @@ describe Squib::Args::Box do
|
||||||
context 'validation' do
|
context 'validation' do
|
||||||
it 'replaces with deck width and height' do
|
it 'replaces with deck width and height' do
|
||||||
args = { crop_width: :deck, crop_height: :deck }
|
args = { crop_width: :deck, crop_height: :deck }
|
||||||
deck = OpenStruct.new(width: 123, height: 456)
|
deck = OpenStruct.new(width: 123, height: 456, size: 1)
|
||||||
trans = Squib::Args::Transform.new(deck)
|
trans = Squib::Args::Transform.new
|
||||||
trans.load!(args, expand_by: 1)
|
trans.extract! args, deck
|
||||||
expect(trans).to have_attributes(crop_width: [123], crop_height: [456])
|
expect(trans).to have_attributes(crop_width: [123], crop_height: [456])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has radius override x_radius and y_radius' do
|
it 'has radius override x_radius and y_radius' do
|
||||||
args = { crop_corner_x_radius: 1, crop_corner_y_radius: 2, crop_corner_radius: 3 }
|
args = { crop_corner_x_radius: 1, crop_corner_y_radius: 2, crop_corner_radius: 3 }
|
||||||
trans.load!(args, expand_by: 2)
|
deck = OpenStruct.new(width: 123, height: 456, size: 2)
|
||||||
|
trans.extract! args, deck
|
||||||
expect(trans).to have_attributes(crop_corner_x_radius: [3, 3], crop_corner_y_radius: [3, 3])
|
expect(trans).to have_attributes(crop_corner_x_radius: [3, 3], crop_corner_y_radius: [3, 3])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ describe Squib::DSL do
|
||||||
|
|
||||||
Squib::DSL.constants.each do |m|
|
Squib::DSL.constants.each do |m|
|
||||||
it "accepted params for #{m} are in the docs" do
|
it "accepted params for #{m} are in the docs" do
|
||||||
accepted_params = Squib::DSL.const_get(m).accepted_params
|
accepted_params = Squib::DSL.const_get(m).accepted_params.sort
|
||||||
expect(accepted_params).to eq(documented_options(m))
|
documented_opts = documented_options(m).sort
|
||||||
|
expect(accepted_params).to eq(documented_opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue