SvgUse.cs 2.19 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
5
6
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
7
using System.Drawing.Drawing2D;
davescriven's avatar
davescriven committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21

namespace Svg
{
    public class SvgUse : SvgGraphicsElement
    {
        private Uri _referencedElement;

        [SvgAttribute("href")]
        public virtual Uri ReferencedElement
        {
            get { return this._referencedElement; }
            set { this._referencedElement = value; }
        }

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        [SvgAttribute("x")]
        public virtual SvgUnit X
        {
            get { return this.Attributes.GetAttribute<SvgUnit>("x"); }
            set { this.Attributes["x"] = value; }
        }

        [SvgAttribute("y")]
        public virtual SvgUnit Y
        {
            get { return this.Attributes.GetAttribute<SvgUnit>("y"); }
            set { this.Attributes["y"] = value; }
        }

        protected internal override void PushTransforms(System.Drawing.Graphics graphics)
        {
            base.PushTransforms(graphics);
            graphics.TranslateTransform(this.X.ToDeviceValue(this), this.Y.ToDeviceValue(this, true));
        }

davescriven's avatar
davescriven committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        public SvgUse()
        {
            
        }

        public override System.Drawing.Drawing2D.GraphicsPath Path
        {
            get { return null; }
        }

        public override System.Drawing.RectangleF Bounds
        {
            get { return new System.Drawing.RectangleF(); }
        }

        protected override string  ElementName
        {
            get { return "use"; }
        }

        protected override void Render(System.Drawing.Graphics graphics)
        {
            this.PushTransforms(graphics);

            SvgGraphicsElement element = (SvgGraphicsElement)this.OwnerDocument.IdManager.GetElementById(this.ReferencedElement);
            // For the time of rendering we want the referenced element to inherit
            // this elements transforms
            SvgElement parent = element._parent;
            element._parent = this;
            element.RenderElement(graphics);
            element._parent = parent;

            this.PopTransforms(graphics);
        }
    }
}