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, **kwargs) { ... } ⇒ Sevgi::Graphics::Element

Renders a callable module inside a group.

Parameters:

  • mod (Module)

    callable drawing module

  • args (Array<Object>)

    callable arguments

  • kwargs (Hash)

    group attributes

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object)

    callable customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



33
34
35
36
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 33

def Group(mod, *args, **kwargs, &block)
  kwargs = kwargs.merge(id: F.demodulize(mod).to_sym) unless kwargs.key?(:id)
  g(**kwargs) { Call(mod, *args, &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:



15
16
17
18
19
20
21
22
23
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 15

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, **kwargs) { ... } ⇒ Sevgi::Graphics::Element

Renders a callable module inside an Inkscape layer.

Parameters:

  • mod (Module)

    callable drawing module

  • args (Array<Object>)

    callable arguments

  • kwargs (Hash)

    layer attributes

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object)

    callable customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



46
47
48
49
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 46

def Layer(mod, *args, **kwargs, &block)
  kwargs = kwargs.merge(id: F.demodulize(mod).to_sym) unless kwargs.key?(:id)
  layer(**kwargs) { Call(mod, *args, &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:



70
71
72
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 70

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

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

Renders a callable module inside an insensitive Inkscape layer.

Parameters:

  • mod (Module)

    callable drawing module

  • args (Array<Object>)

    callable arguments

  • kwargs (Hash)

    layer attributes

Yields:

  • forwards customization to the callable module

Yield Returns:

  • (Object)

    callable customization result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



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

def Layer!(mod, *args, **kwargs, &block)
  kwargs = kwargs.merge(id: F.demodulize(mod).to_sym) unless kwargs.key?(:id)
  layer!(**kwargs) { Call(mod, *args, &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:



80
81
82
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 80

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

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

Builds an Inkscape namedview containing page elements.

Parameters:

  • pages (Array<Hash>)

    page attribute hashes

  • id (String) (defaults to: "namedview")

    namedview id

Yields:

  • (page)

    customizes each generated page element

Yield Parameters:

Yield Returns:

  • (Object)

    ignored customization result

Returns:



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

def Pages(*pages, id: "namedview", **, &block)
  Element(:"sodipodi:namedview", id:, **) do
    pages.each_with_index do |page, i|
      id = page[:id] || "page-#{i + 1}"
      x, y, width, height = page.values_at(*%i[x y width height])
      element = Element(:"inkscape:page", id:, x:, y:, width:, height:)
      yield(element) if block
    end
  end
end

#PagesTabular(rows:, cols:, width:, height:, gap:, id: "namedview") ⇒ Array<Array>

Builds a tabular set of Inkscape pages.

Parameters:

  • rows (Integer)

    number of rows

  • cols (Integer)

    number of columns

  • width (Numeric)

    page width

  • height (Numeric)

    page height

  • gap (Numeric)

    gap between pages

  • id (String) (defaults to: "namedview")

    namedview id

Returns:

  • (Array<Array>)

    matrix entries as x, y, and label tuples



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 110

def PagesTabular(rows:, cols:, width:, height:, gap:, id: "namedview", **)
  [].tap do |matrix|
    Element(:"sodipodi:namedview", id:) do
      rows.times do |row|
        cols.times do |col|
          matrix << (x, y, label = col * (width + gap), row * (height + gap), "#{row + 1}x#{col + 1}")
          Element(:"inkscape:page", id: "pageview-#{label}", x:, y:, width:, height:, **)
        end
      end
    end
  end
end

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

Internal symbol which does not show up Symbols Menu

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:



130
131
132
133
134
135
136
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 130

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