SvgClosePathSegment.cs 1.08 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
            var pathData = graphicsPath.PathData;

            if (pathData.Points.Length > 0)
14
            {
15
                // Important for custom line caps.  Force the path the close with an explicit line, not just an implicit close of the figure.
16

17
18
19
20
21
22
23
                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]);
                }
24

25
                graphicsPath.CloseFigure();
Eric Domke's avatar
Eric Domke committed
26
            }
davescriven's avatar
davescriven committed
27
        }
28

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

davescriven's avatar
davescriven committed
34
    }
Eric Domke's avatar
Eric Domke committed
35
}