Class SvgElement
Represents the base class for all SVG elements.
Inherited Members
Namespace: OpenSvg.SvgNodes
Assembly: OpenSvg.dll
Syntax
public abstract class SvgElement : IXmlSerializable, IEquatable<SvgElement>
Fields
| Edit this page View Sourceid
Declaration
protected readonly StringAttr id
Field Value
Type | Description |
---|---|
StringAttr |
Properties
| Edit this page View SourceID
Gets or sets the ID of the element.
Declaration
public string ID { get; set; }
Property Value
Type | Description |
---|---|
string |
Parent
Gets or sets the parent element of the element.
Declaration
public SvgElement? Parent { get; set; }
Property Value
Type | Description |
---|---|
SvgElement |
Root
Gets the root element of the element.
Declaration
public SvgElement Root { get; }
Property Value
Type | Description |
---|---|
SvgElement |
RootDocument
Gets the root document of the element.
Declaration
public SvgDocument RootDocument { get; }
Property Value
Type | Description |
---|---|
SvgDocument |
SvgName
Gets or sets the name of the SVG element.
Declaration
public abstract string SvgName { get; }
Property Value
Type | Description |
---|---|
string |
ViewPort
Gets the current viewport for the element.
Declaration
public Size ViewPort { get; }
Property Value
Type | Description |
---|---|
Size | The absolute value for the viewport size, width and height. |
Remarks
- If the element is not an SvgDocument, the viewport will be equal to its closest SvgDocument ancestor.
-
If the closest SvgDocument ancestor has a relative defined size (e.g.,
40%
), the viewport will be calculated by traversing upwards, accumulating ratios until an ancestor with an absolute size is found. - If an SvgDocument has no size set, it is equivalent to having a ratio of 1 (
100%
). - If no topmost SvgDocument exists, or the topmost SvgDocument has a ratio or no size set, a default container size is assumed
See Also
| Edit this page View SourceViewPortHeight
Gets the height of the current viewport for the element.
Declaration
public virtual float ViewPortHeight { get; }
Property Value
Type | Description |
---|---|
float |
ViewPortWidth
Gets the width of the current viewport for the element.
Declaration
public virtual float ViewPortWidth { get; }
Property Value
Type | Description |
---|---|
float |
Methods
| Edit this page View SourceAttributes()
Gets the attributes of the element.
Declaration
public IEnumerable<IAttr> Attributes()
Returns
Type | Description |
---|---|
IEnumerable<IAttr> | The attributes of the element. |
Equals(SvgElement?)
Determines whether the specified object is equal to the current object.
Declaration
public bool Equals(SvgElement? other)
Parameters
Type | Name | Description |
---|---|---|
SvgElement | other | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Equals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Returns a hash code for the current object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
| Edit this page View SourceGetSchema()
Gets the schema for the element. Required by interface IXmlSerializable.
Declaration
public XmlSchema? GetSchema()
Returns
Type | Description |
---|---|
XmlSchema |
|
InformedEquals(SvgElement?)
Verbose comparison of two SvgElements, including all attributes and child elements.
Declaration
public (bool equal, string diffMessage) InformedEquals(SvgElement? other)
Parameters
Type | Name | Description |
---|---|---|
SvgElement | other | The object to compare with the current object. |
Returns
Type | Description |
---|---|
(bool IsEqual, string ErrorMessage) | A tuple containing a boolean indicating whether the specified object is equal to the current object and a message describing the differences. |
ReadXml(XmlReader)
Reads the XML representation of the element from the specified reader.
Declaration
public void ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader | The reader from which the element is read. |
ToSvgDocument()
Encapsulates the current SvgElement in an SvgDocument if it is not already a SvgDocument.
Declaration
public SvgDocument ToSvgDocument()
Returns
Type | Description |
---|---|
SvgDocument | A new instance of SvgDocument containing this instance as a child, or this instance if it already is a SvgDocument. |
ToSvgGroup()
Encapsulates the current SvgElement in an SvgGroup if it is not already a SvgGroup.
Declaration
public SvgGroup ToSvgGroup()
Returns
Type | Description |
---|---|
SvgGroup | A new instance of SvgGroup containing this instance as a child, or this instance if it already is a SvgGroup. |
WriteXml(XmlWriter)
Writes the XML representation of the element to the specified writer.
Declaration
public void WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer | The writer to which the element is written. |
Operators
| Edit this page View Sourceoperator ==(SvgElement, SvgElement)
Declaration
public static bool operator ==(SvgElement left, SvgElement right)
Parameters
Type | Name | Description |
---|---|---|
SvgElement | left | |
SvgElement | right |
Returns
Type | Description |
---|---|
bool |
operator !=(SvgElement, SvgElement)
Declaration
public static bool operator !=(SvgElement left, SvgElement right)
Parameters
Type | Name | Description |
---|---|---|
SvgElement | left | |
SvgElement | right |
Returns
Type | Description |
---|---|
bool |