public static List<VectorObject> ParseXMLDom(XmlDocument dom, ParseCallback cbk) { ParseContext cxt = new ParseContext(); // Ԥ����Ԥ����ͼ�� ParseShapes(cxt, dom); // Ԥ����ֵ ParseValues(cxt, dom); // Ԥ���ڻ�ˢ ParseBrushes(cxt, dom); // Ԥ���ڻ��� ParsePens(cxt, dom); // Ԥ�������� ParseFonts(cxt, dom); // ��������ͼ������ return ParseData(cxt, dom, cbk); }
public VectorObject ParseToVector(XmlNode node, ParseCallback cbk) { if (node is System.Xml.XmlComment) return null; if (cbk != null && cbk.BeforeParse != null && cbk.BeforeParse(this, node) == false) return null; if (BooltAttr(node, "break")) { System.Diagnostics.Debug.WriteLine("break: " + node.Name); } String tag = node.Name; if (ParseStack.Contains(tag)) { StringBuilder sb = new StringBuilder(); foreach (String s in ParseStack) { sb.Append(s); sb.Append(">"); } sb.Append(tag); throw new Exception("����ͼ�εݹ�:"+sb.ToString()); } ParseStack.Add(tag); VectorObject vo = null; List<String> IgnorAttrs = new List<string>(); float pscale = this.Scale; switch (tag) { case "line": vo = new VectorLine(FloatAttr(node, "x1") * Scale, FloatAttr(node, "y1") * Scale, FloatAttr(node, "x2") * Scale, FloatAttr(node, "y2") * Scale); IgnorAttrs.Add("x1"); IgnorAttrs.Add("y1"); IgnorAttrs.Add("x2"); IgnorAttrs.Add("y2"); break; case "box": vo = new VectorBox(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, BooltAttr(node, "fill")); IgnorAttrs.Add("x"); IgnorAttrs.Add("y"); IgnorAttrs.Add("w"); IgnorAttrs.Add("h"); IgnorAttrs.Add("fill"); break; case "ellipse": case "circle": if (node.Attributes["r"] != null) vo = new VectorCircle(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "r") * Scale, FloatAttr(node, "r") * Scale, BooltAttr(node, "fill")); else vo = new VectorCircle(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, BooltAttr(node, "fill")); IgnorAttrs.Add("x"); IgnorAttrs.Add("y"); IgnorAttrs.Add("r"); IgnorAttrs.Add("fill"); break; case "text": vo = new VectorText(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, Escaped(AttrOf(node, "text"))); IgnorAttrs.Add("x"); IgnorAttrs.Add("y"); IgnorAttrs.Add("text"); break; case "pie": vo = new VectorPie(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, FloatAttr(node, "sta"), FloatAttr(node, "swa"), BooltAttr(node, "fill")); break; case "arc": vo = new VectorArc(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, FloatAttr(node, "sta"), FloatAttr(node, "swa")); break; case "path": if (node.HasChildNodes && node.ChildNodes.Count > 2) { float sx = FloatAttr(node, "x"); float sy = FloatAttr(node, "y"); List<Object> pathes = new List<Object>(node.ChildNodes.Count); foreach (XmlNode ch in node.ChildNodes) { if (ch is System.Xml.XmlComment) continue; switch (ch.Name) { case "point": pathes.Add(new VectorPathLine(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale)); break; case "line": pathes.Add(new VectorPathLine(FloatAttr(ch, "x1") * Scale, FloatAttr(ch, "y1") * Scale, FloatAttr(ch, "x2") * Scale, FloatAttr(ch, "y2") * Scale)); break; case "arc": pathes.Add(new VectorPathArc(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "w") * Scale, FloatAttr(ch, "h") * Scale, FloatAttr(ch, "sta"), FloatAttr(ch, "swa"))); break; case "pie": pathes.Add(new VectorPathPie(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "w") * Scale, FloatAttr(ch, "h") * Scale, FloatAttr(ch, "sta"), FloatAttr(ch, "swa"))); break; } } vo = new VectorPath(pathes, BooltAttr(node, "fill")); IgnorAttrs.Add("x"); IgnorAttrs.Add("y"); IgnorAttrs.Add("fill"); } else { throw new Exception(String.Format("·���ڵ�{0}���������������ӽڵ�.", node.OuterXml)); } break; default: // ���ȳ���ʹ����չ���� // �����չ����ʧ�ܣ�����Ϊ�ýڵ�Ϊ����ͼ�� List<String> oIgnorAttrs = this.CurIgnorAttrs; this.CurIgnorAttrs = IgnorAttrs; vo = cbk != null && cbk.ExtensionParse != null ? cbk.ExtensionParse(this, node) : null; if (vo != null) break; this.CurIgnorAttrs = oIgnorAttrs; // ��չ����ʧ�ܣ��ж��Ƿ���ڸø���ͼ�� if (!Shapes.Contains(tag)) throw new Exception(String.Format("δ����ͼ��{0}", tag)); else { // ����ע�� } // ��������ͼ�� VectorComplex vc = new VectorComplex(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale); IgnorAttrs.Add("x"); IgnorAttrs.Add("y"); // ���ڸ���ͼ����Ҫ�ȼ� AddExtAttribute(IgnorAttrs, (XmlNode)Shapes[tag], vc); AddExtAttribute(IgnorAttrs, node, vc); float scl = this.Scale; this.Scale *= node.Attributes["scale"] == null ? 1.0f : FloatAttr(node, "scale"); foreach (XmlNode cnode in ((XmlNode)Shapes[tag]).ChildNodes) { VectorObject ovo = CurParent; CurParent = vc; VectorObject cvo = this.ParseToVector(cnode, cbk); if (cvo != null) vc.AddChild(cvo); CurParent = ovo; } this.Scale = scl; vo = vc; break; } vo.ScaleWeight = pscale; if (vo!=null && vo.Attributes == null) AddExtAttribute(IgnorAttrs, node, vo); ParseStack.Remove(tag); if (node.Attributes["display"]!=null) vo.Display = BooltAttr(node, "display"); if (cbk != null && cbk.AfterParse != null && cbk.AfterParse(this, node, vo) == false) return null; else { return vo; } }
private static List<VectorObject> ParseData(ParseContext cxt, XmlDocument dom, ParseCallback cbk) { XmlNode objects = dom.GetElementsByTagName("vectors").Item(0); List<VectorObject> list = new List<VectorObject>(objects.ChildNodes.Count); foreach (XmlNode obj in objects) { if (obj is System.Xml.XmlComment) continue; VectorObject vo = cxt.ParseToVector(obj, cbk); // �������֮���������Ƿ��㹻 vo.CheckRequire(); if (vo != null) list.Add(vo); } return list; }
public static List<VectorObject> ParseXMLString(String xml, ParseCallback cbk) { XmlDocument dom = new XmlDocument(); dom.LoadXml(xml); return ParseXMLDom(dom, cbk); }
public static List<VectorObject> ParseXMLFile(String xmlfile, ParseCallback cbk) { XmlDocument dom = new XmlDocument(); dom.Load(xmlfile); return ParseXMLDom(dom,cbk); }