parseSvg

fun parseSvg(content: String, templates: Map<String, String> = emptyMap()): GroupNode

Parses content, an SVG document in the module's /v1 format, into a GroupNode scene.

The root viewBox becomes the scene's bounds, and every coordinate maps viewBox-relative into CGA model space (centered, Y-up) at full Double precision — nothing is quantized on load; canonical equality is the shapes' own rounded identity. Styles resolve here to a fully concrete per-shape style: root-<svg> and <g> presentation attributes cascade nearest-wins into each shape's unset slots, k:tags union down onto every leaf, and no inheritance escapes into the scene.

templates backs external <use href="doc.svg"> expansion: each key is a referenced document's path (its href up to any #, which is tolerated and ignored), each value that document's raw SVG text. A <use> site re-parses its template inside the site's own inheritance chain, so use-site presentation attributes and k:tags flow into the template's unset slots — a per-instance restyle of the shared template. Documents without <use> need no templates; scanSvgRefs lists the paths a document references.

Return

The scene: the parsed children in source order, bounds carrying the viewBox.

Parameters

content

The SVG document text.

templates

Referenced document path → that document's raw SVG text; empty by default.

Throws

when a <use> references a document absent from templates.

when the document violates the /v1 format — every failure is a subtype naming its condition.

XmlException

when the text is not well-formed XML — below the format layer, so outside the SvgFormatException hierarchy.

Parses this file's UTF-8 SVG text into a GroupNode scene.

The string entry point parseSvg(content) with the file read inline. There is no templates map, so the document must be self-contained — a <use> reference throws MissingTemplateException; fetch the templates and call the string form directly when a layout needs them.

Receiver

The SVG file to read.

Return

The scene: the parsed children in source order, bounds carrying the viewBox.

Throws

when the file cannot be read.

when the document violates the /v1 format — every failure is a subtype naming its condition.

XmlException

when the text is not well-formed XML — below the format layer, so outside the SvgFormatException hierarchy.