Example #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);
     }
 }
Example #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);
            }
        }
Example #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();
        }
Example #4
0
        /// <summary>
        /// 读取SVG文件
        /// </summary>
        /// <param name="stream">文件流</param>
        /// <returns>SVG元素</returns>
        public static SVG Read(System.IO.Stream stream)
        {
            XElement element = XElement.Load(stream);

            SVG svg = new SVG(null, null, element);

            foreach (XElement item in element.Elements())
            {
                Read(svg, svg, item);
            }

            svg.InitHref();

            return(svg);
        }
Example #5
0
        /// <summary>
        /// 尝试从url中获取剪切路径
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="value">剪切路径值</param>
        /// <returns>画刷</returns>
        private Geometry Get_URL(SVG svg, string value)
        {
            value = value.Replace(" ", "").Replace("\t", "");
            value = value.Replace("url(#", "").Replace(")", "");

            if (!svg.Resource.ContainsKey(value))
            {
                return(null);
            }

            ISVGClipPath clip_path = svg.Resource[value] as ISVGClipPath;

            if (clip_path == null || clip_path.Value == null)
            {
                return(null);
            }

            return(clip_path.Value.Clone());
        }
Example #6
0
        /// <summary>
        /// 尝试从url中获取画刷
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="value">颜色</param>
        /// <returns>画刷</returns>
        private DrawingBrush Get_URL(SVG svg, string value)
        {
            value = value.Replace(" ", "").Replace("\t", "");
            value = value.Replace("url(#", "").Replace(")", "");

            if (!svg.Resource.ContainsKey(value))
            {
                return(null);
            }

            ISVGMask mask = svg.Resource[value] as ISVGMask;

            if (mask == null || mask.Value == null)
            {
                return(null);
            }

            return(mask.Value.Clone());
        }
        /// <summary>
        /// 尝试从url中获取画刷
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="value">颜色</param>
        /// <returns>画刷</returns>
        private Brush Get_URL(SVG svg, string value)
        {
            value = value.Replace(" ", "").Replace("\t", "");
            value = value.Replace("url(#", "").Replace(")", "");

            if (!svg.Resource.ContainsKey(value))
            {
                return(null);
            }

            ISVGBrush brush = svg.Resource[value] as ISVGBrush;

            if (brush == null || brush.Value == null)
            {
                return(null);
            }

            return(brush.Value.Clone());
        }
Example #8
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)
 {
 }
Example #9
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)
 {
 }
Example #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)
 {
 }
 /// <summary>
 /// 元素
 /// </summary>
 /// <param name="svg">根元素</param>
 /// <param name="parent">父级元素</param>
 /// <param name="element">当前元素</param>
 public SVGDrawingElement(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Example #12
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)
 {
 }
Example #13
0
 /// <summary>
 /// polygon 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Polygon(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Example #14
0
 /// <summary>
 /// clipPath 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public ClipPath(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Example #15
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)
 {
 }
Example #16
0
 /// <summary>
 /// line 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Line(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Example #17
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)
 {
 }
Example #18
0
 /// <summary>
 /// SVG属性
 /// </summary>
 /// <param name="svg">根元素</param>
 /// <param name="name">属性名</param>
 /// <param name="value">属性值</param>
 public SVGAttribute(SVG svg, XName name, string value)
 {
     this.SVG   = svg;
     this.Name  = name;
     this.Value = value;
 }
Example #19
0
 /// <summary>
 /// marsk 元素
 /// </summary>
 /// <param name="svg">SVG</param>
 /// <param name="parent">父级</param>
 /// <param name="element">当前元素</param>
 public Mask(SVG svg, SVGElement parent, XElement element) : base(svg, parent, element)
 {
 }
Example #20
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)
 {
 }
Example #21
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();
        }
Example #22
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)
 {
 }
Example #23
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)
 {
 }