SvgPolyline.cs 1.69 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;
Eric Domke's avatar
Eric Domke committed
17
        public override GraphicsPath Path(ISvgRenderer renderer)
davescriven's avatar
davescriven committed
18
        {
19
            if (_Path == null || this.IsPathDirty)
davescriven's avatar
davescriven committed
20
            {
21
                _Path = new GraphicsPath();
davescriven's avatar
davescriven committed
22

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

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