SvgPolyline.cs 1.64 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;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Diagnostics;

namespace Svg
{
    /// <summary>
11
    /// SvgPolyline defines a set of connected straight line segments. Typically, <see cref="SvgPolyline"/> defines open shapes.
davescriven's avatar
davescriven committed
12
    /// </summary>
13
    [SvgElement("polyline")]
davescriven's avatar
davescriven committed
14
15
16
17
18
19
    public class SvgPolyline : SvgPolygon
    {
        public override GraphicsPath Path
        {
            get
            {
20
                if (Path == null || this.IsPathDirty)
davescriven's avatar
davescriven committed
21
                {
22
                    Path = new GraphicsPath();
davescriven's avatar
davescriven committed
23
24
25

                    try
                    {
26
                        for (int i = 0; i < Points.Count; i += 2)
davescriven's avatar
davescriven committed
27
                        {
28
                            PointF endPoint = new PointF(Points[i].ToDeviceValue(this), Points[i + 1].ToDeviceValue(this));
davescriven's avatar
davescriven committed
29
30

                            // TODO: Remove unrequired first line
31
                            if (Path.PointCount == 0)
davescriven's avatar
davescriven committed
32
                            {
33
                                Path.AddLine(endPoint, endPoint);
davescriven's avatar
davescriven committed
34
35
36
                            }
                            else
                            {
37
                                Path.AddLine(Path.GetLastPoint(), endPoint);
davescriven's avatar
davescriven committed
38
39
40
                            }
                        }
                    }
41
                    catch (Exception exc)
davescriven's avatar
davescriven committed
42
                    {
43
                        Trace.TraceError("Error rendering points: " + exc.Message);
davescriven's avatar
davescriven committed
44
45
46
                    }
                    this.IsPathDirty = false;
                }
47
                return Path;
davescriven's avatar
davescriven committed
48
49
50
51
            }
        }
    }
}