public EllipseShape(SVG svg, XmlNode node) : base(svg, node) { CX = XmlUtil.AttrValue(node, "cx", 0); CY = XmlUtil.AttrValue(node, "cy", 0); RX = XmlUtil.AttrValue(node, "rx", 0); RY = XmlUtil.AttrValue(node, "ry", 0); }
protected virtual void Parse(SVG svg, ShapeUtil.Attribute attr) { string name = attr.Name; string value = attr.Value; Parse(svg, name, value); }
public Stroke(SVG svg) { Color = new SolidColor(svg.PaintServers, Colors.Black); Width = 1; LineCap = eLineCap.butt; LineJoin = eLineJoin.miter; Opacity = 100; }
public Brush FillBrush(SVG svg) { if (Color != null) { return(Color.GetBrush(Opacity, svg)); } return(null); }
protected Fill GetFill(SVG svg) { if (m_fill == null) { m_fill = new Fill(svg); } return(m_fill); }
protected TextStyle GetTextStyle(SVG svg) { if (m_textstyle == null) { m_textstyle = new TextStyle(svg, this); } return(m_textstyle); }
public override Brush GetBrush(double opacity, SVG svg) { byte a = (byte)(255 * opacity / 100); Color c = Color; Color newcol = System.Windows.Media.Color.FromArgb(a, c.R, c.G, c.B); return(new SolidColorBrush(newcol)); }
Stroke GetStroke(SVG svg) { if (m_stroke == null) { m_stroke = new Stroke(svg); } return(m_stroke); }
public static Element Parse(SVG svg, string text, TextShape owner) { int curpos = 0; Element root = new Element(svg, owner, Element.eElementType.Tag, null); root.Text = "<root>"; root.StartIndex = 0; return(Parse(svg, text, ref curpos, null, root)); }
public LineShape(SVG svg, XmlNode node) : base(svg, node) { double x1 = XmlUtil.AttrValue(node, "x1", 0); double y1 = XmlUtil.AttrValue(node, "y1", 0); double x2 = XmlUtil.AttrValue(node, "x2", 0); double y2 = XmlUtil.AttrValue(node, "y2", 0); P1 = new Point(x1, y1); P2 = new Point(x2, y2); }
public UseShape(SVG svg, XmlNode node) : base(svg, node) { X = XmlUtil.AttrValue(node, "x", 0); Y = XmlUtil.AttrValue(node, "y", 0); hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (hRef.StartsWith("#")) { hRef = hRef.Substring(1); } }
TSpan.Element ParseTSpan(SVG svg, string tspanText) { try { return(TSpan.Parse(svg, tspanText, this)); } catch { return(null); } }
public static double ParseDouble(SVG svg, string svalue) { string units = string.Empty; double value = 0d; if (SplitValueUnits(svalue, out value, out units)) { return(value); } return(0.1); }
public Shape(SVG svg, XmlNode node, Shape parent) : base(node) { Parent = parent; if (node != null) { foreach (XmlAttribute attr in node.Attributes) { Parse(svg, attr); } } }
public Shape(SVG svg, List <ShapeUtil.Attribute> attrs, Shape parent) : base(null) { Parent = parent; if (attrs != null) { foreach (ShapeUtil.Attribute attr in attrs) { Parse(svg, attr); } } }
public void Populate(SVG data) { this.Items.Clear(); foreach (Shape shape in data.Elements) { TreeViewItem root = new TreeViewItem(); root.Header = "root"; this.Items.Add(root); AddShape(shape, root); //this.Items.Add(AddShape(shape, root)); } }
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()); } Points = list.ToArray(); }
static Element Parse(SVG svg, string text, ref int curPos, Element parent, Element curTag) { Element tag = curTag; if (tag == null) { tag = NextTag(svg, parent, text, ref curPos); } while (curPos < text.Length) { int prevPos = curPos; Element next = NextTag(svg, tag, text, ref curPos); if (next == null && curPos < text.Length) { // remaining pure text string s = text.Substring(curPos, text.Length - curPos); tag.Children.Add(new Element(tag, s)); return(tag); } if (next != null && next.StartIndex - prevPos > 0) { // pure text between tspan elements int diff = next.StartIndex - prevPos; string s = text.Substring(prevPos, diff); tag.Children.Add(new Element(tag, s)); } if (next.Text.StartsWith("<tspan")) { // new nested element next = Parse(svg, text, ref curPos, tag, next); tag.Children.Add(next); continue; } if (next.Text.StartsWith("</tspan")) { // end of cur element tag.End = next; return(tag); } if (next.Text.StartsWith("<textPath")) { continue; } if (next.Text.StartsWith("</textPath")) { continue; } throw new Exception(string.Format("unexpected tag '{0}'", next.Text)); } return(tag); }
public RectangleShape(SVG svg, XmlNode node) : base(svg, node) { X = XmlUtil.AttrValue(node, "x", 0); Y = XmlUtil.AttrValue(node, "y", 0); Width = XmlUtil.AttrValue(node, "width", 0); Height = XmlUtil.AttrValue(node, "height", 0); RX = XmlUtil.AttrValue(node, "rx", 0); RY = XmlUtil.AttrValue(node, "ry", 0); if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.Color = svg.PaintServers.Parse("black"); } }
public TextStyle(SVG svg, Shape owner) { FontFamily = "Arial Unicode MS, Verdana"; FontSize = 12; Fontweight = FontWeights.Normal; Fontstyle = FontStyles.Normal; TextAlignment = System.Windows.TextAlignment.Left; WordSpacing = 0; LetterSpacing = 0; BaseLineShift = string.Empty; if (owner.Parent != null) { Copy(owner.Parent.TextStyle); } }
static Element NextTag(SVG svg, Element parent, string text, ref int curPos) { int start = text.IndexOf("<", curPos); if (start < 0) { return(null); } int end = text.IndexOf(">", start + 1); if (end < 0) { throw new Exception("Start '<' with no end '>'"); } end++; string tagtext = text.Substring(start, end - start); if (tagtext.IndexOf("<", 1) > 0) { throw new Exception(string.Format("Start '<' within tag 'tag'")); } List <ShapeUtil.Attribute> attrs = new List <ShapeUtil.Attribute>(); int attrstart = tagtext.IndexOf("tspan"); if (attrstart > 0) { attrstart += 5; while (attrstart < tagtext.Length - 1) { attrs.Add(ShapeUtil.ReadNextAttr(tagtext, ref attrstart)); } } Element tag = new Element(svg, parent, Element.eElementType.Tag, attrs); tag.StartIndex = start; tag.Text = text.Substring(start, end - start); if (tag.Text.IndexOf("<", 1) > 0) { throw new Exception(string.Format("Start '<' within tag 'tag'")); } curPos = end; return(tag); }
public override Brush GetBrush(double opacity, SVG svg) { RadialGradientBrush b = new RadialGradientBrush(); foreach (GradientStop stop in Stops) { b.GradientStops.Add(stop); } b.GradientOrigin = new System.Windows.Point(0.5, 0.5); b.Center = new System.Windows.Point(0.5, 0.5); b.RadiusX = 0.5; b.RadiusY = 0.5; if (GradientUnits == SVGTags.sGradientUserSpace) { b.Center = new System.Windows.Point(CX, CY); b.GradientOrigin = new System.Windows.Point(FX, FY); b.RadiusX = R; b.RadiusY = R; b.MappingMode = BrushMappingMode.Absolute; } else { double scale = 1d / 100d; if (double.IsNaN(CX) == false && double.IsNaN(CY) == false) { b.GradientOrigin = new System.Windows.Point(CX * scale, CY * scale); b.Center = new System.Windows.Point(CX * scale, CY * scale); } if (double.IsNaN(FX) == false && double.IsNaN(FY) == false) { b.GradientOrigin = new System.Windows.Point(FX * scale, FY * scale); } if (double.IsNaN(R) == false) { b.RadiusX = R * scale; b.RadiusY = R * scale; } b.MappingMode = BrushMappingMode.RelativeToBoundingBox; } if (Transform != null) { b.Transform = Transform; } return(b); }
public Group(SVG svg, XmlNode node, Shape parent) : base(svg, node) { // parent on group must be set before children are added this.Parent = parent; foreach (XmlNode childnode in node.ChildNodes) { Shape shape = AddToList(svg, m_elements, childnode, this); if (shape != null) { shape.Parent = this; } } if (Id.Length > 0) { svg.AddShape(Id, this); } }
public override Brush GetBrush(double opacity, SVG svg) { LinearGradientBrush b = new LinearGradientBrush(); foreach (GradientStop stop in Stops) { b.GradientStops.Add(stop); } b.MappingMode = BrushMappingMode.RelativeToBoundingBox; b.StartPoint = new System.Windows.Point(0, 0); b.EndPoint = new System.Windows.Point(1, 0); if (GradientUnits == SVGTags.sGradientUserSpace) { Transform tr = Transform as Transform; if (tr != null) { b.StartPoint = tr.Transform(new System.Windows.Point(X1, Y1)); b.EndPoint = tr.Transform(new System.Windows.Point(X2, Y2)); } else { b.StartPoint = new System.Windows.Point(X1, Y1); b.EndPoint = new System.Windows.Point(X2, Y2); } Transform = null; b.MappingMode = BrushMappingMode.Absolute; } else { Normalize(); if (double.IsNaN(X1) == false) { b.StartPoint = new System.Windows.Point(X1, Y1); } if (double.IsNaN(X2) == false) { b.EndPoint = new System.Windows.Point(X2, Y2); } } return(b); }
static void ReadDefs(SVG svg, List <Shape> list, XmlNode node) { list = new List <Shape>(); // temp list, not needed. //ShapeGroups defined in the 'def' section is added the the 'Shapes' dictionary in SVG for later reference foreach (XmlNode childnode in node.ChildNodes) { if (childnode.Name == SVGTags.sLinearGradient) { svg.PaintServers.Create(childnode); continue; } if (childnode.Name == SVGTags.sRadialGradient) { svg.PaintServers.Create(childnode); continue; } Group.AddToList(svg, list, childnode, null); } }
public PolygonShape(SVG svg, XmlNode node) : base(svg, node) { if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.Color = 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()); } Points = list.ToArray(); }
public ImageShape(SVG svg, XmlNode node) : base(svg, node) { X = XmlUtil.AttrValue(node, "x", 0); Y = XmlUtil.AttrValue(node, "y", 0); Width = XmlUtil.AttrValue(node, "width", 0); Height = XmlUtil.AttrValue(node, "height", 0); string hRef = XmlUtil.AttrValue(node, "xlink:href", string.Empty); if (hRef.Length > 0) { // 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); BitmapImage b = new BitmapImage(); b.BeginInit(); b.UriSource = new Uri(filename, UriKind.RelativeOrAbsolute); b.EndInit(); ImageSource = b; } }
public static List <ShapeUtil.Attribute> SplitStyle(SVG svg, string fullstyle) { List <ShapeUtil.Attribute> list = new List <ShapeUtil.Attribute>(); if (fullstyle.Length == 0) { return(list); } // style contains attributes in format of "attrname:value;attrname:value" string[] attrs = fullstyle.Split(';'); foreach (string attr in attrs) { string[] s = attr.Split(':'); if (s.Length != 2) { continue; } list.Add(new ShapeUtil.Attribute(s[0].Trim(), s[1].Trim())); } return(list); }
public TextShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { X = XmlUtil.AttrValue(node, "x", 0); Y = XmlUtil.AttrValue(node, "y", 0); Text = node.InnerText; GetTextStyle(svg); // check for tSpan tag if (node.InnerXml.IndexOf("<") >= 0) { TextSpan = ParseTSpan(svg, node.InnerXml); } if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.Color = svg.PaintServers.Parse("black"); } if (DefaultStroke == null) { DefaultStroke = new Stroke(svg); DefaultStroke.Width = 0.1; } }
// http://apike.ca/prog_svg_paths.html public PathShape(SVG svg, XmlNode node) : base(svg, node) { if (DefaultFill == null) { DefaultFill = new Fill(svg); DefaultFill.Color = svg.PaintServers.Parse("black"); } ClosePath = false; string path = XmlUtil.AttrValue(node, "d", string.Empty); CommandSplitter cmd = new CommandSplitter(path); string commandstring; char command; List <PathElement> elements = m_elements; while (true) { commandstring = cmd.ReadNext(); if (commandstring.Length == 0) { break; } ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command); if (command == 'm' || command == 'M') { elements.Add(new MoveTo(command, split)); if (split.More) { elements.Add(new LineTo(command, split)); } continue; } if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v') { elements.Add(new LineTo(command, split)); continue; } if (command == 'c' || command == 'C') { while (split.More) { elements.Add(new CurveTo(command, split)); } continue; } if (command == 's' || command == 'S') { while (split.More) { CurveTo lastshape = elements[elements.Count - 1] as CurveTo; System.Diagnostics.Debug.Assert(lastshape != null); elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2)); } continue; } if (command == 'a' || command == 'A') { elements.Add(new EllipticalArcTo(command, split)); while (split.More) { elements.Add(new EllipticalArcTo(command, split)); } continue; } if (command == 'z' || command == 'Z') { ClosePath = true; continue; } // extended format moveto or lineto can contain multiple points which should be translated into lineto PathElement lastitem = elements[elements.Count - 1]; if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo) { //Point p = Point.Parse(s); //elements.Add(new LineTo(p)); continue; } System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring)); } }