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
    public class SvgPolyline : SvgPolygon
    {
16
        private GraphicsPath _Path;
davescriven's avatar
davescriven committed
17
18
19
20
        public override GraphicsPath Path
        {
            get
            {
21
                if (_Path == null || this.IsPathDirty)
davescriven's avatar
davescriven committed
22
                {
23
                    _Path = new GraphicsPath();
davescriven's avatar
davescriven committed
24
25
26

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

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