/// <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); } }
/// <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); } }
// ============================================================================================= // ================== 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(); }
/// <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); }
/// <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()); }
/// <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()); }
/// <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> /// 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) { }
/// <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) { }
/// <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) { }
/// <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) { }
/// <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) { }
/// <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) { }
/// <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; }
/// <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) { }
/// <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) { }
/// <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> /// 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> /// 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) { }
// ============================================================================================= /// <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(); }
/// <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) { }
/// <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) { }