SvgGroup.cs 2.24 KB
Newer Older
1
using System.Drawing;
Tebjan Halm's avatar
Tebjan Halm committed
2
using System.Drawing.Drawing2D;
davescriven's avatar
davescriven committed
3
4
5

namespace Svg
{
6
7
8
    /// <summary>
    /// An element used to group SVG shapes.
    /// </summary>
9
    [SvgElement("g")]
10
    public class SvgGroup : SvgVisualElement
davescriven's avatar
davescriven committed
11
    {
12
13
14
15
        /// <summary>
        /// Gets the <see cref="GraphicsPath"/> for this element.
        /// </summary>
        /// <value></value>
Eric Domke's avatar
Eric Domke committed
16
        public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
davescriven's avatar
davescriven committed
17
        {
18
            return GetPaths(this, renderer);
davescriven's avatar
davescriven committed
19
20
        }

21
22
23
        /// <summary>
        /// Gets the bounds of the element.
        /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
24
25
        /// <value>The bounds.</value>
        public override System.Drawing.RectangleF Bounds
davescriven's avatar
davescriven committed
26
        {
Tebjan Halm's avatar
Tebjan Halm committed
27
28
29
30
            get 
            { 
                var r = new RectangleF();
                foreach(var c in this.Children)
James Welle's avatar
James Welle committed
31
                {
Tebjan Halm's avatar
Tebjan Halm committed
32
                    if (c is SvgVisualElement)
HarkDev's avatar
HarkDev committed
33
                    {
Tebjan Halm's avatar
Tebjan Halm committed
34
35
36
37
38
39
40
                        // 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
James Welle's avatar
James Welle committed
41
                        {
Tebjan Halm's avatar
Tebjan Halm committed
42
43
44
45
46
                            var childBounds = ((SvgVisualElement)c).Bounds;
                            if (!childBounds.IsEmpty)
                            {
                                r = RectangleF.Union(r, childBounds);
                            }
James Welle's avatar
James Welle committed
47
                        }
HarkDev's avatar
HarkDev committed
48
                    }
James Welle's avatar
James Welle committed
49
                }
50
                return TransformedBounds(r);
Tebjan Halm's avatar
Tebjan Halm committed
51
            }
davescriven's avatar
davescriven committed
52
53
        }

Eric Domke's avatar
Eric Domke committed
54
        protected override bool Renderable { get { return false; } }
Eric Domke's avatar
Eric Domke committed
55
                
James Welle's avatar
James Welle committed
56
57
58
59
        public override SvgElement DeepCopy()
        {
            return DeepCopy<SvgGroup>();
        }
60

James Welle's avatar
James Welle committed
61
62
63
64
65
66
67
        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
68
    }
HarkDev's avatar
HarkDev committed
69
}