Module: Sevgi::Graphics

Extended by:
Graphics
Included in:
Graphics
Defined in:
lib/sevgi/graphics.rb,
lib/sevgi/graphics/element.rb,
lib/sevgi/graphics/version.rb,
lib/sevgi/graphics/document.rb,
lib/sevgi/graphics/mixtures.rb,
lib/sevgi/graphics/attribute.rb,
lib/sevgi/graphics/mixtures/rdf.rb,
lib/sevgi/graphics/document/base.rb,
lib/sevgi/graphics/document/html.rb,
lib/sevgi/graphics/mixtures/call.rb,
lib/sevgi/graphics/mixtures/core.rb,
lib/sevgi/graphics/mixtures/lint.rb,
lib/sevgi/graphics/mixtures/save.rb,
lib/sevgi/graphics/mixtures/tile.rb,
lib/sevgi/graphics/mixtures/hatch.rb,
lib/sevgi/graphics/auxiliary/paper.rb,
lib/sevgi/graphics/mixtures/export.rb,
lib/sevgi/graphics/mixtures/render.rb,
lib/sevgi/graphics/auxiliary/canvas.rb,
lib/sevgi/graphics/auxiliary/margin.rb,
lib/sevgi/graphics/document/default.rb,
lib/sevgi/graphics/document/minimal.rb,
lib/sevgi/graphics/mixtures/include.rb,
lib/sevgi/graphics/mixtures/symbols.rb,
lib/sevgi/graphics/auxiliary/content.rb,
lib/sevgi/graphics/document/inkscape.rb,
lib/sevgi/graphics/mixtures/identify.rb,
lib/sevgi/graphics/mixtures/inkscape.rb,
lib/sevgi/graphics/mixtures/validate.rb,
lib/sevgi/graphics/mixtures/wrappers.rb,
lib/sevgi/graphics/mixtures/duplicate.rb,
lib/sevgi/graphics/mixtures/polyfills.rb,
lib/sevgi/graphics/mixtures/transform.rb,
lib/sevgi/graphics/mixtures/underscore.rb

Overview

SVG document builder and DSL namespace.

Defined Under Namespace

Modules: Attribute, Document, Mixtures, Module Classes: Canvas, Content, Element, Margin, Paper

Constant Summary collapse

VERSION =

Current graphics component version.

"0.93.1"
ATTRIBUTE_INTERNAL_PREFIX =

Internal store syntax; not part of the SVG DSL command surface.

"-"
ATTRIBUTE_UPDATE_SUFFIX =

Attribute suffix that merges new values into an existing attribute.

"+"
Attributes =

Public alias for the SVG attribute store.

Attribute::Store
LintError =

Raised when graphics lint checks fail.

Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#canvas(arg = Undefined, **kwargs) ⇒ Sevgi::Graphics::Canvas

Builds a canvas from a paper profile or explicit size.

Parameters:

  • arg (Sevgi::Graphics::Paper, Symbol, String, Sevgi::Undefined) (defaults to: Undefined)

    paper profile or paper object

  • kwargs (Hash)

    canvas keyword arguments

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the paper profile is unknown



23
24
25
# File 'lib/sevgi/graphics.rb', line 23

def canvas(...)
  Graphics::Canvas.from_paper(...)
end

#document(name = Undefined, preambles: [], attributes: {}) ⇒ Class

Defines or returns a document profile class.

Parameters:

  • name (Symbol, String, Sevgi::Undefined) (defaults to: Undefined)

    profile name, or Undefined for an anonymous profile

  • preambles (Array<String>, nil) (defaults to: [])

    document preamble lines

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

    default root attributes

Returns:

  • (Class)

    document class

Raises:

  • (Sevgi::ArgumentError)

    when a named profile conflicts with an existing profile



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

def document(name = Undefined, preambles: [], attributes: {})
  Graphics::Document.define(name, preambles:, attributes:)
end

#document!(name, preambles: [], attributes: {}) ⇒ Class

Defines or replaces a document profile class.

Parameters:

  • name (Symbol, String)

    profile name

  • preambles (Array<String>, nil) (defaults to: [])

    document preamble lines

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

    default root attributes

Returns:

  • (Class)

    document class

Raises:

  • (Sevgi::ArgumentError)

    when the profile name is invalid



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

def document!(name, preambles: [], attributes: {})
  Graphics::Document.define(name, preambles:, attributes:, overwrite: true)
end

#paper(width, height, name = :custom, unit: "mm") ⇒ Symbol, String

Defines a paper profile unless the same profile already exists.

Parameters:

  • width (Numeric)

    paper width

  • height (Numeric)

    paper height

  • name (Symbol, String) (defaults to: :custom)

    profile name

  • unit (Symbol, String) (defaults to: "mm")

    SVG unit

Returns:

  • (Symbol, String)

    original profile name

Raises:

  • (Sevgi::ArgumentError)

    when the profile is invalid or an existing profile has different dimensions



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sevgi/graphics.rb', line 54

def paper(width, height, name = :custom, unit: "mm")
  profile = Graphics::Paper[width, height, unit, name]

  if Graphics::Paper.exist?(name)
    ArgumentError.("Paper already defined differently: #{name}") unless Graphics::Paper.public_send(name) == profile
  else
    Graphics::Paper.define(name, width:, height:, unit:)
  end

  name
end

#paper!(width, height, name = :custom, unit: "mm") ⇒ Symbol, String

Defines or replaces a paper profile.

Parameters:

  • width (Numeric)

    paper width

  • height (Numeric)

    paper height

  • name (Symbol, String) (defaults to: :custom)

    profile name

  • unit (Symbol, String) (defaults to: "mm")

    SVG unit

Returns:

  • (Symbol, String)

    original profile name

Raises:

  • (Sevgi::ArgumentError)

    when the profile is invalid or the profile name is reserved



73
74
75
# File 'lib/sevgi/graphics.rb', line 73

def paper!(width, height, name = :custom, unit: "mm")
  name.tap { Graphics::Paper.define(name, width:, height:, unit:) }
end

#SVG(document = :default, canvas = Undefined, &block) ⇒ Sevgi::Graphics::Document::Proto

Builds an SVG root document.

Parameters:

  • document (Symbol, String, Class) (defaults to: :default)

    document profile name or document class

  • canvas (Sevgi::Graphics::Canvas, Sevgi::Graphics::Paper, Symbol, String, Sevgi::Undefined, nil) (defaults to: Undefined)

    canvas input

  • block (Proc, nil)

    DSL block evaluated in the root element

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the document or canvas profile is unknown



83
84
85
# File 'lib/sevgi/graphics.rb', line 83

def SVG(document = :default, canvas = Undefined, **, &block)
  Graphics::Document.(document, canvas, **, &block)
end