lib/squib/graphics/save_sprue.rb in squib-0.14.3.pre1 vs lib/squib/graphics/save_sprue.rb in squib-0.15.0
- old
+ new
@@ -28,14 +28,15 @@
card = @deck.cards[i]
slot = slots[i % per_sheet]
draw_card cc, card,
- slot['x'], slot['y'],
+ slot['x'] - @sheet_args.trim,
+ slot['y'] - @sheet_args.trim,
slot['rotate'],
+ slot['flip_vertical'], slot['flip_horizontal'],
@sheet_args.trim, @sheet_args.trim_radius
-
bar.increment
end
draw_overlay_above_cards cc
cc.target.finish
@@ -126,11 +127,11 @@
"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)
+ 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
# Normalize the angles first
@@ -140,10 +141,11 @@
# Perform the actual rotation and drawing
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
cc.clip
cc.set_source card.cairo_surface, 0, 0
@@ -156,17 +158,29 @@
# Templated sheet renderer in PDF format.
class SaveSpruePDF < SaveSprue
def init_cc
ratio = 72.0 / @deck.dpi
- surface = Cairo::PDFSurface.new(
- full_filename,
- @tmpl.sheet_width * ratio,
- @tmpl.sheet_height * ratio
- )
+ slots = @tmpl.cards
+ per_sheet = slots.size
- cc = Cairo::Context.new(surface)
+ surface = if per_sheet == 1
+ Cairo::PDFSurface.new(
+ full_filename,
+ (@tmpl.sheet_width - 2 * @sheet_args.trim) * ratio,
+ (@tmpl.sheet_height - 2 *@sheet_args.trim) * ratio
+ )
+ else
+ Cairo::PDFSurface.new(
+ full_filename,
+ @tmpl.sheet_width * ratio,
+ @tmpl.sheet_height * ratio
+ )
+ end
+
+ 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
def draw_page(cc)
@@ -183,10 +197,11 @@
# Templated sheet renderer in PNG format.
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)
cc.target.write_to_png(full_filename)
init_cc