Class SvgDocument
Represents a SVG document.
Inherited Members
Namespace: OpenSvg.SvgNodes
Assembly: OpenSvg.dll
Syntax
public class SvgDocument : SvgVisualContainer, IXmlSerializable, IEquatable<SvgElement>, ISvgElementContainer
Fields
| Edit this page View SourcedefinedViewPortHeight
Declaration
protected readonly AbsoluteOrRatioAttr definedViewPortHeight
Field Value
Type | Description |
---|---|
AbsoluteOrRatioAttr |
definedViewPortWidth
Declaration
protected readonly AbsoluteOrRatioAttr definedViewPortWidth
Field Value
Type | Description |
---|---|
AbsoluteOrRatioAttr |
preserveAspectRatio
Declaration
protected readonly PreserveAspectRatioAttr preserveAspectRatio
Field Value
Type | Description |
---|---|
PreserveAspectRatioAttr |
viewBox
Declaration
protected readonly ViewBoxAttr viewBox
Field Value
Type | Description |
---|---|
ViewBoxAttr |
Properties
| Edit this page View SourceDefinedViewPortHeight
Gets or sets the defined view port height of this SvgDocument.
Declaration
public AbsoluteOrRatio DefinedViewPortHeight { get; set; }
Property Value
Type | Description |
---|---|
AbsoluteOrRatio |
DefinedViewPortWidth
Gets or sets the defined view port width of this SvgDocument.
Declaration
public AbsoluteOrRatio DefinedViewPortWidth { get; set; }
Property Value
Type | Description |
---|---|
AbsoluteOrRatio |
PreserveAspectRatio
Gets or sets the 'preserveAspectRatio' of this SvgDocument.
Declaration
public AspectRatio PreserveAspectRatio { get; set; }
Property Value
Type | Description |
---|---|
AspectRatio |
SvgName
Gets or sets the name of the SVG element.
Declaration
public override string SvgName { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceViewBox
Gets or sets the view box of this SvgDocument.
Declaration
public BoundingBox ViewBox { get; set; }
Property Value
Type | Description |
---|---|
BoundingBox |
ViewPortHeight
Gets the height of the current viewport for the element.
Declaration
public override float ViewPortHeight { get; }
Property Value
Type | Description |
---|---|
float |
Overrides
| Edit this page View SourceViewPortWidth
Gets the width of the current viewport for the element.
Declaration
public override float ViewPortWidth { get; }
Property Value
Type | Description |
---|---|
float |
Overrides
Methods
| Edit this page View SourceEmbedFont(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. |
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 |
EmbeddedFonts()
Gets the collection of embedded fonts.
Declaration
public IEnumerable<SvgFont> EmbeddedFonts()
Returns
Type | Description |
---|---|
IEnumerable<SvgFont> | The collection of embedded fonts. |
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.
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.
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
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
| Edit this page View SourceToXDocument()
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.