Module: Sevgi::Graphics

Extended by:
Graphics
Included in:
Graphics
Defined in:
lib/sevgi/graphics.rb,
lib/sevgi/graphics/xml.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/auxiliary/sizes.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/auxiliary/scalar.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.95.0"
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



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

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

#document(name) ⇒ Class #document(name, preambles: Undefined, attributes: Undefined) ⇒ Class #document(preambles: Undefined, attributes: Undefined) ⇒ Class

Returns document class.

Overloads:

  • #document(name) ⇒ Class

    Looks up an existing document profile by name.

    Parameters:

    • name (Symbol, String)

      profile name

    Returns:

    • (Class)

      document class

    Raises:

    • (Sevgi::ArgumentError)

      when the profile is unknown

  • #document(name, preambles: Undefined, attributes: Undefined) ⇒ Class

    Looks up a named profile when both definition keywords are omitted. Supplying preambles: or attributes: defines a named profile, or returns an existing profile when every explicitly supplied field matches. Omitted fields are ignored during existing-profile comparison. Profile containers and strings are copied into the process-global, thread-atomic registry; mutable non-container attribute values are stringified once before registration. Concurrent identical definitions return the same canonical registered class.

    Parameters:

    • name (Symbol, String)

      profile name

    • preambles (Array<String>, nil, Sevgi::Undefined) (defaults to: Undefined)

      document preamble lines

    • attributes (Hash, nil, Sevgi::Undefined) (defaults to: Undefined)

      default root attributes; nil means an empty Hash

    Returns:

    • (Class)

      document class

    Raises:

    • (Sevgi::ArgumentError)

      when a profile conflicts or metadata is invalid XML, cyclic, or cannot be stringified

  • #document(preambles: Undefined, attributes: Undefined) ⇒ Class

    Defines an anonymous document profile without registering it globally.

    Parameters:

    • preambles (Array<String>, nil, Sevgi::Undefined) (defaults to: Undefined)

      document preamble lines

    • attributes (Hash, nil, Sevgi::Undefined) (defaults to: Undefined)

      default root attributes; nil means an empty Hash

    Returns:

    • (Class)

      anonymous document class

    Raises:

    • (Sevgi::ArgumentError)

      when metadata is invalid XML, cyclic, or cannot be stringified

Returns:

  • (Class)

    document class



51
52
53
# File 'lib/sevgi/graphics.rb', line 51

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

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

Defines or replaces a document profile class. Validation and snapshot capture complete before an existing registration is atomically replaced.

Parameters:

  • name (Symbol, String)

    profile name

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

    document preamble lines

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

    default root attributes; nil means an empty Hash

Returns:

  • (Class)

    document class

Raises:

  • (Sevgi::ArgumentError)

    when the name or metadata is invalid XML, cyclic, or cannot be stringified



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

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. Registration is process-global and thread-atomic; an identical concurrent definition is idempotent and a conflicting definition is rejected.

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



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

def paper(width, height, name = :custom, unit: "mm")
  Graphics::Paper.define(name, width:, height:, unit:, overwrite: false)

  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



87
88
89
# File 'lib/sevgi/graphics.rb', line 87

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

#SVG(document = :default, canvas = Undefined) { ... } ⇒ 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

Yields:

  • evaluates the drawing DSL in the root element

Yield Returns:

  • (Object)

    ignored block result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the document/canvas profile or root XML attributes are invalid



98
99
100
# File 'lib/sevgi/graphics.rb', line 98

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