SvgForeignObject.cs 2.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Svg
{
    /// <summary>
    /// The foreignObject element allows for inclusion of a foreign namespace which has its graphical content drawn by a different user agent
    /// </summary>
    [SvgElement("foreignObject")]
    public class SvgForeignObject : SvgVisualElement
    {
        public SvgForeignObject()
        {
        }

        /// <summary>
        /// Gets the <see cref="GraphicsPath"/> for this element.
        /// </summary>
        /// <value></value>
Eric Domke's avatar
Eric Domke committed
20
        public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
21
        {
22
            return GetPaths(this, renderer);
23
24
25
26
27
        }

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

55
                return TransformedBounds(r);
Tebjan Halm's avatar
Tebjan Halm committed
56
            }
57
58
        }

Eric Domke's avatar
Eric Domke committed
59
        protected override bool Renderable { get { return false; } }
60

Eric Domke's avatar
Eric Domke committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        ///// <summary>
        ///// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
        ///// </summary>
        ///// <param name="renderer">The <see cref="Graphics"/> object to render to.</param>
        //protected override void Render(SvgRenderer renderer)
        //{
        //    if (!Visible || !Displayable)
        //        return;

        //    this.PushTransforms(renderer);
        //    this.SetClip(renderer);
        //    base.RenderChildren(renderer);
        //    this.ResetClip(renderer);
        //    this.PopTransforms(renderer);
        //}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

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

        public override SvgElement DeepCopy<T>()
        {
            var newObj = base.DeepCopy<T>() as SvgForeignObject;
            if (this.Fill != null)
                newObj.Fill = this.Fill.DeepCopy() as SvgPaintServer;
            return newObj;
        }
    }
}