using System.Drawing.Drawing2D;
using Svg.Pathing;
namespace Svg
{
///
/// Represents an SVG path element.
///
[SvgElement("path")]
public class SvgPath : SvgMarkerElement
{
private GraphicsPath _path;
///
/// Gets or sets a of path data.
///
[SvgAttribute("d", true)]
public SvgPathSegmentList PathData
{
get { return this.Attributes.GetAttribute("d"); }
set
{
this.Attributes["d"] = value;
value._owner = this;
this.IsPathDirty = true;
}
}
///
/// Gets or sets the length of the path.
///
[SvgAttribute("pathLength", true)]
public float PathLength
{
get { return this.Attributes.GetAttribute("pathLength"); }
set { this.Attributes["pathLength"] = value; }
}
///
/// Gets the for this element.
///
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (this._path == null || this.IsPathDirty)
{
_path = new GraphicsPath();
foreach (SvgPathSegment segment in this.PathData)
{
segment.AddToPath(_path);
}
this.IsPathDirty = false;
}
return _path;
}
internal void OnPathUpdated()
{
this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs{ Attribute = "d", Value = this.Attributes.GetAttribute("d") });
}
///
/// Gets the bounds of the element.
///
/// The bounds.
public override System.Drawing.RectangleF Bounds
{
get { return this.Path(null).GetBounds(); }
}
///
/// Initializes a new instance of the class.
///
public SvgPath()
{
var pathData = new SvgPathSegmentList();
this.Attributes["d"] = pathData;
pathData._owner = this;
}
public override SvgElement DeepCopy()
{
return DeepCopy();
}
public override SvgElement DeepCopy()
{
var newObj = base.DeepCopy() as SvgPath;
foreach (var pathData in this.PathData)
newObj.PathData.Add(pathData.Clone());
newObj.PathLength = this.PathLength;
newObj.MarkerStart = this.MarkerStart;
newObj.MarkerEnd = this.MarkerEnd;
return newObj;
}
}
}