SvgGroup.cs 2.63 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
5
using System.Drawing;
Tebjan Halm's avatar
Tebjan Halm committed
6
using System.Drawing.Drawing2D;
7
8
using System.Linq;
using Svg.Transforms;
davescriven's avatar
davescriven committed
9
10
11

namespace Svg
{
12
13
14
    /// <summary>
    /// An element used to group SVG shapes.
    /// </summary>
15
    [SvgElement("g")]
16
    public class SvgGroup : SvgVisualElement
davescriven's avatar
davescriven committed
17
18
19
20
21
    {
        public SvgGroup()
        {
        }

22
23
24
25
        /// <summary>
        /// Gets the <see cref="GraphicsPath"/> for this element.
        /// </summary>
        /// <value></value>
davescriven's avatar
davescriven committed
26
27
        public override System.Drawing.Drawing2D.GraphicsPath Path
        {
Tebjan Halm's avatar
Tebjan Halm committed
28
29
            get 
            { 
30
            	//var path = new GraphicsPath();
Tebjan Halm's avatar
Tebjan Halm committed
31
            	//AddPaths(this, path);
Tebjan Halm's avatar
Tebjan Halm committed
32
  
Tebjan Halm's avatar
Tebjan Halm committed
33
            	return GetPaths(this);
Tebjan Halm's avatar
Tebjan Halm committed
34
            }
35
36
            protected set
            { }
davescriven's avatar
davescriven committed
37
38
        }

39
40
41
42
        /// <summary>
        /// Gets the bounds of the element.
        /// </summary>
        /// <value>The bounds.</value>
davescriven's avatar
davescriven committed
43
44
        public override System.Drawing.RectangleF Bounds
        {
Tebjan Halm's avatar
Tebjan Halm committed
45
46
47
48
49
            get 
            { 
            	var r = new RectangleF();
            	foreach(var c in this.Children)
            	{
HarkDev's avatar
HarkDev committed
50
51
52
53
54
55
56
57
58
                    if (c is SvgVisualElement)
                    {
                    	// First it should check if rectangle is empty or it will return the wrong Bounds.
                    	// This is because when the Rectangle is Empty, the Union method adds as if the first values where X=0, Y=0
                        if (r.IsEmpty)
                            r = ((SvgVisualElement)c).Bounds;
                        else
                            r = RectangleF.Union(r, ((SvgVisualElement)c).Bounds);
                    }
Tebjan Halm's avatar
Tebjan Halm committed
59
            	}
HarkDev's avatar
HarkDev committed
60
61
            	
            	return r;
Tebjan Halm's avatar
Tebjan Halm committed
62
            }
davescriven's avatar
davescriven committed
63
64
        }

65
66
67
68
        /// <summary>
        /// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
        /// </summary>
        /// <param name="graphics">The <see cref="Graphics"/> object to render to.</param>
69
        protected override void Render(SvgRenderer renderer)
davescriven's avatar
davescriven committed
70
        {
71
            this.PushTransforms(renderer);
72
            this.SetClip(renderer);
73
            base.RenderChildren(renderer);
74
            this.ResetClip(renderer);
75
            this.PopTransforms(renderer);
davescriven's avatar
davescriven committed
76
        }
77
78
79
80
81
82
83
84
85
86
87
88
89
90

		
		public override SvgElement DeepCopy()
		{
			return DeepCopy<SvgGroup>();
		}

		public override SvgElement DeepCopy<T>()
		{
			var newObj = base.DeepCopy<T>() as SvgGroup;
			if (this.Fill != null)
				newObj.Fill = this.Fill.DeepCopy() as SvgPaintServer;
			return newObj;
		}
davescriven's avatar
davescriven committed
91
    }
HarkDev's avatar
HarkDev committed
92
}