Exemplo n.º 1
0
 /// <summary>
 /// text 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Text(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
     foreach (XNode node in element.Nodes())
     {
         this.Read(node, this);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 读取
        /// </summary>
        /// <param name="root">根</param>
        /// <param name="parent">父级</param>
        /// <param name="element">当前元素</param>
        private static void Read(SVG root, SVGElement parent, XElement element)
        {
            string name = element.Name.LocalName.Trim();

            SVGElement svg_element = null;

            switch (name)
            {
            // container elements
            case "clipPath": svg_element = new ClipPath(root, parent, element); break;

            case "defs": svg_element = new Defs(root, parent, element); break;

            case "linearGradient": svg_element = new LinearGradient(root, parent, element); break;

            case "mask": svg_element = new Mask(root, parent, element); break;

            case "radialGradient": svg_element = new RadialGradient(root, parent, element); break;

            // drawing container elements
            case "g": svg_element = new G(root, parent, element); break;

            case "marker": svg_element = new Marker(root, parent, element); break;

            case "use": svg_element = new Use(root, parent, element); break;

            // drawing elements
            case "circle": svg_element = new Circle(root, parent, element); break;

            case "ellipse": svg_element = new Ellipse(root, parent, element); break;

            case "line": svg_element = new Line(root, parent, element); break;

            case "path": svg_element = new Path(root, parent, element); break;

            case "polygon": svg_element = new Polygon(root, parent, element); break;

            case "polyline": svg_element = new Polyline(root, parent, element); break;

            case "rect": svg_element = new Rect(root, parent, element); break;

            case "text": svg_element = new Text(root, parent, element); break;

            // elements
            case "stop": svg_element = new Stop(root, parent, element); break;

            case "symbol": svg_element = new Symbol(root, parent, element); break;

            // default
            default: return;
            }

            parent.Children.Add(svg_element);

            foreach (XElement item in element.Elements())
            {
                Read(root, svg_element, item);
            }
        }
Exemplo n.º 3
0
        // =============================================================================================
        // ================== Other ==================

        /// <summary>
        /// 元素
        /// </summary>
        /// <param name="svg">根元素</param>
        /// <param name="parent">父级元素</param>
        /// <param name="element">当前元素</param>
        public SVGElement(SVG svg, SVGElement parent, XElement element)
        {
            this.SVG     = svg;
            this.Parent  = parent;
            this.Name    = element?.Name;
            this.Element = element;

            this.Init();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 拷贝
        /// </summary>
        /// <returns>拷贝值</returns>
        private SVGElement Clone()
        {
            SVGElement result = this.GetCloneObject();

            foreach (SVGElement item in this.Children)
            {
                result.Children.Add(item.Clone());
            }

            return(result as SVGElement);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 读取节点
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="parent">父级元素</param>
        private void Read(XNode node, SVGElement parent)
        {
            if (node.NodeType == XmlNodeType.Text)
            {
                Tspan span = new Tspan(this.SVG, parent, null);
                span.Node = node;

                this.Children.Add(span);
            }
            else if (node.NodeType == XmlNodeType.Element)
            {
                XElement element = node as XElement;

                Tspan span = new Tspan(this.SVG, parent, element);
                span.Node = node;

                this.Children.Add(span);

                foreach (XNode n in element.Nodes())
                {
                    this.Read(n, span);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// path 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Path(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 7
0
        /// <summary>
        /// 初始化引用
        /// </summary>
        public void InitHref()
        {
            if (this.IsInitedHref)
            {
                return;
            }

            SVGString href = this.GetAttributeValue <SVGString>(SVGNames.href);

            if (href != null && !string.IsNullOrWhiteSpace(href.Value))
            {
                string id = href.Value.Substring(1, href.Value.Length - 1);

                if (this.SVG != null && this.SVG.Resource.ContainsKey(id))
                {
                    SVGElement element = this.SVG.Resource[id];

                    element.InitHref();

                    if (this.Name == SVGNames.use)
                    {
                        SVGElement clone = element.Clone() as SVGElement;
                        clone.Parent = this;

                        this.Children.Add(clone);
                    }
                    else
                    {
                        foreach (var kv in element.AttributePool)
                        {
                            if (kv.Key == SVGNames.id || kv.Key == SVGNames.href)
                            {
                                continue;
                            }

                            if (this.AttributePool.ContainsKey(kv.Key))
                            {
                                continue;
                            }

                            this.AttributePool[kv.Key] = kv.Value;
                        }

                        foreach (SVGElement item in element.Children)
                        {
                            SVGElement clone = item.Clone() as SVGElement;
                            clone.Parent = this;

                            this.Children.Add(clone);
                        }
                    }
                }
            }

            foreach (SVGElement item in this.Children)
            {
                item.InitHref();
            }

            this.IsInitedHref = true;
        }
Exemplo n.º 8
0
 /// <summary>
 /// marker 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Marker(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// ellipse 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Ellipse(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// rect 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Rect(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// defs 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Symbol(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
 /// <summary>
 /// 元素
 /// </summary>
 /// <param name="svg">根元素</param>
 /// <param name="parent">父级元素</param>
 /// <param name="element">当前元素</param>
 public SVGDrawingContainerElement(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// path 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Tspan(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// defs 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Defs(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 /// circle 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Circle(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 16
0
        // =============================================================================================

        /// <summary>
        /// svg 元素
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="parent">父级</param>
        /// <param name="element">当前元素</param>
        public SVG(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
        {
            this.Width  = this.GetAttributeValue <SVGDouble>("width").GetValue();
            this.Height = this.GetAttributeValue <SVGDouble>("height").GetValue();
        }
Exemplo n.º 17
0
 /// <summary>
 /// linearGradient 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public LinearGradient(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// radialGradient 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public RadialGradient(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// polyline 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Polyline(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Exemplo n.º 20
0
 /// <summary>
 /// stop 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Stop(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }