// THIS FILE IS PART OF SVG PROJECT
// THE SVG PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MS-PL License.
// COPYRIGHT (C) svg-net. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/svg-net/SVG
using AntdUI.Svg.Pathing;
using System.Drawing.Drawing2D;
namespace AntdUI.Svg
{
///
/// Represents an SVG path element.
///
public class SvgPath : SvgMarkerElement
{
public override string ClassName { get => "path"; }
private GraphicsPath _path;
///
/// Gets or sets a of path data.
///
[SvgAttribute("d", true)]
public SvgPathSegmentList PathData
{
get { return Attributes.GetAttribute("d"); }
set
{
Attributes["d"] = value;
value._owner = this;
IsPathDirty = true;
}
}
///
/// Gets or sets the length of the path.
///
[SvgAttribute("pathLength", true)]
public float PathLength
{
get { return Attributes.GetAttribute("pathLength"); }
set { Attributes["pathLength"] = value; }
}
///
/// Gets the for this element.
///
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (_path == null || IsPathDirty)
{
_path = new GraphicsPath();
foreach (var segment in PathData)
{
segment.AddToPath(_path);
}
if (_path.PointCount == 0)
{
if (PathData.Count > 0)
{
// special case with one move command only, see #223
var segment = PathData.Last;
_path.AddLine(segment.End, segment.End);
Fill = SvgPaintServer.None;
}
else
{
_path = null;
}
}
IsPathDirty = false;
}
return _path;
}
internal void OnPathUpdated()
{
IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs { Attribute = "d", Value = Attributes.GetAttribute("d") });
}
///
/// Gets the bounds of the element.
///
/// The bounds.
public override System.Drawing.RectangleF Bounds
{
get { return Path(null).GetBounds(); }
}
///
/// Initializes a new instance of the class.
///
public SvgPath()
{
var pathData = new SvgPathSegmentList();
Attributes["d"] = pathData;
pathData._owner = this;
}
}
}