SvgGroup.cs 2.52 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
26
27
28
        /// <summary>
        /// Gets or sets the fill.
        /// </summary>
        /// <value>The fill.</value>
        [SvgAttribute("fill")]
        public override SvgPaintServer Fill
        {
29
            get { return (this.Attributes["Fill"] == null) ? null : (SvgPaintServer)this.Attributes["Fill"]; }
30
31
32
33
34
35
36
            set { this.Attributes["Fill"] = value; }
        }

        /// <summary>
        /// Gets the <see cref="GraphicsPath"/> for this element.
        /// </summary>
        /// <value></value>
davescriven's avatar
davescriven committed
37
38
        public override System.Drawing.Drawing2D.GraphicsPath Path
        {
Tebjan Halm's avatar
Tebjan Halm committed
39
40
41
42
            get 
            { 
            	var path = new GraphicsPath();

Tebjan Halm's avatar
Tebjan Halm committed
43
            	//AddPaths(this, path);
Tebjan Halm's avatar
Tebjan Halm committed
44
  
Tebjan Halm's avatar
Tebjan Halm committed
45
            	return GetPaths(this);
Tebjan Halm's avatar
Tebjan Halm committed
46
            }
davescriven's avatar
davescriven committed
47
48
        }

49
50
51
52
        /// <summary>
        /// Gets the bounds of the element.
        /// </summary>
        /// <value>The bounds.</value>
davescriven's avatar
davescriven committed
53
54
        public override System.Drawing.RectangleF Bounds
        {
Tebjan Halm's avatar
Tebjan Halm committed
55
56
57
58
59
60
61
62
63
64
            get 
            { 
            	var r = new RectangleF();
            	foreach(var c in this.Children)
            	{
            		if(c is SvgVisualElement)
            			r = RectangleF.Union(r, ((SvgVisualElement)c).Bounds);
            	}
				return r;         	
            }
davescriven's avatar
davescriven committed
65
66
        }

67
68
69
70
        /// <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>
71
        protected override void Render(SvgRenderer renderer)
davescriven's avatar
davescriven committed
72
        {
73
            this.PushTransforms(renderer);
74
            this.SetClip(renderer);
75
            base.RenderChildren(renderer);
76
            this.ResetClip(renderer);
77
            this.PopTransforms(renderer);
davescriven's avatar
davescriven committed
78
        }
79
80
81
82
83
84
85
86
87
88
89
90
91
92

		
		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
93
94
    }
}