public Shape(SVG svg, List<ShapeUtil.Attribute> attrs, Shape parent) : base(null) { this.Parent = parent; if (attrs != null) { foreach (ShapeUtil.Attribute attr in attrs) this.Parse(svg, attr); } }
public Shape(SVG svg, XmlNode node, Shape parent) : base(node) { this.Parent = parent; if (node != null) { foreach (XmlAttribute attr in node.Attributes) this.Parse(svg, attr); } }
private Geometry getGeoForShape(Shape shp) { if (shp is RectangleShape) { var r = shp as RectangleShape; return new RectangleGeometry(new Rect(r.RX, r.RY, r.Width, r.Height)); } if (shp is CircleShape) { var c = shp as CircleShape; return new EllipseGeometry(new Point(c.CX, c.CY), c.R, c.R); } return null; }
public TextShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { this.X = XmlUtil.AttrValue(node, "x", 0); this.Y = XmlUtil.AttrValue(node, "y", 0); this.Text = node.InnerText; this.GetTextStyle(svg); // check for tSpan tag if (node.InnerXml.IndexOf("<") >= 0) this.TextSpan = this.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; } }
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; } if (this.Id.Length > 0) svg.AddShape(this.Id, this); }
public Clip(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { }
public static Shape AddToList(SVG svg, List<Shape> list, XmlNode childnode, Shape parent) { if (childnode.NodeType != XmlNodeType.Element) return null; if (childnode.Name == SVGTags.sShapeRect) { list.Add(new RectangleShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapeCircle) { list.Add(new CircleShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapeEllipse) { list.Add(new EllipseShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapeLine) { list.Add(new LineShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapePolyline) { list.Add(new PolylineShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapePolygon) { list.Add(new PolygonShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapePath) { list.Add(new PathShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sClipPath) { list.Add(new Clip(svg, childnode, parent)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapeGroup || childnode.Name == SVGTags.sSwitch) { list.Add(new Group(svg, childnode, parent)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sLinearGradient) { svg.PaintServers.Create(childnode); return null; } if (childnode.Name == SVGTags.sRadialGradient) { svg.PaintServers.Create(childnode); return null; } if (childnode.Name == SVGTags.sDefinitions) { ReadDefs(svg, list, childnode); return null; } if (childnode.Name == SVGTags.sShapeUse) { list.Add(new UseShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sShapeImage) { list.Add(new ImageShape(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == SVGTags.sAnimateTransform) { list.Add(new AnimateTransform(svg, childnode)); return list[list.Count - 1]; } if (childnode.Name == "text") { list.Add(new TextShape(svg, childnode, parent)); return list[list.Count - 1]; } return null; }
private Shape AddChild(Shape shape) { this.m_elements.Add(shape); shape.Parent = this; return shape; }
public Element(SVG svg, Shape parent, eElementType eType, List<ShapeUtil.Attribute> attrs) : base(svg, attrs, parent) { this.ElementType = eType; this.Text = string.Empty; this.Children = new List<Element>(); }
public Element(Shape parent, string text) : base(null, (XmlNode)null, parent) { this.ElementType = eElementType.Text; this.Text = text; }
public DrawingGroup CreateDrawing(Shape shape) { return this.LoadGroup(new Shape[] { shape }, null); }
private GeometryDrawing NewDrawingItem(Shape shape, Geometry geometry) { GeometryDrawing item = new GeometryDrawing(); Stroke stroke = shape.Stroke; if (stroke != null) { item.Pen = new Pen(stroke.StrokeBrush(this.SVG), stroke.Width); if (stroke.StrokeArray != null) { item.Pen.DashCap = PenLineCap.Flat; DashStyle ds = new DashStyle(); double scale = 1 / stroke.Width; foreach (int dash in stroke.StrokeArray) ds.Dashes.Add(dash * scale); item.Pen.DashStyle = ds; } switch (stroke.LineCap) { case Stroke.eLineCap.butt: item.Pen.StartLineCap = PenLineCap.Flat; item.Pen.EndLineCap = PenLineCap.Flat; break; case Stroke.eLineCap.round: item.Pen.StartLineCap = PenLineCap.Round; item.Pen.EndLineCap = PenLineCap.Round; break; case Stroke.eLineCap.square: item.Pen.StartLineCap = PenLineCap.Square; item.Pen.EndLineCap = PenLineCap.Square; break; } switch (stroke.LineJoin) { case Stroke.eLineJoin.round: item.Pen.LineJoin = PenLineJoin.Round; break; case Stroke.eLineJoin.miter: item.Pen.LineJoin = PenLineJoin.Miter; break; case Stroke.eLineJoin.bevel: item.Pen.LineJoin = PenLineJoin.Bevel; break; } } if (shape.Fill != null) { item.Brush = shape.Fill.FillBrush(this.SVG); GeometryGroup g = new GeometryGroup(); g.FillRule = FillRule.Nonzero; if (shape.Fill.FillRule == Fill.eFillRule.evenodd) g.FillRule = FillRule.EvenOdd; g.Children.Add(geometry); geometry = g; } if (shape.Transform != null) geometry.Transform = shape.Transform; // for debugging, if neither stroke or fill is set then set default pen //if (shape.Fill == null && shape.Stroke == null) // item.Pen = new Pen(Brushes.Blue, 1); item.Geometry = geometry; return item; }
public void AddShape(string id, Shape shape) { System.Diagnostics.Debug.Assert(id.Length > 0 && this.m_shapes.ContainsKey(id) == false); this.m_shapes[id] = shape; }