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, &block) ⇒ 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

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



31
32
33
34
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 31

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, &block) ⇒ 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

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



42
43
44
45
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 42

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

Returns:



62
63
64
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 62

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

#Layer!(mod, *args, **kwargs, &block) ⇒ 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

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a plain module



53
54
55
56
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 53

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

Returns:



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

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

#Pages(*pages, id: "namedview", &block) ⇒ Sevgi::Graphics::Element

Builds an Inkscape namedview containing page elements.

Parameters:

  • pages (Array<Hash>)

    page attribute hashes

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

    namedview id

Returns:



78
79
80
81
82
83
84
85
86
87
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 78

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



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sevgi/graphics/mixtures/inkscape.rb', line 97

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

Returns:



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

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