Class: Squib::Graphics::SaveSprue

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/graphics/save_sprue.rb

Overview

Helper class to generate templated sheet.

Direct Known Subclasses

SaveSpruePDF, SaveSpruePNG

Instance Method Summary collapse

Constructor Details

#initialize(deck, tmpl, sheet_args) ⇒ SaveSprue

Returns a new instance of SaveSprue


5
6
7
8
9
10
11
12
13
# File 'lib/squib/graphics/save_sprue.rb', line 5

def initialize(deck, tmpl, sheet_args)
  @deck = deck
  @tmpl = tmpl
  @page_number = 1
  @sheet_args = sheet_args # might be Args::Sheet or Args::SaveBatch
  @overlay_lines = @tmpl.crop_lines.select do |line|
    line['overlay_on_cards']
  end
end

Instance Method Details

#render_sheet(range) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/squib/graphics/save_sprue.rb', line 15

def render_sheet(range)
  cc = init_cc
  cc.set_source_color(:white) # white backdrop TODO make option
  cc.paint
  slots = @tmpl.cards
  per_sheet = slots.size
  check_oversized_card

  draw_overlay_below_cards cc if range.size

  track_progress(range) do |bar|
    range.each do |i|
      cc = next_page_if_needed(cc, i, per_sheet)

      card = @deck.cards[i]
      slot = slots[i % per_sheet]

      draw_card cc, card,
                slot['x'], slot['y'],
                slot['rotate'],
                @sheet_args.trim, @sheet_args.trim_radius

      bar.increment
    end

    draw_overlay_above_cards cc
    cc.target.finish
  end
end