Back to top OpenSVG (c) Veridict AB, www.veridict.com
Edit this page

Class SvgDocument

Represents a SVG document.

Inheritance
object
SvgElement
SvgVisual
SvgVisualContainer
SvgDocument
Implements
IXmlSerializable
IEquatable<SvgElement>
ISvgElementContainer
Inherited Members
SvgVisualContainer.ChildElements
SvgVisualContainer.Children()
SvgVisualContainer.Descendants()
SvgVisualContainer.Add(SvgElement)
SvgVisualContainer.AddAll(IEnumerable<SvgElement>)
SvgVisualContainer.AddChildWithAlignment(SvgVisual, HorizontalAlignment, VerticalAlignment)
SvgVisualContainer.ComputeConvexHull()
SvgVisual.fillColor
SvgVisual.strokeColor
SvgVisual.strokeWidth
SvgVisual.transform
SvgVisual.FillColor
SvgVisual.StrokeColor
SvgVisual.StrokeWidth
SvgVisual.Transform
SvgVisual.DrawConfig
SvgVisual.ConvexHull
SvgVisual.BoundingBox
SvgVisual.AlignRelativeTo(SvgVisual, HorizontalAlignment?, VerticalAlignment?)
SvgElement.id
SvgElement.ID
SvgElement.RootDocument
SvgElement.Root
SvgElement.Parent
SvgElement.ViewPort
SvgElement.GetSchema()
SvgElement.WriteXml(XmlWriter)
SvgElement.ReadXml(XmlReader)
SvgElement.ToSvgGroup()
SvgElement.ToSvgDocument()
SvgElement.Attributes()
SvgElement.Equals(object)
SvgElement.Equals(SvgElement)
SvgElement.InformedEquals(SvgElement)
SvgElement.GetHashCode()
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: OpenSvg.SvgNodes
Assembly: OpenSvg.dll
Syntax
public class SvgDocument : SvgVisualContainer, IXmlSerializable, IEquatable<SvgElement>, ISvgElementContainer

Fields

| Edit this page View Source

definedViewPortHeight

Declaration
protected readonly AbsoluteOrRatioAttr definedViewPortHeight
Field Value
Type Description
AbsoluteOrRatioAttr
| Edit this page View Source

definedViewPortWidth

Declaration
protected readonly AbsoluteOrRatioAttr definedViewPortWidth
Field Value
Type Description
AbsoluteOrRatioAttr
| Edit this page View Source

preserveAspectRatio

Declaration
protected readonly PreserveAspectRatioAttr preserveAspectRatio
Field Value
Type Description
PreserveAspectRatioAttr
| Edit this page View Source

viewBox

Declaration
protected readonly ViewBoxAttr viewBox
Field Value
Type Description
ViewBoxAttr

Properties

| Edit this page View Source

DefinedViewPortHeight

Gets or sets the defined view port height of this SvgDocument.

Declaration
public AbsoluteOrRatio DefinedViewPortHeight { get; set; }
Property Value
Type Description
AbsoluteOrRatio
| Edit this page View Source

DefinedViewPortWidth

Gets or sets the defined view port width of this SvgDocument.

Declaration
public AbsoluteOrRatio DefinedViewPortWidth { get; set; }
Property Value
Type Description
AbsoluteOrRatio
| Edit this page View Source

PreserveAspectRatio

Gets or sets the 'preserveAspectRatio' of this SvgDocument.

Declaration
public AspectRatio PreserveAspectRatio { get; set; }
Property Value
Type Description
AspectRatio
| Edit this page View Source

SvgName

Gets or sets the name of the SVG element.

Declaration
public override string SvgName { get; }
Property Value
Type Description
string
Overrides
SvgElement.SvgName
| Edit this page View Source

ViewBox

Gets or sets the view box of this SvgDocument.

Declaration
public BoundingBox ViewBox { get; set; }
Property Value
Type Description
BoundingBox
| Edit this page View Source

ViewPortHeight

Gets the height of the current viewport for the element.

Declaration
public override float ViewPortHeight { get; }
Property Value
Type Description
float
Overrides
SvgElement.ViewPortHeight
| Edit this page View Source

ViewPortWidth

Gets the width of the current viewport for the element.

Declaration
public override float ViewPortWidth { get; }
Property Value
Type Description
float
Overrides
SvgElement.ViewPortWidth

Methods

| Edit this page View Source

EmbedFont(SvgFont)

Embeds a font into the SVG document.

Declaration
public void EmbedFont(SvgFont svgFont)
Parameters
Type Name Description
SvgFont svgFont

The SVG font to embed.

| Edit this page View Source

EmbeddedFont(string)

Gets the embedded font with the specified font name.

Declaration
public SvgFont? EmbeddedFont(string fontName)
Parameters
Type Name Description
string fontName

The name of the font to get.

Returns
Type Description
SvgFont

The embedded font with the specified font name, or null if no such font was found.

| Edit this page View Source

EmbeddedFonts()

Gets the collection of embedded fonts.

Declaration
public IEnumerable<SvgFont> EmbeddedFonts()
Returns
Type Description
IEnumerable<SvgFont>

The collection of embedded fonts.

| Edit this page View Source

FromXDocument(XDocument)

Converts an XDocument to an SVG document.

Declaration
public static SvgDocument FromXDocument(XDocument xDocument)
Parameters
Type Name Description
XDocument xDocument

The XDocument to convert.

Returns
Type Description
SvgDocument

The SVG document representation of the XDocument.

Remarks

This method deserializes the XDocument using an XmlSerializer and returns the resulting SVG document.

| Edit this page View Source

Load(string)

Loads an SVG file from the specified path.

Declaration
public static SvgDocument Load(string svgFilePath)
Parameters
Type Name Description
string svgFilePath

The path to the SVG file to read from.

Returns
Type Description
SvgDocument

The XElement representation of the SVG file.

Remarks

This method supports both uncompressed (.svg) and compressed (.svgz) SVG files.

| Edit this page View Source

Save(string, FileFormat)

Saves the SVG document to a specified file path.

Declaration
public void Save(string svgFilePath, FileFormat fileFormat = FileFormat.Auto)
Parameters
Type Name Description
string svgFilePath

The path to save the SVG document.

FileFormat fileFormat

The file format to save the SVG document in. Default is Auto.

Remarks

This method saves the SVG document to the specified file path using the specified file format

| Edit this page View Source

SetViewBoxToActualSizeAndDefaultViewPort()

Sets the viewBox of the SVG document to the actual size of its bounding box and defines a default viewport size. This method aligns the SVG content to the upper-left corner of the viewport and scales it to fit within the default viewport dimensions, maintaining the aspect ratio.

Declaration
public void SetViewBoxToActualSizeAndDefaultViewPort()
Remarks

This method sets the ViewBox property to the bounding box of the SVG document. It also sets the PreserveAspectRatio to align the content to the upper-left corner ('XMinYMin') and scales it to fit ('Meet') within the default viewport. The default viewport dimensions are defined by DefaultContainerWidth and DefaultContainerHeight, which are set to 1024 and 768 pixels respectively.

See Also
AspectRatio
AspectRatioAlign
AspectRatioMeetOrSlice
| Edit this page View Source

ToXDocument()

Converts the SVG document to an XDocument.

Declaration
public XDocument ToXDocument()
Returns
Type Description
XDocument

The XDocument representation of the SVG document.

Remarks

This method serializes the SVG document using an XmlSerializer and returns the resulting XDocument.

Implements

IXmlSerializable
IEquatable<T>
ISvgElementContainer