public void WriteToFile(string filenameAndPath, SvgWrapper source) { document = new System.IO.StreamWriter(filenameAndPath); WriteXmlHeader(); source.WriteToFile(writeStartTag, endTagWithContent); document.Close(); }
public SvgWrapper Parse() { Console.WriteLine("start parsing document..."); try { var svgWrapper = new SvgWrapper(); var doc = new XmlDocument(); doc.Load(Path); //Console.WriteLine(doc.DocumentElement.Name); foreach (XmlAttribute attribute in doc.DocumentElement.Attributes) // root node { if (attribute.Name == "viewbox") { svgWrapper.Attributes.Remove("viewbox"); svgWrapper.Attributes.Add(attribute.Name, attribute.Value); } } int i = 0; foreach (XmlNode elem in doc.DocumentElement) { SvgElement svg = new SvgElement(); //Console.WriteLine(elem.Name + " : "); foreach (XmlAttribute attribute in elem.Attributes) { svg.SetAttribute(attribute.Name, attribute.Value); //Console.WriteLine(attribute.Name + "=" + attribute.Value + ", "); } svg.Path = ParseParth(svg.Attributes["d"]); //svg.WriteToConsole(); svgWrapper.SetChild($"{i++}", svg); } //SVGDocumentWriter writer = new SVGDocumentWriter(); //writer.WriteToFile("otherSvg.svg", svgWrapper); Console.WriteLine("finished parsing document..."); return(svgWrapper); } catch (XmlException) { Console.WriteLine("SvgDocumentParser.Parse() : Syntax error in svg file found"); return(null); } }
static void testrun1() { // var a = new SvgDocumentParser(); SvgCommandFactory factory = new SvgCommandFactory(); SvgCommand p1 = factory.MCmd(0, 0); SvgCommand p2 = factory.LCmd(70, 70); //SvgCommand p3 = factory.LCmd(70, 60); SvgElement line = new SvgElement(); line.Path.Add(p1); line.Path.Add(p2); //line.Path.Add(p3); line.SetAttribute("stroke", "red"); line.SetAttribute("fill", "transparent"); //PathOperation.ScalePath(ref line, 0.5); //PathOperation.TranslatePath(ref line, 250, 250); SvgCommand d = new SvgCommand(); d.x = 35; d.y = 35; PathMatrixOperation.RotatePathToDegrees(ref line, 45, d); SvgDocumentWriter writer = new SvgDocumentWriter(); SvgWrapper wrapper = new SvgWrapper(); wrapper.SetChild("one", line); writer.WriteToFile("MySvg.svg", wrapper); }