Module: Sevgi::Sundries::Export::Renderer Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Low-level format renderers used by call.
Instance Method Summary collapse
-
#[](format) ⇒ Method?
private
Returns a renderer method for a format.
-
#pdf(handle:, output:, tw:, th:, dpi:) ⇒ void
private
Renders SVG data to a PDF surface.
-
#png(handle:, output:, tw:, th:) ⇒ void
private
Renders SVG data to a PNG image.
Instance Method Details
#[](format) ⇒ Method?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a renderer method for a format.
247 248 249 250 251 252 253 254 |
# File 'lib/sevgi/sundries/export/native.rb', line 247 def [](format) case format&.to_sym when :png method(:png) when :pdf method(:pdf) end end |
#pdf(handle:, output:, tw:, th:, dpi:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Renders SVG data to a PDF surface.
265 266 267 268 269 270 271 272 273 |
# File 'lib/sevgi/sundries/export/native.rb', line 265 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, (tw, th)) context.show_page surface.finish end |
#png(handle:, output:, tw:, th:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Renders SVG data to a PNG image.
283 284 285 286 287 288 |
# File 'lib/sevgi/sundries/export/native.rb', line 283 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, (tw, th)) surface.write_to_png(output) end |