SceneElement Class

An element of a Scene.

public abstract class SceneElement

Properties

NameDescription
BlendModeGets or sets how the element is blended with what is drawn under it. The default is SceneBlendMode.Normal.
ClippingPathGets or sets the shapes and texts outside of which the element is not drawn, as the SVG clip-path property, or null for none.
CssClassGets or sets the CSS class of the element in the SVG output.
DataAttributesGets the data-* attributes of the element in the SVG output, by name without the data- prefix. Scripts of a web page read them with element.dataset. Set them with SceneElement.SetDataAttribute.
FilterGets or sets the effect applied to what the element draws, such as a blur or a drop shadow, or null for none.
HyperlinkGets or sets the address the element links to, or null for none. The SVG output wraps the element in an a element, the PDF output adds a link over what it draws (absolute addresses only), and an image ignores it.
IdGets or sets the identifier of the element in the SVG output (its id attribute), or null for none: a script or a style sheet of a web page finds the element with it. The other renderers ignore it.
MaskGets or sets the opacity mask of the element, or null for none.
OpacityGets or sets the opacity of the element, from 0 to 1.
TooltipGets or sets the text shown when hovering the element (an SVG title).
TransformGets or sets the transform of the element, or null for none. For a group, it transforms its children.

Gets or sets how the element is blended with what is drawn under it. The default is SceneBlendMode.Normal.

public SceneBlendMode BlendMode { get; set; }

Property value

SceneBlendMode

ClippingPath

SceneElement.cs

Gets or sets the shapes and texts outside of which the element is not drawn, as the SVG clip-path property, or null for none.

public SceneClipPath? ClippingPath { get; set; }

Property value

SceneClipPath?

Remarks

The clipping path is in the coordinates of the parent of the element, as SceneElement.Mask: outside of the SceneElement.Transform of the element. It applies after the SceneElement.Filter and before the mask, as in SVG.

Gets or sets the CSS class of the element in the SVG output.

public string? CssClass { get; set; }

Property value

string?

DataAttributes

SceneElement.cs

Gets the data-* attributes of the element in the SVG output, by name without the data- prefix. Scripts of a web page read them with element.dataset. Set them with SceneElement.SetDataAttribute.

public IReadOnlyDictionary<string, string> DataAttributes { get; }

Gets or sets the effect applied to what the element draws, such as a blur or a drop shadow, or null for none.

public SceneFilter? Filter { get; set; }

Property value

SceneFilter?

Remarks

PDF has no filters: the PDF renderer throws NotSupportedException for a scene that has one.

Gets or sets the identifier of the element in the SVG output (its id attribute), or null for none: a script or a style sheet of a web page finds the element with it. The other renderers ignore it.

public string? Id { get; set; }

Property value

string?

Exceptions

ArgumentException
The value is not a valid identifier (SceneElement.IsValidId).

Remarks

The identifiers of the elements of a scene must be different: SvgSceneRenderer throws InvalidOperationException when two elements have the same one. The identifiers the renderer generates (of the gradients, the clip paths, ...) avoid them.

Gets or sets the opacity mask of the element, or null for none.

public SceneMask? Mask { get; set; }

Property value

SceneMask?

Gets or sets the opacity of the element, from 0 to 1.

public double Opacity { get; set; }

Property value

double

Gets or sets the text shown when hovering the element (an SVG title).

public string? Tooltip { get; set; }

Property value

string?

Gets or sets the transform of the element, or null for none. For a group, it transforms its children.

public SceneTransform? Transform { get; set; }

Property value

SceneTransform?

Remarks

The element is drawn as if it were the only child of a group with this transform: its clips, its mask, its filter, its opacity and its hyperlink are in the coordinates of its parent, around what it draws. The rotation of a text (SceneText.Rotation) applies before the transform.

Methods

NameDescription
GetBounds(Func<SceneText, SceneBounds?>, bool)Gets a rectangle that contains what the element draws, in the coordinates of its parent, or null when it draws nothing, for a renderer that places what it draws: a filter region, a link, a layer.
IsValidDataAttributeName(string?)Indicates whether a name is a valid name of a data-* attribute: lowercase ASCII letters, digits, hyphens, underscores and dots, without the data- prefix.
IsValidId(string?)Indicates whether a value is a valid identifier (SceneElement.Id): an ASCII letter, then ASCII letters, digits, hyphens, underscores and dots.
SetDataAttribute(string, string?)Sets a data-* attribute of the element in the SVG output, or removes it.
ThrowIfInvalidDataAttributeName(string, string)Throws when a name is not a valid name of a data-* attribute.

GetBounds(Func<SceneText, SceneBounds?>, bool)

SceneElement.cs

Gets a rectangle that contains what the element draws, in the coordinates of its parent, or null when it draws nothing, for a renderer that places what it draws: a filter region, a link, a layer.

public SceneBounds? GetBounds(Func<SceneText, SceneBounds?> measureText, bool applyClips = true)

Parameters

measureText Func<SceneText, SceneBounds?>
Gives the rectangle of a text before its rotation, in the coordinates of its parent, or null when it draws nothing: the size of a text depends on the fonts of the renderer. It is not called for a text on a path (SceneText.Path), whose rectangle is the one of its path enlarged by the size of its font.
applyClips bool
Whether the clips apply (SceneGroup.Clip, SceneGroup.ClipPath, SceneElement.ClippingPath). The filter of an element applies before its clips: the region of its filter is the rectangle without them.

Returns

SceneBounds? The rectangle, or null.

Remarks

The rectangle contains the strokes, with their joins and their caps, and the blurs and the shadows of the children; not the filter of the element itself. A group applies its transform, and its clips unless applyClips is false.

IsValidDataAttributeName(string?)

SceneElement.cs

Indicates whether a name is a valid name of a data-* attribute: lowercase ASCII letters, digits, hyphens, underscores and dots, without the data- prefix.

public static bool IsValidDataAttributeName(string? name)

Parameters

name string?
The name.

Returns

bool true when the name is valid.

IsValidId(string?)

SceneElement.cs

Indicates whether a value is a valid identifier (SceneElement.Id): an ASCII letter, then ASCII letters, digits, hyphens, underscores and dots.

public static bool IsValidId(string? id)

Parameters

id string?
The identifier.

Returns

bool true when the identifier is valid.

Remarks

These identifiers are written in url(#id) references and CSS selectors without escaping.

SetDataAttribute(string, string?)

SceneElement.cs

Sets a data-* attribute of the element in the SVG output, or removes it.

public void SetDataAttribute(string name, string? value)

Parameters

name string
The name of the attribute without the data- prefix: lowercase ASCII letters, digits, hyphens, underscores and dots.
value string?
The value, or null to remove the attribute.

Exceptions

ArgumentException
name is empty or contains another character.

ThrowIfInvalidDataAttributeName(string, string)

SceneElement.cs

Throws when a name is not a valid name of a data-* attribute.

public static void ThrowIfInvalidDataAttributeName(string name, string paramName)

Parameters

name string
The name.
paramName string
The name of the parameter, for the exception.

Exceptions

ArgumentException
name is empty or contains another character.
ArgumentNullException
name is null.