Class: Squib::Graphics::SaveSpruePDF

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

Overview

Templated sheet renderer in PDF format.

Instance Method Summary collapse

Methods inherited from SaveSprue

#initialize, #render_sheet

Constructor Details

This class inherits a constructor from Squib::Graphics::SaveSprue

Instance Method Details

#draw_final_page(cc) ⇒ Object



193
194
195
196
# File 'lib/squib/graphics/save_sprue.rb', line 193

def draw_final_page(cc)
  # PDF doesn't need to create a last page. See bug #320
  cc.target.finish
end

#draw_page(cc) ⇒ Object



186
187
188
189
190
191
# File 'lib/squib/graphics/save_sprue.rb', line 186

def draw_page(cc)
  cc.show_page
  cc.set_source_color(:white) # white backdrop TODO make option
  cc.paint
  cc
end

#full_filenameObject



198
199
200
# File 'lib/squib/graphics/save_sprue.rb', line 198

def full_filename
  @sheet_args.full_filename
end

#init_ccObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/squib/graphics/save_sprue.rb', line 160

def init_cc
  ratio = 72.0 / @deck.dpi

  slots = @tmpl.cards
  per_sheet = slots.size

  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