Class SvgNode
A node of a document's render tree: the elements resolved for drawing, with styles applied, units in pixels, use
expanded, references linked and shapes turned into paths, as resvg's usvg tree. It is immutable, so a document that is not
being edited can be drawn on many threads at once.
public abstract record SvgNode : IEquatable<SvgNode>
- Inheritance
-
SvgNode
- Implements
- Derived
- Inherited Members
Examples
// The resolved tree: groups, paths with their paints and strokes, images; styles applied and units in pixels.
static void Walk(SvgNode node, int depth)
{
string what = node switch
{
SvgPath path => $"path {path.Path.Bounds} fill {path.Fill}",
SvgGroup group => $"group of {group.Children.Count}",
SvgImage image => $"image {image.Destination}",
_ => node.GetType().Name,
};
Console.WriteLine($"{new string(' ', depth * 2)}{node.Id} {what} opacity {node.Opacity}");
if (node is SvgGroup g)
{
foreach (SvgNode child in g.Children)
{
Walk(child, depth + 1);
}
}
}
Walk(document.RenderTree, 0);
Remarks
RenderTree builds the tree on first use after a load or an edit and caches it. Drawing walks it and
calls only the public canvas API, so a raster canvas, a PDF page, SvgCanvas and a PictureRecorder receive
the same calls. A later 1.x release may add node kinds, so a switch over nodes should keep a default case.
Properties
BlendMode
Gets how the node blends with what lies below it (mix-blend-mode).
public BlendMode BlendMode { get; init; }
Property Value
Bounds
Gets the node's object bounding box in its own coordinates (before Transform): the geometry without strokes, markers or filters, as SVG's objectBoundingBox units use it. Empty for a node that draws nothing.
public RectF Bounds { get; init; }
Property Value
Classes
Gets the element's classes, from its class attribute.
public IReadOnlyList<string> Classes { get; init; }
Property Value
Clip
Gets the clip path, in this node's coordinates, or null.
public SvgClip? Clip { get; init; }
Property Value
Element
Gets the element this node was made from, or null for a node with no element of its own.
public SvgElement? Element { get; init; }
Property Value
Filter
Gets the filter, in this node's coordinates, or null.
public SvgFilter? Filter { get; init; }
Property Value
Id
Gets the element's id, or null.
public string? Id { get; init; }
Property Value
Isolated
Gets a value indicating whether the node starts its own transparency group (isolation: isolate).
public bool Isolated { get; init; }
Property Value
Mask
Gets the mask, in this node's coordinates, or null.
public SvgMask? Mask { get; init; }
Property Value
Opacity
Gets the opacity the node is drawn with as a whole, 0 to 1.
public float Opacity { get; init; }
Property Value
Transform
Gets the transform from this node's coordinates to its parent's.
public Matrix3x2 Transform { get; init; }