Module: Sevgi::Graphics::Mixtures::Inkscape

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

Overview

Inkscape-specific SVG DSL helpers.

Instance Method Summary collapse

Instance Method Details

#Group(mod, *args, attributes: {}, **kwargs) { ... } ⇒ Sevgi::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 Sevgi::Graphics::Module
  def call = circle r: 5
end
Sevgi::Graphics.SVG(:inkscape) { Group drawing, attributes: {id: "drawing"} }

Parameters:

  • mod (Module)

    module extended with Sevgi::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:

  • (Sevgi::ArgumentError)

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



57
58
59
60
61
62
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 57

def Group(mod, *args, attributes: {}, **kwargs, &block)
  Graphics::Module.__send__(:callables, mod)
  ArgumentError.("Group attributes must be a Hash") unless attributes.is_a?(::Hash)
  attributes = Wrapper.attributes(mod, attributes)
  g(**attributes) { Call(mod, *args, **kwargs, &block) }
end

#InkscapeTemplateInfo(name:, desc: nil, author: nil, date: nil, keywords: nil) ⇒ Sevgi::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:



31
32
33
34
35
36
37
38
39
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 31

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) { ... } ⇒ Sevgi::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 Sevgi::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:

  • (Sevgi::ArgumentError)

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



74
75
76
77
78
79
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 74

def Layer(mod, *args, attributes: {}, **kwargs, &block)
  Graphics::Module.__send__(:callables, mod)
  ArgumentError.("Layer attributes must be a Hash") unless attributes.is_a?(::Hash)
  attributes = Wrapper.attributes(mod, attributes)
  layer(**attributes) { Call(mod, *args, **kwargs, &block) }
end

#layer(**attributes) { ... } ⇒ Sevgi::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:



104
105
106
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 104

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

#Layer!(mod, *args, attributes: {}, **kwargs) { ... } ⇒ Sevgi::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 Sevgi::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:

  • (Sevgi::ArgumentError)

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



91
92
93
94
95
96
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 91

def Layer!(mod, *args, attributes: {}, **kwargs, &block)
  Graphics::Module.__send__(:callables, mod)
  ArgumentError.("Layer attributes must be a Hash") unless attributes.is_a?(::Hash)
  attributes = Wrapper.attributes(mod, attributes)
  layer!(**attributes) { Call(mod, *args, **kwargs, &block) }
end

#layer!(**attributes) { ... } ⇒ Sevgi::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:



114
115
116
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 114

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

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

Builds an Inkscape namedview containing page elements.

Examples:

Build explicit pages with separate namedview and page attributes

Sevgi::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:

  • (Sevgi::ArgumentError)

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



250
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 250

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

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

Builds a tabular set of Inkscape pages.

Examples:

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

Sevgi::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:

  • (Sevgi::ArgumentError)

    when counts, dimensions, gap, or an attribute channel is invalid

See Also:



273
274
275
276
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 273

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) { ... } ⇒ Sevgi::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:



284
285
286
287
288
289
290
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 284

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