public CircleShape(SVG svg, XmlNode node) : base(svg, node) { this.CX = XmlUtil.AttrValue(node, "cx", 0); this.CY = XmlUtil.AttrValue(node, "cy", 0); this.R = XmlUtil.AttrValue(node, "r", 0); }
public ImageShape(SVG svg, XmlNode node) : base(svg, node) { this.X = XmlUtil.AttrValue(node, "x", 0, svg.Size.Width); this.Y = XmlUtil.AttrValue(node, "y", 0, svg.Size.Height); this.Width = XmlUtil.AttrValue(node, "width", 0, svg.Size.Width); this.Height = XmlUtil.AttrValue(node, "height", 0, svg.Size.Height); string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (hRef.Length > 0) { try { BitmapImage b = new BitmapImage(); b.BeginInit(); if (hRef.StartsWith("data:image/png;base64")) { b.StreamSource = new MemoryStream(Convert.FromBase64String(hRef.Substring("data:image/png;base64,".Length))); } else { if (svg.ExternalFileLoader != null) { b.StreamSource = svg.ExternalFileLoader.LoadFile(hRef, svg.Filename); } } b.EndInit(); this.ImageSource = b; } catch (Exception ex) { } } }
public Group(SVG svg, XmlNode node, Shape parent) : base(svg, node) { // parent on group must be set before children are added var clp = XmlUtil.AttrValue(node, "clip-path", null); if (!string.IsNullOrEmpty(clp)) { Shape result; string id = ShapeUtil.ExtractBetween(clp, '(', ')'); if (id.Length > 0 && id[0] == '#') { id = id.Substring(1); } svg.m_shapes.TryGetValue(id, out result); this.m_clip = result as Clip; } this.Parent = parent; foreach (XmlNode childnode in node.ChildNodes) { Shape shape = AddToList(svg, this.m_elements, childnode, this); if (shape != null) { shape.Parent = this; } } }
public string Create(SVG svg, XmlNode node) { if (node.Name == SVGTags.sLinearGradient) { string id = XmlUtil.AttrValue(node, "id"); if (this.m_servers.ContainsKey(id) == false) { this.m_servers[id] = new LinearGradientColorPaintServerPaintServer(this, node); } return(id); } if (node.Name == SVGTags.sRadialGradient) { string id = XmlUtil.AttrValue(node, "id"); if (this.m_servers.ContainsKey(id) == false) { this.m_servers[id] = new RadialGradientColorPaintServerPaintServer(this, node); } return(id); } if (node.Name == SVGTags.sPattern) { string id = XmlUtil.AttrValue(node, "id"); if (this.m_servers.ContainsKey(id) == false) { this.m_servers[id] = new PatternPaintServer(this, svg, node); } return(id); } return(null); }
public ImageShape(SVG svg, XmlNode node) : base(svg, node) { this.X = XmlUtil.AttrValue(node, "x", 0); this.Y = XmlUtil.AttrValue(node, "y", 0); this.Width = XmlUtil.AttrValue(node, "width", 0); this.Height = XmlUtil.AttrValue(node, "height", 0); string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (hRef.Length > 0) { BitmapImage b = new BitmapImage(); b.BeginInit(); if (hRef.StartsWith("data:image/png;base64")) { b.StreamSource = new System.IO.MemoryStream(Convert.FromBase64String(hRef.Substring("data:image/png;base64,".Length))); } else { // filename given must be relative to the location of the svg file string svgpath = System.IO.Path.GetDirectoryName(svg.Filename); string filename = System.IO.Path.Combine(svgpath, hRef); b.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute); } b.EndInit(); this.ImageSource = b; } }
public EllipseShape(SVG svg, XmlNode node) : base(svg, node) { this.CX = XmlUtil.AttrValue(node, "cx", 0); this.CY = XmlUtil.AttrValue(node, "cy", 0); this.RX = XmlUtil.AttrValue(node, "rx", 0); this.RY = XmlUtil.AttrValue(node, "ry", 0); }
public LinearGradientColorPaintServerPaintServer(PaintServerManager owner, XmlNode node) : base(owner, node) { System.Diagnostics.Debug.Assert(node.Name == SVGTags.sLinearGradient); this.X1 = XmlUtil.AttrValue(node, "x1", double.NaN); this.Y1 = XmlUtil.AttrValue(node, "y1", double.NaN); this.X2 = XmlUtil.AttrValue(node, "x2", double.NaN); this.Y2 = XmlUtil.AttrValue(node, "y2", double.NaN); }
public AnimateTransform(global::SVGImage.SVG.SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { this.Type = (AnimateTransformType)Enum.Parse(typeof(AnimateTransformType), XmlUtil.AttrValue(node, "type", "translate"), true); this.From = XmlUtil.AttrValue(node, "from", null); this.To = XmlUtil.AttrValue(node, "to", null); this.AttributeName = XmlUtil.AttrValue(node, "attributeName", null); this.RepeatType = XmlUtil.AttrValue(node, "repeatCount", "indefinite"); this.Values = XmlUtil.AttrValue(node, "values", null); }
public LineShape(SVG svg, XmlNode node) : base(svg, node) { double x1 = XmlUtil.AttrValue(node, "x1", 0, svg.Size.Width); double y1 = XmlUtil.AttrValue(node, "y1", 0, svg.Size.Height); double x2 = XmlUtil.AttrValue(node, "x2", 0, svg.Size.Width); double y2 = XmlUtil.AttrValue(node, "y2", 0, svg.Size.Height); this.P1 = new Point(x1, y1); this.P2 = new Point(x2, y2); }
public UseShape(SVG svg, XmlNode node) : base(svg, node) { this.X = XmlUtil.AttrValue(node, "x", 0); this.Y = XmlUtil.AttrValue(node, "y", 0); this.hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (this.hRef.StartsWith("#")) { this.hRef = this.hRef.Substring(1); } }
public RadialGradientColorPaintServerPaintServer(PaintServerManager owner, XmlNode node) : base(owner, node) { System.Diagnostics.Debug.Assert(node.Name == SVGTags.sRadialGradient); this.CX = XmlUtil.AttrValue(node, "cx", double.NaN); this.CY = XmlUtil.AttrValue(node, "cy", double.NaN); this.FX = XmlUtil.AttrValue(node, "fx", double.NaN); this.FY = XmlUtil.AttrValue(node, "fy", double.NaN); this.R = XmlUtil.AttrValue(node, "r", double.NaN); this.Normalize(); }
public CircleShape(SVG svg, XmlNode node) : base(svg, node) { this.CX = XmlUtil.AttrValue(node, "cx", 0, svg.ViewBox.HasValue ? svg.ViewBox.Value.Width : svg.Size.Width); this.CY = XmlUtil.AttrValue(node, "cy", 0, svg.ViewBox.HasValue ? svg.ViewBox.Value.Height : svg.Size.Height); var diagRef = Math.Sqrt(svg.Size.Width * svg.Size.Width + svg.Size.Height * svg.Size.Height) / Math.Sqrt(2); // see https://oreillymedia.github.io/Using_SVG/extras/ch05-percentages.html if (svg.ViewBox.HasValue) { diagRef = Math.Sqrt(svg.ViewBox.Value.Width * svg.ViewBox.Value.Width + svg.ViewBox.Value.Height * svg.ViewBox.Value.Height) / Math.Sqrt(2); } this.R = XmlUtil.AttrValue(node, "r", 0, diagRef); }
public EllipseShape(SVG svg, XmlNode node) : base(svg, node) { this.CX = XmlUtil.AttrValue(node, "cx", 0, svg.ViewBox.HasValue ? svg.ViewBox.Value.Width : svg.Size.Width); this.CY = XmlUtil.AttrValue(node, "cy", 0, svg.ViewBox.HasValue ? svg.ViewBox.Value.Height : svg.Size.Height); var diagRef = Math.Sqrt(svg.Size.Width * svg.Size.Width + svg.Size.Height * svg.Size.Height) / Math.Sqrt(2); if (svg.ViewBox.HasValue) { diagRef = Math.Sqrt(svg.ViewBox.Value.Width * svg.ViewBox.Value.Width + svg.ViewBox.Value.Height * svg.ViewBox.Value.Height) / Math.Sqrt(2); } this.RX = XmlUtil.AttrValue(node, "rx", 0, diagRef); this.RY = XmlUtil.AttrValue(node, "ry", 0, diagRef); }
public PolylineShape(SVG svg, XmlNode node) : base(svg, node) { string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty); ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points); List <Point> list = new List <Point>(); while (split.More) { list.Add(split.ReadNextPoint()); } this.Points = list.ToArray(); }
public Animate(global::SVGImage.SVG.SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { this.From = XmlUtil.AttrValue(node, "from", null); this.To = XmlUtil.AttrValue(node, "to", null); this.AttributeName = XmlUtil.AttrValue(node, "attributeName", null); this.RepeatType = XmlUtil.AttrValue(node, "repeatCount", "indefinite"); this.Values = XmlUtil.AttrValue(node, "values", null); this.hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (this.hRef.StartsWith("#")) { this.hRef = this.hRef.Substring(1); } }
public PatternPaintServer(PaintServerManager owner, SVG svg, XmlNode node) : base(owner) { this.PatternUnits = XmlUtil.AttrValue(node, "patternUnits", string.Empty); string transform = XmlUtil.AttrValue(node, "patternTransform", string.Empty); if (transform.Length > 0) { this.PatternTransform = ShapeUtil.ParseTransform(transform.ToLower()); } m_elements = SVG.Parse(new SVG(), node); this.X = XmlUtil.AttrValue(node, "x", 0, svg.Size.Width); this.Y = XmlUtil.AttrValue(node, "y", 0, svg.Size.Height); this.Width = XmlUtil.AttrValue(node, "width", 1, svg.Size.Width); this.Height = XmlUtil.AttrValue(node, "height", 1, svg.Size.Height); }
public RectangleShape(SVG svg, XmlNode node) : base(svg, node) { this.X = XmlUtil.AttrValue(node, "x", 0); this.Y = XmlUtil.AttrValue(node, "y", 0); this.Width = XmlUtil.AttrValue(node, "width", 0); this.Height = XmlUtil.AttrValue(node, "height", 0); this.RX = XmlUtil.AttrValue(node, "rx", 0); this.RY = XmlUtil.AttrValue(node, "ry", 0); if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.Color = svg.PaintServers.Parse("black"); } }
public AnimationBase(global::SVGImage.SVG.SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { var d = XmlUtil.AttrValue(node, "dur", ""); if (d.EndsWith("ms")) { Duration = TimeSpan.FromMilliseconds(double.Parse(d.Substring(0, d.Length - 2))); } else if (d.EndsWith("s")) { Duration = TimeSpan.FromSeconds(double.Parse(d.Substring(0, d.Length - 1))); } else { Duration = TimeSpan.FromSeconds(double.Parse(d)); } }
public ImageShape(SVG svg, XmlNode node) : base(svg, node) { this.X = XmlUtil.AttrValue(node, "x", 0, svg.Size.Width); this.Y = XmlUtil.AttrValue(node, "y", 0, svg.Size.Height); this.Width = XmlUtil.AttrValue(node, "width", 0, svg.Size.Width); this.Height = XmlUtil.AttrValue(node, "height", 0, svg.Size.Height); string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (hRef.Length > 0) { try { Stream imageStream = null; if (hRef.StartsWith("data:image/png;base64", StringComparison.OrdinalIgnoreCase)) { var embeddedImage = hRef.Substring("data:image/png;base64,".Length); if (!string.IsNullOrWhiteSpace(embeddedImage)) { imageStream = new MemoryStream(Convert.FromBase64String(embeddedImage)); } } else { if (svg.ExternalFileLoader != null) { imageStream = svg.ExternalFileLoader.LoadFile(hRef, svg.Filename); } } if (imageStream != null) { BitmapImage b = new BitmapImage(); b.BeginInit(); b.StreamSource = imageStream; b.EndInit(); this.ImageSource = b; } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } } }
public PolygonShape(SVG svg, XmlNode node) : base(svg, node) { if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.PaintServerKey = svg.PaintServers.Parse("black"); } string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty); ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points); List <Point> list = new List <Point>(); while (split.More) { list.Add(split.ReadNextPoint()); } this.Points = list.ToArray(); }
public FilterFeGaussianBlur(global::SVGImage.SVG.SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { StdDeviationX = StdDeviationY = XmlUtil.AttrValue(node, "stdDeviation", 0); }
protected virtual void Parse(SVG svg, string name, string value) { if (name == SVGTags.sTransform) { this.Transform = ShapeUtil.ParseTransform(value.ToLower()); return; } if (name == SVGTags.sStroke) { this.GetStroke(svg).Color = svg.PaintServers.Parse(value); return; } if (name == SVGTags.sStrokeWidth) { this.GetStroke(svg).Width = XmlUtil.ParseDouble(svg, value); return; } if (name == SVGTags.sStrokeOpacity) { this.GetStroke(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100; return; } if (name == SVGTags.sStrokeDashArray) { if (value == "none") { this.GetStroke(svg).StrokeArray = null; return; } ShapeUtil.StringSplitter sp = new ShapeUtil.StringSplitter(value); List <double> a = new List <double>(); while (sp.More) { a.Add(sp.ReadNextValue()); } this.GetStroke(svg).StrokeArray = a.ToArray(); return; } if (name == SVGTags.sStrokeLinecap) { this.GetStroke(svg).LineCap = (Stroke.eLineCap)Enum.Parse(typeof(Stroke.eLineCap), value); return; } if (name == SVGTags.sStrokeLinejoin) { this.GetStroke(svg).LineJoin = (Stroke.eLineJoin)Enum.Parse(typeof(Stroke.eLineJoin), value); return; } if (name == SVGTags.sClipPath) { if (value.StartsWith("url")) { Shape result; string id = ShapeUtil.ExtractBetween(value, '(', ')'); if (id.Length > 0 && id[0] == '#') { id = id.Substring(1); } svg.m_shapes.TryGetValue(id, out result); this.m_clip = result as Clip; return; } return; } if (name == SVGTags.sFill) { this.GetFill(svg).Color = svg.PaintServers.Parse(value); return; } if (name == SVGTags.sFillOpacity) { this.GetFill(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100; return; } if (name == SVGTags.sFillRule) { this.GetFill(svg).FillRule = (Fill.eFillRule)Enum.Parse(typeof(Fill.eFillRule), value); return; } if (name == SVGTags.sStyle) { foreach (ShapeUtil.Attribute item in XmlUtil.SplitStyle(svg, value)) { this.Parse(svg, item); } } //********************** text ******************* if (name == SVGTags.sFontFamily) { this.GetTextStyle(svg).FontFamily = value; return; } if (name == SVGTags.sFontSize) { this.GetTextStyle(svg).FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value)); return; } if (name == SVGTags.sFontWeight) { this.GetTextStyle(svg).Fontweight = (FontWeight) new FontWeightConverter().ConvertFromString(value); return; } if (name == SVGTags.sFontStyle) { this.GetTextStyle(svg).Fontstyle = (FontStyle) new FontStyleConverter().ConvertFromString(value); return; } if (name == SVGTags.sTextDecoration) { TextDecoration t = new TextDecoration(); if (value == "none") { return; } if (value == "underline") { t.Location = TextDecorationLocation.Underline; } if (value == "overline") { t.Location = TextDecorationLocation.OverLine; } if (value == "line-through") { t.Location = TextDecorationLocation.Strikethrough; } TextDecorationCollection tt = new TextDecorationCollection(); tt.Add(t); this.GetTextStyle(svg).TextDecoration = tt; return; } if (name == SVGTags.sTextAnchor) { if (value == "start") { this.GetTextStyle(svg).TextAlignment = TextAlignment.Left; } if (value == "middle") { this.GetTextStyle(svg).TextAlignment = TextAlignment.Center; } if (value == "end") { this.GetTextStyle(svg).TextAlignment = TextAlignment.Right; } return; } if (name == "word-spacing") { this.GetTextStyle(svg).WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value)); return; } if (name == "letter-spacing") { this.GetTextStyle(svg).LetterSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value)); return; } if (name == "baseline-shift") { //GetTextStyle(svg).BaseLineShift = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value)); this.GetTextStyle(svg).BaseLineShift = value; return; } }
public GradientColorPaintServer(PaintServerManager owner, XmlNode node) : base(owner) { this.GradientUnits = XmlUtil.AttrValue(node, "gradientUnits", string.Empty); string transform = XmlUtil.AttrValue(node, "gradientTransform", string.Empty); if (transform.Length > 0) { this.Transform = ShapeUtil.ParseTransform(transform.ToLower()); } if (node.ChildNodes.Count == 0 && XmlUtil.AttrValue(node, "xlink:href", string.Empty).Length > 0) { string refid = XmlUtil.AttrValue(node, "xlink:href", string.Empty); GradientColorPaintServer refcol = owner.Parse(refid.Substring(1)) as GradientColorPaintServer; if (refcol == null) { return; } this.m_stops = new List <GradientStop>(refcol.m_stops); } foreach (XmlNode childnode in node.ChildNodes) { if (childnode.Name == "stop") { var styleattr = new List <XmlUtil.StyleItem>(); string fullstyle = XmlUtil.AttrValue(childnode, SVGTags.sStyle, string.Empty); if (fullstyle.Length > 0) { foreach (ShapeUtil.Attribute styleitem in XmlUtil.SplitStyle(null, fullstyle)) { styleattr.Add(new XmlUtil.StyleItem(styleitem.Name, styleitem.Value)); } } foreach (var attr1 in styleattr) { childnode.Attributes.Append(new TempXmlAttribute(childnode, attr1.Name, attr1.Value)); } double offset = XmlUtil.AttrValue(childnode, "offset", (double)0); string s = XmlUtil.AttrValue(childnode, "stop-color", "#0"); double stopopacity = XmlUtil.AttrValue(childnode, "stop-opacity", (double)1); Color color; if (s.StartsWith("#")) { color = PaintServerManager.ParseHexColor(s); } else { color = PaintServerManager.KnownColor(s); } if (stopopacity != 1) { color = Color.FromArgb((byte)(stopopacity * 255), color.R, color.G, color.B); } if (offset > 1) { offset = offset / 100; } this.m_stops.Add(new GradientStop(color, offset)); } } }