Module: Sumi::Graphics::Mixtures::Inkscape

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

Overview

Inkscape-specific SVG DSL helpers.

Instance Method Summary collapse

Instance Method Details

#Group(mod, *args, attributes: {}, **kwargs) { ... } ⇒ Sumi::Graphics::Element

Renders a callable module inside a group. Named modules default the group id to their final constant name. Anonymous modules omit the id unless supplied.

Examples:

Supply a stable id for an anonymous callable

drawing = Module.new do
  extend Sumi::Graphics::Module
  def call = circle r: 5
end
Sumi::Graphics.SVG(:inkscape) { Group drawing, attributes: {id: "drawing"} }

Parameters:

  • mod (Module) —

    module extended with Sumi::Graphics::Module

  • args (Array<Object>) —

    callable arguments

  • attributes (Hash) (defaults to: {}) —

    group attributes. String and Symbol names are normalized and must not collide

  • kwargs (Hash) —

    callable keyword arguments

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object) —

    callable customization result

Returns:

Raises:

  • (Sumi::ArgumentError) —

    when mod is not a callable drawing module or attributes is not a Hash



61
62
63
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 61

def Group(mod, *args, attributes: {}, **kwargs, &block)
  g(**Wrapper.attributes(mod, attributes, kind: "Group")) { Call(mod, *args, **kwargs, &block) }
end

#InkscapeTemplateInfo(name:, desc: nil, author: nil, date: nil, keywords: nil) ⇒ Sumi::Graphics::Element

Adds Inkscape template metadata.

Parameters:

  • name (String) —

    template name

  • desc (String, nil) (defaults to: nil) —

    short description

  • author (String, nil) (defaults to: nil) —

    author

  • date (String, nil) (defaults to: nil) —

    date

  • keywords (Array<String>, String, nil) (defaults to: nil) —

    keywords

Returns:



35
36
37
38
39
40
41
42
43
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 35

def InkscapeTemplateInfo(name:, desc: nil, author: nil, date: nil, keywords: nil)
  Element(:"inkscape:_templateinfo") do
    Element(:"inkscape:_name", name)
    Element(:"inkscape:_shortdesc", desc) if desc
    Element(:"inkscape:date", date) if date
    Element(:"inkscape:author", author) if author
    Element(:"inkscape:_keywords", [*keywords].join(" ")) if keywords
  end
end

#Layer(mod, *args, attributes: {}, **kwargs) { ... } ⇒ Sumi::Graphics::Element

Renders a callable module inside an Inkscape layer. Named modules default the layer id to their final constant name. Anonymous modules omit the id unless supplied.

Parameters:

  • mod (Module) —

    module extended with Sumi::Graphics::Module

  • args (Array<Object>) —

    callable arguments

  • attributes (Hash) (defaults to: {}) —

    layer attributes. String and Symbol names are normalized and must not collide

  • kwargs (Hash) —

    callable keyword arguments

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object) —

    callable customization result

Returns:

Raises:

  • (Sumi::ArgumentError) —

    when mod is not a callable drawing module or attributes is not a Hash



75
76
77
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 75

def Layer(mod, *args, attributes: {}, **kwargs, &block)
  layer(**Wrapper.attributes(mod, attributes, kind: "Layer")) { Call(mod, *args, **kwargs, &block) }
end

#layer(**attributes) { ... } ⇒ Sumi::Graphics::Element

Builds an Inkscape layer group.

Parameters:

  • attributes (Hash) —

    layer attributes

Yields:

  • evaluates the drawing DSL in the layer

Yield Returns:

  • (Object) —

    ignored block result

Returns:



99
100
101
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 99

def layer(**, &block)
  g("inkscape:groupmode": "layer", **, &block)
end

#Layer!(mod, *args, attributes: {}, **kwargs) { ... } ⇒ Sumi::Graphics::Element

Renders a callable module inside an insensitive Inkscape layer. Named modules default the layer id to their final constant name. Anonymous modules omit the id unless supplied.

Parameters:

  • mod (Module) —

    module extended with Sumi::Graphics::Module

  • args (Array<Object>) —

    callable arguments

  • attributes (Hash) (defaults to: {}) —

    layer attributes. String and Symbol names are normalized and must not collide

  • kwargs (Hash) —

    callable keyword arguments

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object) —

    callable customization result

Returns:

Raises:

  • (Sumi::ArgumentError) —

    when mod is not a callable drawing module or attributes is not a Hash



89
90
91
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 89

def Layer!(mod, *args, attributes: {}, **kwargs, &block)
  layer!(**Wrapper.attributes(mod, attributes, kind: "Layer")) { Call(mod, *args, **kwargs, &block) }
end

#layer!(**attributes) { ... } ⇒ Sumi::Graphics::Element

Builds an insensitive Inkscape layer group.

Parameters:

  • attributes (Hash) —

    layer attributes

Yields:

  • evaluates the drawing DSL in the layer

Yield Returns:

  • (Object) —

    ignored block result

Returns:



109
110
111
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 109

def layer!(**, &block)
  layer("sodipodi:insensitive": "true", **, &block)
end

#Pages(*pages, namedview: {}, page: {}) {|page| ... } ⇒ Sumi::Graphics::Element

Builds an Inkscape namedview containing page elements.

Examples:

Build explicit pages with separate namedview and page attributes

Sumi::Graphics.SVG(:inkscape) do
  Pages(
    {x: 0, y: 0, width: 100, height: 50, label: "front"},
    namedview: {id: "views"},
    page: {class: "print"}
  )
end

Parameters:

  • pages (Array<Hash>) —

    page attribute hashes. Numeric page fields are normalized to SVG numbers

  • namedview (Hash) (defaults to: {}) —

    namedview attributes. String and Symbol names are normalized and must not collide

  • page (Hash) (defaults to: {}) —

    page defaults. Normalized page attributes override these defaults by name

Yields:

  • (page) —

    customizes each generated page element

Yield Parameters:

Yield Returns:

  • (Object) —

    ignored customization result

Returns:

Raises:

  • (Sumi::ArgumentError) —

    when an attribute channel, page, coordinate, or dimension is invalid



258
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 258

def Pages(*pages, namedview: {}, page: {}, &block) = Pagination.call(self, pages, namedview:, page:, &block)

#PagesTabular(rows:, cols:, width:, height:, gap:, namedview: {}, page: {}) {|page| ... } ⇒ Sumi::Graphics::Element

Builds a tabular set of Inkscape pages.

Examples:

Build a page grid using the same attribute channels as #Pages

Sumi::Graphics.SVG(:inkscape) do
  PagesTabular(
    rows: 2, cols: 3, width: 100, height: 50, gap: 5,
    namedview: {id: "views"}, page: {class: "print"}
  )
end

Parameters:

  • rows (Integer) —

    number of rows

  • cols (Integer) —

    number of columns

  • width (Numeric) —

    finite positive page width, normalized to an SVG number

  • height (Numeric) —

    finite positive page height, normalized to an SVG number

  • gap (Numeric) —

    finite non-negative gap, normalized to an SVG number

  • namedview (Hash) (defaults to: {}) —

    namedview attributes. String and Symbol names are normalized and must not collide

  • page (Hash) (defaults to: {}) —

    page defaults. Normalized page attributes override these defaults by name

Yields:

  • (page) —

    customizes each generated page element

Yield Parameters:

Yield Returns:

  • (Object) —

    ignored customization result

Returns:

Raises:

See Also:



281
282
283
284
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 281

def PagesTabular(rows:, cols:, width:, height:, gap:, namedview: {}, page: {}, &block)
  pages = Pagination.tabular(rows:, cols:, width:, height:, gap:)
  Pages(*pages, namedview:, page:, &block)
end

#symbol!(**attributes) { ... } ⇒ Sumi::Graphics::Element

Builds an Inkscape symbol group hidden from the symbols menu.

Parameters:

  • attributes (Hash) —

    symbol attributes

Yields:

  • evaluates the drawing DSL in the symbol group

Yield Returns:

  • (Object) —

    ignored block result

Returns:



292
293
294
295
296
297
298
299
300
# File 'graphics/lib/sumi/graphics/mixtures/inkscape.rb', line 292

def symbol!(**, &block)
  if Is?(:defs)
    g(role: "inkscape:symbol", **, &block)
  else
    symbol_element = nil
    defs { symbol_element = g(role: "inkscape:symbol", **, &block) }
    symbol_element
  end
end