Module: Sevgi::Sundries::Export::Renderer

Extended by:
Renderer
Included in:
Renderer
Defined in:
lib/sevgi/sundries/export/native.rb

Instance Method Summary collapse

Instance Method Details

#[](format) ⇒ Object



186
187
188
189
190
191
192
193
# File 'lib/sevgi/sundries/export/native.rb', line 186

def [](format)
  case format&.to_sym
  when :png
    method(:png)
  when :pdf
    method(:pdf)
  end
end

#pdf(handle:, output:, tw:, th:, dpi:) ⇒ Object



195
196
197
198
199
200
201
202
203
# File 'lib/sevgi/sundries/export/native.rb', line 195

def pdf(handle:, output:, tw:, th:, dpi:, **)
  pw, ph = tw * (72.0 / dpi), th * (72.0 / dpi)
  surface = Cairo::PDFSurface.new(output, pw, ph)
  context = Cairo::Context.new(surface)
  context.scale(pw / tw, ph / th)
  handle.render_document(context, viewport(tw, th))
  context.show_page
  surface.finish
end

#png(handle:, output:, tw:, th:) ⇒ Object



205
206
207
208
209
210
# File 'lib/sevgi/sundries/export/native.rb', line 205

def png(handle:, output:, tw:, th:, **)
  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, tw.round, th.round)
  context = Cairo::Context.new(surface)
  handle.render_document(context, viewport(tw, th))
  surface.write_to_png(output)
end