SvgPolyline.cs 1.68 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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    public class SvgPolyline : SvgPolygon
    {
        public override GraphicsPath Path
        {
            get
            {
                if (this._path == null || this.IsPathDirty)
                {
                    this._path = new GraphicsPath();

                    try
                    {
                        for (int i = 0; i < this._points.Count; i += 2)
                        {
                            PointF endPoint = new PointF(this._points[i].ToDeviceValue(this), this._points[i + 1].ToDeviceValue(this));

                            // TODO: Remove unrequired first line
                            if (_path.PointCount == 0)
                            {
                                _path.AddLine(endPoint, endPoint);
                            }
                            else
                            {
                                _path.AddLine(_path.GetLastPoint(), endPoint);
                            }
                        }
                    }
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
47
48
49
50
51
                    }
                    this.IsPathDirty = false;
                }
                return this._path;
            }
        }
    }
}