SvgClosePathSegment.cs 1.01 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)
        {
Eric Domke's avatar
Eric Domke committed
11
            // Important for custom line caps.  Force the path the close with an explicit line, not just an implicit close of the figure.
12
13
14
            var pathPoints = graphicsPath.PathPoints;

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

davescriven's avatar
davescriven committed
23
24
            graphicsPath.CloseFigure();
        }
25

Tebjan Halm's avatar
Tebjan Halm committed
26
        public override string ToString()
27
28
29
        {
            return "z";
        }
Tebjan Halm's avatar
Tebjan Halm committed
30

davescriven's avatar
davescriven committed
31
    }
Eric Domke's avatar
Eric Domke committed
32
}