dom library

This package provides a document object model to allow programmatic modification of an SVG asset. It can be used for animation/scripting, where the asset is modified then displayed, perhaps many times. This is similar to what some web pages do with JavaScript code modifying an SVG.

Sample Usage:

final String svgSrc =
    '<svg><circle id="foo" cx="5" cy="5" r="5" fill="green"/></svg>';
final svg = SvgDOMManager.fromString(svgSrc);
final node = svg.dom.idLookup['foo'] as SvgEllipse;
node.paint.fillColor = Colors.blue;
final ScalableImage si = svg.build();
   ... display si, perhaps in a ScalableImageWidget ...

A full sample can be found in the GitHub repository in example/lib/animation.dart. Here is an overview of the DOM class structure:

Classes

Affine
Affine matrix, used to represent scale, translate and other transformations applied to e.g. an SVG node. Attaching an affine matrix to a node is equivalent to calling dart:ui's Canvas.transform method.
MutableAffine
An mutable version of an Affine matrix.
ParseError
Exception thrown when there is a problem parsing See PathParser.parse.
PathBuilder
A builder of a path whose source is a SVG path element. A PathParser calls methods on an implementor of PathBuilder as it parses the components of an SVG path.
PathParser
Parse an SVG Path. The path syntax is specified at at https://www.w3.org/TR/2018/CR-SVG2-20181004/paths.html
StringPathBuilder
A PathBuilder that produces a path string. This can be used with a PathParser if you have a path string that you want to parse, modify, and then reconstitute as a path string.
Style
An entry in the list of styles for a given element type or node ID in a Stylesheet.
SvgColor
Color as SVG knows it, plus alpha in the high-order byte (in case we encounter an SVG file with an (invalid) eight-character hex value).
SvgColorReference
A reference to a gradient color. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgCoordinate
A coordinate in a gradient color. A coordinate can be a pixel value or a percentage.
SvgCustomPath
An SVG node that lets the client specify the Path directly. This can be used with the SVG DOM API, by programmatically creating an instance of this node, and inserting it into an SVG DOM, either in a SvgGroup or into SvgDOM.root.
SvgDefs
An SVG definitions node. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/struct.html#DefsElement .
SvgDOM
A document object model representing an asset that can be turned into a ScalableImage. Normally this is obtained by parsing an SVG XML file (or, internally, by parsing an Android AVD XML file). See also SVGDomManager.
SvgDOMManager
Support for loading an SVG asset, manipulating it, and producing ScalableImage instances from the asset's current state. This is the entry point for use of the dom library.
SvgEllipse
An SVG ellipse or circle. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#EllipseElement and https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#CircleElement .
SvgFontSize
Font size for SVG text. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html#FontPropertiesUsedBySVG .
SvgFontSizeAbsolute
Absolute font size for SVG text. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html#FontPropertiesUsedBySVG .
SvgFontWeight
The value of an SVG font weight attribute. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html#FontWeightProperty .
SvgGradientColor
A gradient color. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgGradientNode
A node in an SVG asset that defines an SvgGradientColor. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgGradientStop
An SVG gradient stop. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgGradientStopStyle
The style attributes for an SVG gradient stop. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgGroup
An SVG g node. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/struct.html#Groups .
SvgImage
An SVG image. See https://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#ImageElement .
SvgInheritableAttributes
Attributes of an SVG element that are inherited from an ancestor node. These attributes are also present in Style instances.
SvgInheritableAttributesNode
Common supertype of nodes that can contain the attributes that are inherited by children.
SvgInheritableTextAttributes
Attributes of an SVG element that are inherited from an ancestor node, and that are also present in an SvgTextSpan within an SVG text element..
SvgLinearGradientColor
An SVG linear gradient. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients
SvgMask
An SVG mask. See https://www.w3.org/TR/2011/REC-SVG11-20110816/masking.html#MaskElement .
SvgNode
Common supertype for all nodes in an SVG DOM graph.
SvgPaint
Parameters used to control the painting of an SVG node. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html .
SvgPath
An SVG path. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/paths.html#PathElement .
SvgPoly
An SVG line, polyline or polygon. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#LineElement , https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#PolylineElement , or https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#PolygonElement .
SvgRadialGradientColor
An SVG radial gradient. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgRect
An SVG rect element. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/shapes.html#RectElement .
SvgRoot
The root node of an SvgDOM.
SvgSweepGradientColor
An SVG sweep gradient. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SvgSymbol
An SVG symbol. See https://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#SymbolElement .
SvgText
An SVG text node. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SvgTextSpan
An SVG tspan. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SvgTextSpanComponent
A component of an SVG tspan. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SvgTextSpanStringComponent
A string run within an SVG text. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SvgTextStyle
Text styling information for an SVG asset. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html#FontPropertiesUsedBySVG .
SvgUse
An SVG use. See https://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#UseElement .
SvgValueColor
A color value, specified as a 32 bit ARGB value. Normally, the alpha is fully opaque (0xff); transparency in SVG is specified as a separate attribute. However, many renderers (including this one) honor a transparency value other than 0xff in the top byte, where appropriate.

Enums

SIBlendMode
Possible blend mode values used when painting a node. This is analagous to BlendMode in dart:ui.
SIDominantBaseline
Dominant baseline values. See https://www.w3.org/TR/SVG11/text.html .
SIFillType
Possible fill type values for a paint object. This is analogous to PathFillType in dart:ui.
SIFontStyle
Possible font styles.
SIGradientSpreadMethod
Possible spread methods for a color gradient. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/painting.html#Gradients .
SIStrokeCap
Possible stroke cap values for a paint object. This is analagous to StrokeCap in dart:ui.
SIStrokeJoin
Possible stroke join values for a paint object. This is analagous to StrokeJoin in dart:ui.
SITextAnchor
Text anchor values. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SITextDecoration
Text decoration values. See https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html .
SITintMode
Possible tint mode values for an asset. This is a top-level property for an asset that is not present in an SVG; it comes from Android Vector Drawables. It determines the dart:ui BlendMode used to apply a tint,

Typedefs

Stylesheet = Map<String, List<Style>>
A stylesheet is a map from a tagName or a node ID to a list of Style instances. A tagName is like "tspan" or "", and an ID starts with "#". The Style instances will be in the order they were encountered in the SVG source file.