* Flipping works, now just need new argument * Finishing up * New test datadev
parent
a40c4d7dc4
commit
cb66d7c31d
|
|
@ -5,6 +5,7 @@ Squib follows [semantic versioning](http://semver.org).
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
* Added check for malformed PNG files (#250, #218)
|
* Added check for malformed PNG files (#250, #218)
|
||||||
|
* Sprues: you can now flip individual cards (#251)
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
* `trim_radius` now defaults to 0 on `save_pdf`, not 38. (#270)
|
* `trim_radius` now defaults to 0 on `save_pdf`, not 38. (#270)
|
||||||
|
|
|
||||||
|
|
@ -48,4 +48,4 @@ flip_horiztonal
|
||||||
flip_vertical
|
flip_vertical
|
||||||
default: ``false``
|
default: ``false``
|
||||||
|
|
||||||
Flip this image about its center verticall (i.e. top becomes bottom and vice versa).
|
Flip this image about its center vertical (i.e. top becomes bottom and vice versa).
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,16 @@ rotate
|
||||||
|
|
||||||
Rotate the card around its position_reference. Allows ``clockwise``, ``counterclockwise``, or ``turnaround``, or numerical angle.
|
Rotate the card around its position_reference. Allows ``clockwise``, ``counterclockwise``, or ``turnaround``, or numerical angle.
|
||||||
|
|
||||||
|
flip_vertical
|
||||||
|
Default: ``false``
|
||||||
|
|
||||||
|
Determine whether or not to flip the card vertically about the vertical line through the card's its position reference. Works most intuitively with ``position_reference: :center``
|
||||||
|
|
||||||
|
flip_horizontal
|
||||||
|
Default: ``false``
|
||||||
|
|
||||||
|
Determine whether or not to flip the card vertically about the horizontal line through the card's its position reference. Works most intuitively with ``position_reference: :center``
|
||||||
|
|
||||||
crop_line
|
crop_line
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ module Squib
|
||||||
|
|
||||||
def_delegators :cairo_cxt, :save, :set_source_color, :paint, :restore,
|
def_delegators :cairo_cxt, :save, :set_source_color, :paint, :restore,
|
||||||
:translate, :rotate, :move_to, :update_pango_layout, :width, :height,
|
:translate, :rotate, :move_to, :update_pango_layout, :width, :height,
|
||||||
:show_pango_layout, :rounded_rectangle, :set_line_width, :stroke, :fill,
|
:show_pango_layout, :rectangle, :rounded_rectangle, :set_line_width, :stroke, :fill,
|
||||||
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
|
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
|
||||||
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
|
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
|
||||||
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
|
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
|
||||||
:stroke_preserve, :target, :new_path, :fill_preserve, :close_path,
|
:stroke_preserve, :target, :new_path, :new_sub_path, :reset_clip, :fill_preserve, :close_path,
|
||||||
:set_line_join, :set_line_cap, :set_dash, :arc, :arc_negative
|
:set_line_join, :set_line_cap, :set_dash, :arc, :arc_negative
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ module Squib
|
||||||
draw_card cc, card,
|
draw_card cc, card,
|
||||||
slot['x'], slot['y'],
|
slot['x'], slot['y'],
|
||||||
slot['rotate'],
|
slot['rotate'],
|
||||||
|
slot['flip_vertical'], slot['flip_horizontal'],
|
||||||
@sheet_args.trim, @sheet_args.trim_radius
|
@sheet_args.trim, @sheet_args.trim_radius
|
||||||
|
|
||||||
bar.increment
|
bar.increment
|
||||||
|
|
@ -128,7 +129,7 @@ module Squib
|
||||||
(@deck.height - 2.0 * @sheet_args.trim) > @tmpl.card_height
|
(@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, flip_v, flip_h, trim, trim_radius)
|
||||||
# Compute the true size of the card after trimming
|
# Compute the true size of the card after trimming
|
||||||
w = @deck.width - 2.0 * trim
|
w = @deck.width - 2.0 * trim
|
||||||
h = @deck.height - 2.0 * trim
|
h = @deck.height - 2.0 * trim
|
||||||
|
|
@ -142,6 +143,7 @@ module Squib
|
||||||
mat = cc.matrix # Save the transformation matrix to revert later
|
mat = cc.matrix # Save the transformation matrix to revert later
|
||||||
cc.translate x, y
|
cc.translate x, y
|
||||||
cc.translate @deck.width / 2.0, @deck.height / 2.0
|
cc.translate @deck.width / 2.0, @deck.height / 2.0
|
||||||
|
cc.flip(flip_v, flip_h, 0, 0)
|
||||||
cc.rotate angle
|
cc.rotate angle
|
||||||
cc.translate -@deck.width / 2.0, -@deck.height / 2.0
|
cc.translate -@deck.width / 2.0, -@deck.height / 2.0
|
||||||
cc.rounded_rectangle(trim, trim, w, h, trim_radius, trim_radius) # clip
|
cc.rounded_rectangle(trim, trim, w, h, trim_radius, trim_radius) # clip
|
||||||
|
|
@ -164,7 +166,8 @@ module Squib
|
||||||
@tmpl.sheet_height * ratio
|
@tmpl.sheet_height * ratio
|
||||||
)
|
)
|
||||||
|
|
||||||
cc = Cairo::Context.new(surface)
|
cc = CairoContextWrapper.new(Cairo::Context.new(surface))
|
||||||
|
# cc = Cairo::Context.new(surface)
|
||||||
cc.scale(72.0 / @deck.dpi, 72.0 / @deck.dpi) # make it like pixels
|
cc.scale(72.0 / @deck.dpi, 72.0 / @deck.dpi) # make it like pixels
|
||||||
cc
|
cc
|
||||||
end
|
end
|
||||||
|
|
@ -185,7 +188,8 @@ module Squib
|
||||||
class SaveSpruePNG < SaveSprue
|
class SaveSpruePNG < SaveSprue
|
||||||
def init_cc
|
def init_cc
|
||||||
surface = Cairo::ImageSurface.new @tmpl.sheet_width, @tmpl.sheet_height
|
surface = Cairo::ImageSurface.new @tmpl.sheet_width, @tmpl.sheet_height
|
||||||
Cairo::Context.new(surface)
|
CairoContextWrapper.new(Cairo::Context.new(surface))
|
||||||
|
# Cairo::Context.new(surface)
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_page(cc)
|
def draw_page(cc)
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,8 @@ module Squib
|
||||||
new_card['y'] = y
|
new_card['y'] = y
|
||||||
new_card['rotate'] = parse_rotate_param(
|
new_card['rotate'] = parse_rotate_param(
|
||||||
card['rotate'] ? card['rotate'] : @template_hash['rotate'])
|
card['rotate'] ? card['rotate'] : @template_hash['rotate'])
|
||||||
|
new_card['flip_vertical'] = card['flip_vertical'] == true
|
||||||
|
new_card['flip_horizontal'] = card['flip_horizontal'] == true
|
||||||
new_card
|
new_card
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -199,5 +201,6 @@ module Squib
|
||||||
val.to_f
|
val.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ module Squib
|
||||||
:optional, Numeric,
|
:optional, Numeric,
|
||||||
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
||||||
ROTATE_REGEX
|
ROTATE_REGEX
|
||||||
]
|
],
|
||||||
|
'flip_vertical' => [ :optional, FalseClass ],
|
||||||
|
'flip_horizontal' => [ :optional, FalseClass ],
|
||||||
}]]
|
}]]
|
||||||
}.freeze
|
}.freeze
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg
|
<svg
|
||||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
xmlns:cc="http://creativecommons.org/ns#"
|
xmlns:cc="http://creativecommons.org/ns"
|
||||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns"
|
||||||
xmlns:svg="http://www.w3.org/2000/svg"
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
|
@ -1,4 +1,5 @@
|
||||||
require 'squib'
|
# 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)
|
||||||
|
|
@ -14,7 +15,7 @@ Squib::Deck.new(cards: 6, width: '2.2in', height: '2.1in') do
|
||||||
|
|
||||||
circle x: width/2, y: height/2, radius: 20 # midpoint
|
circle x: width/2, y: height/2, radius: 20 # midpoint
|
||||||
|
|
||||||
text str: (0..9).map{ |i| "Card #{i}\n\n" },
|
text str: (0..9).map{ |i| "Card! #{i}\n\n" },
|
||||||
font: 'Sans 32', align: :center, valign: :middle,
|
font: 'Sans 32', align: :center, valign: :middle,
|
||||||
height: :deck, width: :deck
|
height: :deck, width: :deck
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 109 KiB |
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
sheet_width: 5in
|
sheet_width: 5in
|
||||||
sheet_height: 4.5in
|
sheet_height: 6.5in
|
||||||
card_width: 2in
|
card_width: 2in
|
||||||
card_height: 2in
|
card_height: 2in
|
||||||
position_reference: :center
|
position_reference: :center
|
||||||
|
|
@ -12,6 +12,10 @@ cards:
|
||||||
rotate: 3.14159
|
rotate: 3.14159
|
||||||
- x: 1.1in
|
- x: 1.1in
|
||||||
y: 3.1in
|
y: 3.1in
|
||||||
|
flip_horizontal: true
|
||||||
- x: 3.1in
|
- x: 3.1in
|
||||||
y: 3.1in
|
y: 3.1in
|
||||||
rotate: 2 # 2 radians?? ew.
|
rotate: 2 # 2 radians?? ew. (this exists to annoy anyone who digs this deep)
|
||||||
|
- x: 1.1in
|
||||||
|
y: 5.1in
|
||||||
|
flip_vertical: true
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
sheet_width: 8.5in
|
||||||
|
sheet_height: 11in
|
||||||
|
card_width: 2.5in
|
||||||
|
card_height: 3.5in
|
||||||
|
cards:
|
||||||
|
- x: 0.5in
|
||||||
|
y: 1in
|
||||||
|
- x: 3.0in
|
||||||
|
y: 1in
|
||||||
|
flip_vertical: true
|
||||||
|
- x: 3.5in
|
||||||
|
y: 1in
|
||||||
|
flip_horizontal: true
|
||||||
|
|
@ -144,6 +144,15 @@ describe Squib::Sprue do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'loads a template with flipped cards' do
|
||||||
|
tmpl = Squib::Sprue.load(sprue_file('card_flip.yml'), 100)
|
||||||
|
expect(tmpl.cards.length).to eq(3)
|
||||||
|
expect(tmpl.cards.map { |card| card['flip_vertical'] })
|
||||||
|
.to eq( [false, true, false] )
|
||||||
|
expect(tmpl.cards.map { |card| card['flip_horizontal'] })
|
||||||
|
.to eq( [false, false, true] )
|
||||||
|
end
|
||||||
|
|
||||||
it 'fails when sheet_width is not defined' do
|
it 'fails when sheet_width is not defined' do
|
||||||
expect do
|
expect do
|
||||||
Squib::Sprue.load(sprue_file('fail_no_sheet_width.yml'), 100)
|
Squib::Sprue.load(sprue_file('fail_no_sheet_width.yml'), 100)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue