diff --git a/Source/Paths/SvgClosePathSegment.cs b/Source/Paths/SvgClosePathSegment.cs index 8ad928ae7b23af791602c22356b4bdd97f1279bc..f8aa8b0b1a3c655a58fa90ce67572da4143609aa 100644 --- a/Source/Paths/SvgClosePathSegment.cs +++ b/Source/Paths/SvgClosePathSegment.cs @@ -8,24 +8,22 @@ namespace Svg.Pathing { public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath) { - if (graphicsPath.PointCount == 0) + var pathData = graphicsPath.PathData; + + if (pathData.Points.Length > 0) { - return; - } + // Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure. - // Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure. - var pathPoints = graphicsPath.PathPoints; + if (!pathData.Points[0].Equals(pathData.Points[pathData.Points.Length - 1])) + { + int i = pathData.Points.Length - 1; + while (i >= 0 && pathData.Types[i] > 0) i--; + if (i < 0) i = 0; + graphicsPath.AddLine(pathData.Points[pathData.Points.Length - 1], pathData.Points[i]); + } - if (!pathPoints[0].Equals(pathPoints[pathPoints.Length - 1])) - { - var pathTypes = graphicsPath.PathTypes; - int i = pathPoints.Length - 1; - while (i >= 0 && pathTypes[i] > 0) i--; - if (i < 0) i = 0; - graphicsPath.AddLine(pathPoints[pathPoints.Length - 1], pathPoints[i]); + graphicsPath.CloseFigure(); } - - graphicsPath.CloseFigure(); } public override string ToString()