Table of Contents

Class SvgElement

Namespace
Svg
Assembly
Svg.dll

The base class of which all SVG elements are derived from.

public abstract class SvgElement : ISvgTransformable, ICloneable, ISvgNode
Inheritance
SvgElement
Implements
Derived
Inherited Members
Extension Methods

Constructors

SvgElement()

Initializes a new instance of the SvgElement class.

public SvgElement()

Fields

AutoPublishEvents

public bool AutoPublishEvents

Field Value

bool

Properties

Attributes

Gets a collection of element attributes.

protected virtual SvgAttributeCollection Attributes { get; }

Property Value

SvgAttributeCollection

BaselineShift

Specifies dominant-baseline positioning of text.

public virtual string BaselineShift { get; set; }

Property Value

string

Children

Gets a collection of all child SvgElement objects.

public virtual SvgElementCollection Children { get; }

Property Value

SvgElementCollection

Color

Gets or sets the color SvgPaintServer of this element which drives the currentColor property.

public virtual SvgPaintServer Color { get; set; }

Property Value

SvgPaintServer

ColorInterpolation

Gets or sets the color space for gradient interpolations, color animations and alpha compositing.

public SvgColourInterpolation ColorInterpolation { get; set; }

Property Value

SvgColourInterpolation

ColorInterpolationFilters

Gets or sets the color space for imaging operations performed via filter effects. NOT currently mapped through to bitmap

public SvgColourInterpolation ColorInterpolationFilters { get; set; }

Property Value

SvgColourInterpolation

Content

public virtual string Content { get; set; }

Property Value

string

CustomAttributes

Gets a collection of custom attributes

public SvgCustomAttributeCollection CustomAttributes { get; }

Property Value

SvgCustomAttributeCollection

Display

Gets or sets a value to determine whether the element will be rendered. Needed to support SVG attribute display="none"

public virtual string Display { get; set; }

Property Value

string

ElementName

Gets the name of the element.

protected string ElementName { get; }

Property Value

string

ElementNamespace

Gets the elements namespace as a string.

protected string ElementNamespace { get; set; }

Property Value

string

Events

Gets an EventHandlerList of all events belonging to the element.

protected virtual EventHandlerList Events { get; }

Property Value

EventHandlerList

Fill

Gets or sets the fill SvgPaintServer of this element.

public virtual SvgPaintServer Fill { get; set; }

Property Value

SvgPaintServer

FillOpacity

Gets or sets the opacity of this element's Fill.

public virtual float FillOpacity { get; set; }

Property Value

float

FillRule

public virtual SvgFillRule FillRule { get; set; }

Property Value

SvgFillRule

Font

Set all font information.

public virtual string Font { get; set; }

Property Value

string

FontFamily

Indicates which font family is to be used to render the text.

public virtual string FontFamily { get; set; }

Property Value

string

FontSize

Refers to the size of the font from baseline to baseline when multiple lines of text are set solid in a multiline layout environment.

public virtual SvgUnit FontSize { get; set; }

Property Value

SvgUnit

FontStretch

Indicates the desired amount of condensing or expansion in the glyphs used to render the text.

public virtual SvgFontStretch FontStretch { get; set; }

Property Value

SvgFontStretch

FontStyle

Refers to the style of the font.

public virtual SvgFontStyle FontStyle { get; set; }

Property Value

SvgFontStyle

FontVariant

Refers to the varient of the font.

public virtual SvgFontVariant FontVariant { get; set; }

Property Value

SvgFontVariant

FontWeight

Refers to the boldness of the font.

public virtual SvgFontWeight FontWeight { get; set; }

Property Value

SvgFontWeight

HttpClient

protected static HttpClient HttpClient { get; }

Property Value

HttpClient

ID

Gets or sets the ID of the element.

public string ID { get; set; }

Property Value

string

Exceptions

SvgException

The ID is already used within the SvgDocument.

IsPathDirty

Gets or sets a value indicating whether this element's 'Path' is dirty.

protected virtual bool IsPathDirty { get; set; }

Property Value

bool

true if the path is dirty; otherwise, false.

Namespaces

Gets the namespaces that element has.

public Dictionary<string, string> Namespaces { get; }

Property Value

Dictionary<string, string>

Key is prefix and value is namespace.

Nodes

public IList<ISvgNode> Nodes { get; }

Property Value

IList<ISvgNode>

Opacity

Gets or sets the opacity of the element. 1.0 is fully opaque; 0.0 is transparent.

public virtual float Opacity { get; set; }

Property Value

float

OwnerDocument

Gets the owner SvgDocument.

public virtual SvgDocument OwnerDocument { get; }

Property Value

SvgDocument

Parent

Gets the parent SvgElement.

public virtual SvgElement Parent { get; }

Property Value

SvgElement

An SvgElement if one exists; otherwise null.

Parents

public IEnumerable<SvgElement> Parents { get; }

Property Value

IEnumerable<SvgElement>

ParentsAndSelf

public IEnumerable<SvgElement> ParentsAndSelf { get; }

Property Value

IEnumerable<SvgElement>

ShapeRendering

Refers to the AnitAlias rendering of shapes.

public virtual SvgShapeRendering ShapeRendering { get; set; }

Property Value

SvgShapeRendering

SpaceHandling

Gets or sets the space handling.

[SvgAttribute("space", "http://www.w3.org/XML/1998/namespace")]
public virtual XmlSpaceHandling SpaceHandling { get; set; }

Property Value

XmlSpaceHandling

The space handling.

Stroke

Gets or sets the SvgPaintServer to be used when rendering a stroke around this element.

public virtual SvgPaintServer Stroke { get; set; }

Property Value

SvgPaintServer

StrokeDashArray

[TypeConverter(typeof(SvgStrokeDashArrayConverter))]
public virtual SvgUnitCollection StrokeDashArray { get; set; }

Property Value

SvgUnitCollection

StrokeDashOffset

public virtual SvgUnit StrokeDashOffset { get; set; }

Property Value

SvgUnit

StrokeLineCap

public virtual SvgStrokeLineCap StrokeLineCap { get; set; }

Property Value

SvgStrokeLineCap

StrokeLineJoin

public virtual SvgStrokeLineJoin StrokeLineJoin { get; set; }

Property Value

SvgStrokeLineJoin

StrokeMiterLimit

public virtual float StrokeMiterLimit { get; set; }

Property Value

float

StrokeOpacity

Gets or sets the opacity of the stroke, if the Stroke property has been specified. 1.0 is fully opaque; 0.0 is transparent.

public virtual float StrokeOpacity { get; set; }

Property Value

float

StrokeWidth

Gets or sets the width of the stroke (if the Stroke property has a valid value specified.

public virtual SvgUnit StrokeWidth { get; set; }

Property Value

SvgUnit

TextAnchor

Gets or sets the text anchor.

public virtual SvgTextAnchor TextAnchor { get; set; }

Property Value

SvgTextAnchor

TextDecoration

Refers to the boldness of the font.

public virtual SvgTextDecoration TextDecoration { get; set; }

Property Value

SvgTextDecoration

TextTransformation

Refers to the text transformation.

public virtual SvgTextTransformation TextTransformation { get; set; }

Property Value

SvgTextTransformation

Transforms

Gets or sets the element transforms.

public SvgTransformCollection Transforms { get; set; }

Property Value

SvgTransformCollection

The transforms.

Visibility

Gets or sets a value to determine whether the element will be rendered.

public virtual string Visibility { get; set; }

Property Value

string

Writing

protected bool Writing { get; set; }

Property Value

bool

Methods

AddElement(SvgElement, int)

Called by the underlying SvgElement when an element has been added to the Children collection.

protected virtual void AddElement(SvgElement child, int index)

Parameters

child SvgElement

The SvgElement that has been added.

index int

An int representing the index where the element was added to the collection.

AddPaths(SvgElement, GraphicsPath)

Recursive method to add up the paths of all children

protected void AddPaths(SvgElement elem, GraphicsPath path)

Parameters

elem SvgElement
path GraphicsPath

AddStyle(string, string, int)

Add style.

public void AddStyle(string name, string value, int specificity)

Parameters

name string

The style name.

value string

The style value.

specificity int

The specificity value.

Clone()

Creates a new object that is a copy of the current instance.

public virtual object Clone()

Returns

object

A new object that is a copy of this instance.

ContainsAttribute(string)

public bool ContainsAttribute(string name)

Parameters

name string

Returns

bool

CreateMouseEventAction(Action<object, MouseArg>)

protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)

Parameters

eventRaiser Action<object, MouseArg>

Returns

Action<float, float, int, int, bool, bool, bool, string>

DeepCopy()

public abstract SvgElement DeepCopy()

Returns

SvgElement

DeepCopy<T>()

public virtual SvgElement DeepCopy<T>() where T : SvgElement, new()

Returns

SvgElement

Type Parameters

T

Descendants()

public IEnumerable<SvgElement> Descendants()

Returns

IEnumerable<SvgElement>

FixOpacityValue(float)

protected static float FixOpacityValue(float value)

Parameters

value float

Returns

float

FlushStyles(bool)

Flush styles.

public void FlushStyles(bool children = false)

Parameters

children bool

If true, flush styles to the children.

GetAttribute<TAttributeType>(string, bool, TAttributeType)

protected TAttributeType GetAttribute<TAttributeType>(string attributeName, bool inherited, TAttributeType defaultValue = default)

Parameters

attributeName string
inherited bool
defaultValue TAttributeType

Returns

TAttributeType

Type Parameters

TAttributeType

GetPaths(SvgElement, ISvgRenderer)

Recursive method to add up the paths of all children

protected GraphicsPath GetPaths(SvgElement elem, ISvgRenderer renderer)

Parameters

elem SvgElement
renderer ISvgRenderer

Returns

GraphicsPath

HasChildren()

Gets a value to determine whether the element has children.

public virtual bool HasChildren()

Returns

bool

InitialiseFromXML(XmlReader, SvgDocument)

public virtual void InitialiseFromXML(XmlReader reader, SvgDocument document)

Parameters

reader XmlReader
document SvgDocument

InvalidateChildPaths()

Force recreation of the paths for the element and it's children.

public void InvalidateChildPaths()

OnAttributeChanged(AttributeEventArgs)

protected void OnAttributeChanged(AttributeEventArgs args)

Parameters

args AttributeEventArgs

OnContentChanged(ContentEventArgs)

protected void OnContentChanged(ContentEventArgs args)

Parameters

args ContentEventArgs

OnMouseScroll(int, bool, bool, bool, string)

protected void OnMouseScroll(int scroll, bool ctrlKey, bool shiftKey, bool altKey, string sessionID)

Parameters

scroll int
ctrlKey bool
shiftKey bool
altKey bool
sessionID string

PopTransforms(ISvgRenderer)

Removes any previously applied transforms from the specified ISvgRenderer.

protected virtual void PopTransforms(ISvgRenderer renderer)

Parameters

renderer ISvgRenderer

The ISvgRenderer that should have transforms removed.

PushTransforms(ISvgRenderer)

Applies the required transforms to ISvgRenderer.

protected virtual bool PushTransforms(ISvgRenderer renderer)

Parameters

renderer ISvgRenderer

The ISvgRenderer to be transformed.

Returns

bool

RaiseMouseClick(object, MouseArg)

protected void RaiseMouseClick(object sender, MouseArg e)

Parameters

sender object
e MouseArg

RaiseMouseDown(object, MouseArg)

protected void RaiseMouseDown(object sender, MouseArg e)

Parameters

sender object
e MouseArg

RaiseMouseMove(object, MouseArg)

protected void RaiseMouseMove(object sender, MouseArg e)

Parameters

sender object
e MouseArg

RaiseMouseOut(object, MouseArg)

protected void RaiseMouseOut(object sender, MouseArg args)

Parameters

sender object
args MouseArg

RaiseMouseOver(object, MouseArg)

protected void RaiseMouseOver(object sender, MouseArg args)

Parameters

sender object
args MouseArg

RaiseMouseScroll(object, MouseScrollArg)

protected void RaiseMouseScroll(object sender, MouseScrollArg e)

Parameters

sender object
e MouseScrollArg

RaiseMouseUp(object, MouseArg)

protected void RaiseMouseUp(object sender, MouseArg e)

Parameters

sender object
e MouseArg

RegisterEvents(ISvgEventCaller)

Use this method to provide your implementation ISvgEventCaller which can register Actions and call them if one of the events occurs. Make sure, that your SvgElement has a unique ID. The SvgTextElement overwrites this and registers the Change event tor its text content.

public virtual void RegisterEvents(ISvgEventCaller caller)

Parameters

caller ISvgEventCaller

RemoveElement(SvgElement)

Called by the underlying SvgElement when an element has been removed from the Children collection.

protected virtual void RemoveElement(SvgElement child)

Parameters

child SvgElement

The SvgElement that has been removed.

Render(ISvgRenderer)

Renders the SvgElement and contents to the specified ISvgRenderer object.

protected virtual void Render(ISvgRenderer renderer)

Parameters

renderer ISvgRenderer

The ISvgRenderer object to render to.

RenderChildren(ISvgRenderer)

Renders the children of this SvgElement.

protected virtual void RenderChildren(ISvgRenderer renderer)

Parameters

renderer ISvgRenderer

The ISvgRenderer to render the child SvgElements to.

RenderElement(ISvgRenderer)

Renders this element to the ISvgRenderer.

public void RenderElement(ISvgRenderer renderer)

Parameters

renderer ISvgRenderer

The ISvgRenderer that the element should use to render itself.

SetAndForceUniqueID(string, bool, Action<SvgElement, string, string>)

public void SetAndForceUniqueID(string value, bool autoForceUniqueID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)

Parameters

value string
autoForceUniqueID bool
logElementOldIDNewID Action<SvgElement, string, string>

ShouldWriteElement()

Derived classes may decide that the element should not be written. For example, the text element shouldn't be written if it's empty.

public virtual bool ShouldWriteElement()

Returns

bool

TransformedBounds(RectangleF)

Transforms the given rectangle with the set transformation, if any. Can be applied to bounds calculated without considering the element transformation.

protected RectangleF TransformedBounds(RectangleF bounds)

Parameters

bounds RectangleF

The rectangle to be transformed.

Returns

RectangleF

The transformed rectangle, or the original rectangle if no transformation exists.

TryGetAttribute(string, out string)

public bool TryGetAttribute(string name, out string value)

Parameters

name string
value string

Returns

bool

UnregisterEvents(ISvgEventCaller)

Use this method to provide your implementation ISvgEventCaller to unregister Actions

public virtual void UnregisterEvents(ISvgEventCaller caller)

Parameters

caller ISvgEventCaller

ValidateFontFamily(string, SvgDocument, SvgFontManager)

public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc, SvgFontManager fontManager)

Parameters

fontFamilyList string
doc SvgDocument
fontManager SvgFontManager

Returns

object

Write(XmlWriter)

Write this SvgElement out using a given XmlWriter.

public virtual void Write(XmlWriter writer)

Parameters

writer XmlWriter

The XmlWriter to use.

Remarks

Recommendation is to create an XmlWriter by calling a factory method,
e.g. Create(Stream), as per Microsoft documentation.

However, unlike an XmlTextWriter created via 'new XmlTextWriter()',
a factory-constructed XmlWriter will not flush output until it is closed
(normally via a using statement), or unless the client explicitly calls Flush().

WriteAttributes(XmlWriter)

protected virtual void WriteAttributes(XmlWriter writer)

Parameters

writer XmlWriter

WriteChildren(XmlWriter)

protected virtual void WriteChildren(XmlWriter writer)

Parameters

writer XmlWriter

WriteEndElement(XmlWriter)

protected virtual void WriteEndElement(XmlWriter writer)

Parameters

writer XmlWriter

WriteStartElement(XmlWriter)

protected virtual void WriteStartElement(XmlWriter writer)

Parameters

writer XmlWriter

Events

AttributeChanged

Fired when an Attribute of this Element has changed

public event EventHandler<AttributeEventArgs> AttributeChanged

Event Type

EventHandler<AttributeEventArgs>

ChildAdded

Fired when an Element was added to the children of this Element

public event EventHandler<ChildAddedEventArgs> ChildAdded

Event Type

EventHandler<ChildAddedEventArgs>

Click

public event EventHandler<MouseArg> Click

Event Type

EventHandler<MouseArg>

ContentChanged

Fired when an Attribute of this Element has changed

public event EventHandler<ContentEventArgs> ContentChanged

Event Type

EventHandler<ContentEventArgs>

Load

Occurs when the element is loaded.

public event EventHandler Load

Event Type

EventHandler

MouseDown

public event EventHandler<MouseArg> MouseDown

Event Type

EventHandler<MouseArg>

MouseMove

public event EventHandler<MouseArg> MouseMove

Event Type

EventHandler<MouseArg>

MouseOut

public event EventHandler<MouseArg> MouseOut

Event Type

EventHandler<MouseArg>

MouseOver

public event EventHandler<MouseArg> MouseOver

Event Type

EventHandler<MouseArg>

MouseScroll

public event EventHandler<MouseScrollArg> MouseScroll

Event Type

EventHandler<MouseScrollArg>

MouseUp

public event EventHandler<MouseArg> MouseUp

Event Type

EventHandler<MouseArg>