SvgClosePathSegment.cs 1.09 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
5
6
7
8
9
10
using System;
using System.Collections.Generic;
using System.Text;

namespace Svg.Pathing
{
    public sealed class SvgClosePathSegment : SvgPathSegment
    {
        public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
        {
11
12
13
14
15
            if (graphicsPath.PointCount == 0)
            {
                return;
            }

Eric Domke's avatar
Eric Domke committed
16
            // Important for custom line caps.  Force the path the close with an explicit line, not just an implicit close of the figure.
17
18
            var pathPoints = graphicsPath.PathPoints;

19
            if (!pathPoints[0].Equals(pathPoints[pathPoints.Length - 1]))
Eric Domke's avatar
Eric Domke committed
20
            {
21
22
23
                var pathTypes = graphicsPath.PathTypes;
                int i = pathPoints.Length - 1;
                while (i >= 0 && pathTypes[i] > 0) i--;
Eric Domke's avatar
Eric Domke committed
24
                if (i < 0) i = 0;
25
                graphicsPath.AddLine(pathPoints[pathPoints.Length - 1], pathPoints[i]);
Eric Domke's avatar
Eric Domke committed
26
            }
27

davescriven's avatar
davescriven committed
28
29
            graphicsPath.CloseFigure();
        }
30

Tebjan Halm's avatar
Tebjan Halm committed
31
        public override string ToString()
32
33
34
        {
            return "z";
        }
Tebjan Halm's avatar
Tebjan Halm committed
35

davescriven's avatar
davescriven committed
36
    }
Eric Domke's avatar
Eric Domke committed
37
}