Skip to content

Commit

Permalink
Prevent crashes on zero length segments or paths
Browse files Browse the repository at this point in the history
- fixes __tiger.svg test image
  • Loading branch information
mrbean-bremen committed Mar 11, 2017
1 parent f918193 commit ac31614
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Source/Paths/SvgClosePathSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ public sealed class SvgClosePathSegment : SvgPathSegment
{
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
{
if (graphicsPath.PointCount == 0)
{
return;
}

// 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 (pathPoints.Length > 0 && !pathPoints[0].Equals(pathPoints[pathPoints.Length - 1]))
if (!pathPoints[0].Equals(pathPoints[pathPoints.Length - 1]))
{
var pathTypes = graphicsPath.PathTypes;
int i = pathPoints.Length - 1;
Expand Down
5 changes: 4 additions & 1 deletion Source/Paths/SvgLineSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public SvgLineSegment(PointF start, PointF end)

public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
{
graphicsPath.AddLine(this.Start, this.End);
if (this.Start != this.End)
{
graphicsPath.AddLine(this.Start, this.End);
}
}

public override string ToString()
Expand Down
5 changes: 4 additions & 1 deletion Source/Paths/SvgMoveToSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public SvgMoveToSegment(PointF moveTo)

public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
{
graphicsPath.StartFigure();
if (this.Start != this.End)
{
graphicsPath.StartFigure();
}
}

public override string ToString()
Expand Down

0 comments on commit ac31614

Please sign in to comment.