Module: Sumi::Graphics::Mixtures::Export

Defined in:
graphics/lib/sumi/graphics/mixtures/export.rb

Overview

DSL helpers for native SVG export formats. Export CSS is a late adjustment after document checks. Its supported XML endings and cascade limitations are documented in Sundries::Export. The source callback receives SVG after CSS insertion.

Instance Method Summary collapse

Instance Method Details

#PDF(path = nil, **kwargs) {|svg| ... } ⇒ String

Exports the document as PDF. Relative paths are expanded, missing parent directories are created after export validation, and an existing file is replaced. An existing directory target uses the caller-derived default PDF name.

Parameters:

  • path (String, #to_path, nil) (defaults to: nil) —

    output path or existing directory

  • kwargs (Hash) —

    export options

Options Hash (**kwargs):

  • :default (String, #to_path, nil) —

    caller-derived output name used when path is nil or a directory

  • :width (Numeric, nil) —

    finite positive target width in CSS pixels

  • :height (Numeric, nil) —

    finite positive target height in CSS pixels

  • :dpi (Numeric) — default: 96.0 —

    finite positive CSS pixel density

  • :css (String, nil) —

    CSS inserted before rendering

  • :declaration (Hash, nil) — default: document Imprint —

    producer declaration; nil omits the document declaration

  • :preview (String, nil) —

    separate PNG thumbnail bytes; selects Toji even without a declaration

  • :fallback (Boolean) — default: true —

    warn and use ordinary PDF after preparation failure

Yields:

  • (svg) —

    transforms SVG source before rendering

Yield Parameters:

  • svg (String) —

    rendered SVG source

Yield Returns:

  • (String) —

    transformed SVG source

Returns:

  • (String) —

    expanded output path

Raises:



96
97
98
# File 'graphics/lib/sumi/graphics/mixtures/export.rb', line 96

def PDF(path = nil, **kwargs, &block)
  Runner.(self, path, caller_path: caller_locations(1, 1).first&.path, **kwargs, format: :pdf, &block)
end

#PNG(path = nil, **kwargs) {|svg| ... } ⇒ String

Exports the document as PNG. Relative paths are expanded, missing parent directories are created after export validation, and an existing file is replaced. An existing directory target uses the caller-derived default PNG name.

Parameters:

  • path (String, #to_path, nil) (defaults to: nil) —

    output path or existing directory

  • kwargs (Hash) —

    export options

Options Hash (**kwargs):

  • :default (String, #to_path, nil) —

    caller-derived output name used when path is nil or a directory

  • :width (Numeric, nil) —

    finite positive target width in output pixels

  • :height (Numeric, nil) —

    finite positive target height in output pixels

  • :dpi (Numeric) — default: 96.0 —

    finite positive CSS pixel density

  • :css (String, nil) —

    CSS inserted before rendering

Yields:

  • (svg) —

    transforms SVG source before rendering

Yield Parameters:

  • svg (String) —

    rendered SVG source

Yield Returns:

  • (String) —

    transformed SVG source

Returns:

  • (String) —

    expanded output path

Raises:



121
122
123
# File 'graphics/lib/sumi/graphics/mixtures/export.rb', line 121

def PNG(path = nil, **kwargs, &block)
  Runner.(self, path, caller_path: caller_locations(1, 1).first&.path, **kwargs, format: :png, &block)
end