diff --git a/CHANGELOG.md b/CHANGELOG.md index 76286f0..ee26db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Squib follows [semantic versioning](http://semver.org). Features: * Added check for malformed PNG files (#250, #218) +* Sprues: you can now flip individual cards (#251) Bugs * `trim_radius` now defaults to 0 on `save_pdf`, not 38. (#270) diff --git a/docs/args/transform.rst b/docs/args/transform.rst index 00d7649..fe5c761 100644 --- a/docs/args/transform.rst +++ b/docs/args/transform.rst @@ -48,4 +48,4 @@ flip_horiztonal flip_vertical 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). diff --git a/docs/sprues.rst b/docs/sprues.rst index f54e585..e3053ae 100644 --- a/docs/sprues.rst +++ b/docs/sprues.rst @@ -156,6 +156,16 @@ rotate 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 ^^^^^^^^^ diff --git a/lib/squib/graphics/cairo_context_wrapper.rb b/lib/squib/graphics/cairo_context_wrapper.rb index df0f70b..5ad6aa0 100644 --- a/lib/squib/graphics/cairo_context_wrapper.rb +++ b/lib/squib/graphics/cairo_context_wrapper.rb @@ -20,11 +20,11 @@ module Squib def_delegators :cairo_cxt, :save, :set_source_color, :paint, :restore, :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, :operator=, :show_page, :clip, :transform, :mask, :create_pango_layout, :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 # :nodoc: diff --git a/lib/squib/graphics/save_sprue.rb b/lib/squib/graphics/save_sprue.rb index b946569..8433246 100644 --- a/lib/squib/graphics/save_sprue.rb +++ b/lib/squib/graphics/save_sprue.rb @@ -32,6 +32,7 @@ module Squib draw_card cc, card, slot['x'], slot['y'], slot['rotate'], + slot['flip_vertical'], slot['flip_horizontal'], @sheet_args.trim, @sheet_args.trim_radius bar.increment @@ -128,7 +129,7 @@ module Squib (@deck.height - 2.0 * @sheet_args.trim) > @tmpl.card_height 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 w = @deck.width - 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 cc.translate x, y cc.translate @deck.width / 2.0, @deck.height / 2.0 + cc.flip(flip_v, flip_h, 0, 0) cc.rotate angle cc.translate -@deck.width / 2.0, -@deck.height / 2.0 cc.rounded_rectangle(trim, trim, w, h, trim_radius, trim_radius) # clip @@ -164,7 +166,8 @@ module Squib @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 end @@ -185,7 +188,8 @@ module Squib class SaveSpruePNG < SaveSprue def init_cc 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 def draw_page(cc) diff --git a/lib/squib/sprues/sprue.rb b/lib/squib/sprues/sprue.rb index 877f1ff..0dc80a6 100644 --- a/lib/squib/sprues/sprue.rb +++ b/lib/squib/sprues/sprue.rb @@ -175,6 +175,8 @@ module Squib new_card['y'] = y new_card['rotate'] = parse_rotate_param( 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 end @@ -199,5 +201,6 @@ module Squib val.to_f end end + end end diff --git a/lib/squib/sprues/sprue_schema.rb b/lib/squib/sprues/sprue_schema.rb index 16b5460..1c011fd 100644 --- a/lib/squib/sprues/sprue_schema.rb +++ b/lib/squib/sprues/sprue_schema.rb @@ -41,8 +41,10 @@ module Squib :optional, Numeric, ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround), ROTATE_REGEX - ] - }]] + ], + 'flip_vertical' => [ :optional, FalseClass ], + 'flip_horizontal' => [ :optional, FalseClass ], + }]] }.freeze end end diff --git a/samples/spanner.svg b/samples/spanner.svg index 1f3a747..5cf52f6 100644 --- a/samples/spanner.svg +++ b/samples/spanner.svg @@ -1,8 +1,8 @@