/// <summary> /// 它创建一个新的svg rect元素。 /// </summary> public SVGRect AddRect(SVGUnit parent, ref SVGUnit last) { SVGRect rect = new SVGRect(this); AddElement(parent, rect, ref last); return(rect); }
void ILogicForCommand.load(string filename) { Tuple<List<SVGShape>, int, int> fromfile = SVGIO.import(filename); Figures.clear(); CurientFigures.Clear(); foreach (SVGShape item in fromfile.Item1) { if (item is SVGCircle) { } if (item is SVGEllipse) { } if (item is SVGRect) { SVGRect fig = (SVGRect)item; Interfaces.Point downleft = new Interfaces.Point(fig.rx - fig.width / 2.0, fig.ry - fig.height / 2.0); Interfaces.Point upright = new Interfaces.Point(fig.rx + fig.width / 2.0, fig.ry + fig.height / 2.0); Figures.addNewFigure(new VectorGraphicsEditor.Rectangle(downleft, upright, fig.stroke, fig.fill) } if (item is SVGPolygon) { SVGPolygon fig = (SVGPolygon)item; if (fig.points.Count == 3) { Figures.addNewFigure(new VectorGraphicsEditor.Triangle(fig.points[0], fig.points[1], fig.points[2], fig.stroke, fig.fill)); } else { List<List<Segment>> list = new List<List<Segment>>(); list.Add(PointToSegment(fig.points)); Figures.addNewFigure(new VectorGraphicsEditor.Mutant(list, fig.stroke, fig.fill, 1.0)); } } if (item is SVGPath) { } } }
static void Main(string[] args) { var circle = new SVGCircle(new Point(250.0, 550.0), 20.0, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2 ); var ellipse = new SVGEllipse(new Point(450.0, 550.0), 20.0, 10.0, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2 ); var points = new List <Point>() { new Point(70, 5), new Point(90, 41), new Point(136, 48), new Point(103, 80), new Point(111, 126), new Point(70, 105), new Point(29, 126), new Point(36, 80), new Point(5, 48), new Point(48, 41) }; var pathdata = new List <Point>() { new Point(200, 100), new Point(250, 210), new Point(16, 210) }; var path = new SVGPath(pathdata, new Color(255, 100, 56, 0), new Color(0, 0, 0, 0), 2); var polygon = new SVGPolygon(points, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2); var rect = new SVGRect(50.0, 20.0, 50.0, 20.0, new Color(100, 255, 56, 0), new Color(0, 0, 0, 0), 2); SVGIO.export(new List <SVGShape>() { polygon, ellipse, circle, rect, path }, "Z:\\Sources\\VectorGraphicsEditor\\IO Tests\\output\\mix.svg", 1000, 1001); // SVGIO.import("Z:\\Sources\\VectorGraphicsEditor\\IO Tests\\output\\Freesample.svg"); }
public static List <List <Polygon> > LoadSVGToPolies(string Filename, double xoff, double yoff) { XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Parse; XmlReader reader = XmlReader.Create(Filename, settings); reader.MoveToContent(); // Parse the file and display each of the nodes. SVGGroup RootGroup = new SVGGroup(); SVGGroup CurrentGroup = RootGroup; bool clippath = false; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // Console.WriteLine("<{0}>", reader.Name); switch (reader.Name) { case "circle": { SVGCirc R = new SVGCirc(); var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } R.Setup(reader.GetAttribute("cx"), reader.GetAttribute("cy"), reader.GetAttribute("r")); // < rect x = "336.794" y = "701.551" width = "1.889" height = "56.691" /> if (clippath) { Console.WriteLine("circle ignored for clippath"); } else { CurrentGroup.Children.Add(R); } } break; case "rect": { SVGRect R = new SVGRect(); var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } R.Setup(reader.GetAttribute("x"), reader.GetAttribute("y"), reader.GetAttribute("width"), reader.GetAttribute("height")); // < rect x = "336.794" y = "701.551" width = "1.889" height = "56.691" /> if (clippath) { Console.WriteLine("rect ignored for clippath"); } else { CurrentGroup.Children.Add(R); } } break; case "clipPath": clippath = true; break; case "g": { SVGGroup ng = new SVGGroup(); var T = reader.GetAttribute("transform"); if (T != null) { ng.ParseTransform(T); } else { ng.mTransform.Reset(); } CurrentGroup.Children.Add(ng); ng.Parent = CurrentGroup; CurrentGroup = ng; } break; case "path": { SVGPathCollection R = new SVGPathCollection(); var P = reader.GetAttribute("d"); if (P != null) { R.ParseSVGPath(P); } var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } if (clippath) { } else { CurrentGroup.Children.Add(R); } } break; } break; case XmlNodeType.Text: // Console.WriteLine(reader.Value); break; case XmlNodeType.CDATA: // Console.WriteLine("<![CDATA[{0}]]>", reader.Value); break; case XmlNodeType.ProcessingInstruction: // Console.WriteLine("<?{0} {1}?>", reader.Name, reader.Value); break; case XmlNodeType.Comment: // Console.WriteLine("<!--{0}-->", reader.Value); break; case XmlNodeType.XmlDeclaration: // Console.WriteLine("<?xml version='1.0'?>"); break; case XmlNodeType.Document: break; case XmlNodeType.DocumentType: // Console.WriteLine("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value); break; case XmlNodeType.EntityReference: // Console.WriteLine(reader.Name); break; case XmlNodeType.EndElement: switch (reader.Name) { case "clipPath": clippath = false; break; case "g": if (CurrentGroup.Parent != null) { CurrentGroup = CurrentGroup.Parent; } break; } break; } } Matrix Trans = new Matrix(); Trans.Translate((float)xoff, (float)yoff); RootGroup.Transform(Trans); // RootGroup.Print(0); return(RootGroup.GetPolygons()); }
public SVGRect GetBound() { float cx, cy, r, rx, ry, x, y, width, height; for(int i = 0; i < listObject.Count; i++) switch((SVGPathElementType)listType[i]) { case SVGPathElementType.Polygon: SVGPolygonElement polygonElement = (SVGPolygonElement)listObject[i]; ExpandBounds(polygonElement.listPoints); break; case SVGPathElementType.Polyline: SVGPolylineElement polylineElement = (SVGPolylineElement)listObject[i]; ExpandBounds(polylineElement.listPoints); break; case SVGPathElementType.Rect: SVGRectElement rectElement = (SVGRectElement)listObject[i]; x = rectElement.x.value; y = rectElement.y.value; width = rectElement.width.value; height = rectElement.height.value; ExpandBounds(x, y); ExpandBounds(x + width, y); ExpandBounds(x + width, y + height); ExpandBounds(x, y + height); break; case SVGPathElementType.Circle: SVGCircleElement circleElement = (SVGCircleElement)listObject[i]; cx = circleElement.cx.value; cy = circleElement.cy.value; r = circleElement.r.value; ExpandBounds(cx, cy, r, r); break; case SVGPathElementType.Ellipse: SVGEllipseElement ellipseElement = (SVGEllipseElement)listObject[i]; cx = ellipseElement.cx.value; cy = ellipseElement.cy.value; rx = ellipseElement.rx.value; ry = ellipseElement.ry.value; ExpandBounds(cx, cy, rx, ry); break; //----- case SVGPathElementType.CircleTo: SVGGCircle circle = (SVGGCircle)listObject[i]; r = circle.r; ExpandBounds(circle.point, r, r); break; //----- case SVGPathElementType.EllipseTo: SVGGEllipse ellipse = (SVGGEllipse)listObject[i]; ExpandBounds(ellipse.point, ellipse.r1, ellipse.r2); break; //----- case SVGPathElementType.MoveTo: SVGPoint pointMoveTo = (SVGPoint)listObject[i]; ExpandBounds(pointMoveTo); break; //----- case SVGPathElementType.ArcTo: SVGGArcAbs gArcAbs = (SVGGArcAbs)listObject[i]; r = (int)gArcAbs.r1 + (int)gArcAbs.r2; ExpandBounds(gArcAbs.point, r, r); break; //----- case SVGPathElementType.CubicCurveTo: SVGGCubicAbs gCubicAbs = (SVGGCubicAbs)listObject[i]; ExpandBounds(gCubicAbs.p1); ExpandBounds(gCubicAbs.p2); ExpandBounds(gCubicAbs.p); break; //----- case SVGPathElementType.QuadraticCurveTo: SVGGQuadraticAbs gQuadraticAbs = (SVGGQuadraticAbs)listObject[i]; ExpandBounds(gQuadraticAbs.p1); ExpandBounds(gQuadraticAbs.p); break; //----- case SVGPathElementType.LineTo: ExpandBounds((SVGPoint)listObject[i]); break; } SVGRect tmp = new SVGRect(boundUL.x - 1, boundUL.y - 1, boundBR.x - boundUL.x + 2, boundBR.y - boundUL.y + 2); return tmp; }
public void CreateSVGDependencyGraph(DependencyGraph graph) { SVG svg = new SVG(this.Document, SVGNameSpace, "1.1"); this.BodyElement.AppendChild((svg as ISVGElement).Element); SVGDefinitions definitions = new SVGDefinitions(svg); System.Collections.Generic.Dictionary <DependencyNode, SVGGroup> nodeToSVGGroup = new System.Collections.Generic.Dictionary <DependencyNode, SVGGroup>(); int rankCount = graph.RankCount; int numVerticalSlots = 2 * rankCount + 1; float verticalStride = 100 / numVerticalSlots; int y = (int)verticalStride;; for (int i = rankCount - 1; i >= 0; --i) { DependencyNodeCollection rank = graph[i]; int nodeCount = rank.Count; int numHorizontalSlots = 2 * nodeCount + 1; float horizontalStride = 100 / numHorizontalSlots; int x = (int)horizontalStride; System.Text.StringBuilder rankIdName = new System.Text.StringBuilder(); rankIdName.AppendFormat("Rank{0}", rank.Rank); SVGGroup rankGroup = new SVGGroup(svg, rankIdName.ToString()); SVGAttributes.Fill(rankGroup, "red"); SVGText rankText = new SVGText(rankGroup, rankIdName.ToString(), 0, y, 100, (int)verticalStride, "%"); SVGAttributes.Fill(rankText, "black"); foreach (DependencyNode node in rank) { SVGGroup nodeGroup = new SVGGroup(rankGroup, node.UniqueModuleName); SVGRect nodeRect = new SVGRect(nodeGroup, x, y, (int)horizontalStride, (int)verticalStride, "%"); SVGText nodeText = new SVGText(nodeGroup, node.UniqueModuleName, x, y + (int)verticalStride / 2, (int)horizontalStride, (int)verticalStride, "%"); SVGAttributes.Fill(nodeText, "black"); nodeToSVGGroup.Add(node, nodeGroup); x += (int)(2 * horizontalStride); } y += (int)(verticalStride * 2); } SVGArrow arrow = new SVGArrow(svg, 0, 0, 100, 100, ""); SVGAttributes.Stroke(arrow, "black"); SVGAttributes.StrokeWidth(arrow, 5); #if false System.Xml.XmlElement circle = this.Document.CreateElement("circle"); System.Xml.XmlAttribute cx = this.Document.CreateAttribute("cx"); cx.Value = "100"; System.Xml.XmlAttribute cy = this.Document.CreateAttribute("cy"); cy.Value = "50"; System.Xml.XmlAttribute r = this.Document.CreateAttribute("r"); r.Value = "40"; circle.Attributes.Append(cx); circle.Attributes.Append(cy); circle.Attributes.Append(r); svgElement.AppendChild(circle); #endif }
/***********************************************************************************/ private void SetViewBox() { string attr = this._attrList.GetValue("viewBox"); if(attr != "") { string[] _temp = SVGStringExtractor.ExtractTransformValue(attr); if(_temp.Length == 4) { float x = SVGNumber.ParseToFloat(_temp[0]); float y = SVGNumber.ParseToFloat(_temp[1]); float w = SVGNumber.ParseToFloat(_temp[2]); float h = SVGNumber.ParseToFloat(_temp[3]); this._viewport = new SVGRect(x, y, w, h); } } }