/// <summary> /// Convert attribute of line join from a string. /// </summary> LineJoin ToLineJoin(string s, XmlInput xmlinput) { switch (s) { case "round": return(LineJoin.Round); case "sharp": return(LineJoin.Miter); default: xmlinput.BadXml("Invalid line end value '{0}'", s); return(LineJoin.Round); } }
/// <summary> /// Convert attribute of line cap from a string. /// </summary> LineCap ToLineCap(string s, XmlInput xmlinput) { switch (s) { case "round": return(LineCap.Round); case "flat": return(LineCap.Flat); default: xmlinput.BadXml("Invalid line end value '{0}'", s); return(LineCap.Round); } }
/// <summary> /// Read the state of this symbol from XML. The xmlinput must be on a /// symbol node. /// </summary> public void ReadXml(XmlInput xmlinput) { xmlinput.CheckElement("symbol"); this.kind = xmlinput.GetAttributeString("kind")[0]; this.id = xmlinput.GetAttributeString("id"); this.replacementId = xmlinput.GetAttributeString("replacement-id", null); this.id2018 = xmlinput.GetAttributeString("id-2018", null); this.sizeIsDepth = xmlinput.GetAttributeBool("size-is-depth", false); string standardStrings = xmlinput.GetAttributeString("standard", ""); if (standardStrings != "") { this.standards = standardStrings.Split(','); } bool first = true; List <SymbolStroke> strokes = new List <SymbolStroke>(); while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" })) { SymbolStroke stroke = new SymbolStroke(); bool isStroke = true; switch (xmlinput.Name) { case "name": xmlinput.CheckElement("name"); string language = xmlinput.GetAttributeString("lang"); name.Add(language, xmlinput.GetContentString()); isStroke = false; break; case "text": xmlinput.CheckElement("text"); SymbolText symtext = new SymbolText(); symtext.ReadXml(xmlinput); texts.Add(symtext); isStroke = false; break; case "filled-circle": xmlinput.CheckElement("filled-circle"); stroke.kind = SymbolStrokes.Disc; stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "circle": xmlinput.CheckElement("circle"); stroke.kind = SymbolStrokes.Circle; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "polygon": xmlinput.CheckElement("polygon"); stroke.kind = SymbolStrokes.Polygon; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "filled-polygon": xmlinput.CheckElement("filled-polygon"); stroke.kind = SymbolStrokes.FilledPolygon; break; case "lines": xmlinput.CheckElement("lines"); stroke.kind = SymbolStrokes.Polyline; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "beziers": xmlinput.CheckElement("beziers"); stroke.kind = SymbolStrokes.PolyBezier; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); break; case "filled-beziers": xmlinput.CheckElement("filled-beziers"); stroke.kind = SymbolStrokes.FilledPolyBezier; break; } if (isStroke) { stroke.points = ReadPoints(xmlinput); strokes.Add(stroke); } first = false; } if (this.name == null) { xmlinput.BadXml("Missing name element"); } if (texts.Count == 0) { xmlinput.BadXml("Missing text element"); } this.strokes = strokes.ToArray(); }