using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Drawing.Drawing2D; using System.Drawing; using System.ComponentModel; namespace Svg { /// /// An represents an SVG fragment that can be the root element or an embedded fragment of an SVG document. /// [SvgElement("svg")] public class SvgFragment : SvgElement, ISvgViewPort { /// /// Gets the SVG namespace string. /// public static readonly Uri Namespace = new Uri("http://www.w3.org/2000/svg"); /// /// Gets or sets the width of the fragment. /// /// The width. [SvgAttribute("width")] public SvgUnit Width { get { return this.Attributes.GetAttribute("width"); } set { this.Attributes["width"] = value; } } /// /// Gets or sets the height of the fragment. /// /// The height. [SvgAttribute("height")] public SvgUnit Height { get { return this.Attributes.GetAttribute("height"); } set { this.Attributes["height"] = value; } } [SvgAttribute("overflow")] public virtual SvgOverflow Overflow { get { return this.Attributes.GetAttribute("overflow"); } set { this.Attributes["overflow"] = value; } } /// /// Gets or sets the viewport of the element. /// /// [SvgAttribute("viewBox")] public SvgViewBox ViewBox { get { return this.Attributes.GetAttribute("viewBox"); } set { this.Attributes["viewBox"] = value; } } /// /// Gets or sets the aspect of the viewport. /// /// [SvgAttribute("preserveAspectRatio")] public SvgAspectRatio AspectRatio { get {return this.Attributes.GetAttribute("preserveAspectRatio"); } set { this.Attributes["preserveAspectRatio"] = value; } } /// /// Applies the required transforms to . /// /// The to be transformed. protected internal override void PushTransforms(SvgRenderer renderer) { base.PushTransforms(renderer); if (!this.ViewBox.Equals(SvgViewBox.Empty)) { renderer.TranslateTransform(-this.ViewBox.MinX, -this.ViewBox.MinY, MatrixOrder.Append); renderer.ScaleTransform(this.Width.ToDeviceValue() / this.ViewBox.Width, this.Height.ToDeviceValue() / this.ViewBox.Height, MatrixOrder.Append); } } /// /// Gets the for this element. /// /// public GraphicsPath Path { get { var path = new GraphicsPath(); AddPaths(this, path); return path; } } /// /// Gets the bounds of the svg element. /// /// The bounds. public RectangleF Bounds { get { return this.Path.GetBounds(); } } /// /// Initializes a new instance of the class. /// public SvgFragment() { this.Height = new SvgUnit(SvgUnitType.Percentage, 100.0f); this.Width = new SvgUnit(SvgUnitType.Percentage, 100.0f); this.ViewBox = SvgViewBox.Empty; this.AspectRatio = new SvgAspectRatio(SvgPreserveAspectRatio.None); } public override SvgElement DeepCopy() { return DeepCopy(); } public override SvgElement DeepCopy() { var newObj = base.DeepCopy() as SvgFragment; newObj.Height = this.Height; newObj.Width = this.Width; newObj.Overflow = this.Overflow; newObj.ViewBox = this.ViewBox; newObj.AspectRatio = this.AspectRatio; return newObj; } } }