public void OnStartElement(string name, AttributeList attrs) { Node node = new BlockOpenNode(Lookup(name), new AttributeList(attrs), _currentDepth++); // Debug.Log("OnStartElement: "+name); node.parent = _lastParent; if (_lastParent != null) { _lastParent.children.Add(node); } _lastParent = node; OnNode(node); //Debug.Log("OnStartElement: "+node.name+", depth: "+node.depth); }
protected void ResolveGradientLinks() { string xlink = node.attributes.GetValue("xlink:href"); if (!string.IsNullOrEmpty(xlink)) { if (xlink [0] == '#') { xlink = xlink.Remove(0, 1); } if (_defs.ContainsKey(xlink)) { Node definitionNode = _defs [xlink]; if (definitionNode != null && definitionNode != node) { MergeNodeAttributes(definitionNode, node); List <Node> injectNodes = definitionNode.GetNodes(); if (injectNodes != null && injectNodes.Count > 0) { bool createOpenNode = nodes[idx] is InlineNode; if (createOpenNode) { nodes[idx] = new BlockOpenNode(nodes[idx].name, nodes[idx].attributes, nodes[idx].depth); } injectNodes.RemoveAt(0); if (injectNodes.Count > 0) { injectNodes.RemoveAt(injectNodes.Count - 1); } if (injectNodes.Count > 0) { nodes[idx].children = injectNodes; nodes.InsertRange(idx + 1, injectNodes); } if (createOpenNode) { nodes.Insert(idx + 1 + injectNodes.Count, new BlockCloseNode(node.name, new AttributeList(), node.depth)); } } } } } }
protected void ResolveGradientLinks() { string xlink = node.attributes.GetValue("xlink:href"); if (!string.IsNullOrEmpty(xlink)) { if (xlink [0] == '#') xlink = xlink.Remove(0, 1); if (_defs.ContainsKey(xlink)) { Node definitionNode = _defs [xlink]; if (definitionNode != null && definitionNode != node) { MergeNodeAttributes(definitionNode, node); List<Node> injectNodes = definitionNode.GetNodes(); if (injectNodes != null && injectNodes.Count > 0) { bool createOpenNode = nodes[idx] is InlineNode; if(createOpenNode) { nodes[idx] = new BlockOpenNode(nodes[idx].name, nodes[idx].attributes, nodes[idx].depth); } injectNodes.RemoveAt(0); if(injectNodes.Count > 0) { injectNodes.RemoveAt(injectNodes.Count - 1); } if(injectNodes.Count > 0) { nodes[idx].children = injectNodes; nodes.InsertRange(idx + 1, injectNodes); } if(createOpenNode) { nodes.Insert(idx + 1 + injectNodes.Count, new BlockCloseNode(node.name, new AttributeList(), node.depth)); } } } } } }
public void GetElementList(List<object> elementList, SVGPaintable paintable, SVGTransformList summaryTransformList) { bool exitFlag = false; while (!exitFlag && Next()) { //while (Next()) if (node is BlockCloseNode) { exitFlag = true; continue; } //Debug.Log(node.name); switch (node.name) { case SVGNodeName.Rect: { elementList.Add(new SVGRectElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Line: { elementList.Add(new SVGLineElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Circle: { elementList.Add(new SVGCircleElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Ellipse: { elementList.Add(new SVGEllipseElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.PolyLine: { elementList.Add(new SVGPolylineElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Polygon: { elementList.Add(new SVGPolygonElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Path: { elementList.Add(new SVGPathElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.SVG: { if(node is InlineNode) break; elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } case SVGNodeName.Symbol: { if(node is InlineNode) break; elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } case SVGNodeName.G: { if(node is InlineNode) break; elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } /* case SVGNodeName.ClipPath: { paintable.AppendClipPath(new SVGClipPathElement(this, node)); break; } */ case SVGNodeName.LinearGradient: { ResolveGradientLinks(); paintable.AppendLinearGradient(new SVGLinearGradientElement(this, node)); break; } case SVGNodeName.RadialGradient: { ResolveGradientLinks(); paintable.AppendRadialGradient(new SVGRadialGradientElement(this, node)); break; } case SVGNodeName.ConicalGradient: { ResolveGradientLinks(); paintable.AppendConicalGradient(new SVGConicalGradientElement(this, node)); break; } case SVGNodeName.Defs: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Title: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Desc: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Style: { paintable.AddCSS(node.content); break; } case SVGNodeName.Use: { // Debug.Log("Begin Use Command: " + node.attributes.GetValue("id")); string xlink = node.attributes.GetValue("xlink:href"); if (!string.IsNullOrEmpty(xlink)) { if (xlink [0] == '#') xlink = xlink.Remove(0, 1); if (_defs.ContainsKey(xlink)) { Node definitionNode = _defs [xlink]; if (definitionNode != null && definitionNode != node) { List<Node> injectNodes = definitionNode.GetNodes(); if (injectNodes != null && injectNodes.Count > 0) { nodes [idx] = new BlockOpenNode(SVGNodeName.Use, node.attributes, node.depth); injectNodes.Add(new BlockCloseNode(SVGNodeName.Use, new AttributeList(), node.depth)); nodes.InsertRange(idx + 1, injectNodes); elementList.Add(new SVGElement(this, summaryTransformList, paintable)); } } } } break; } } } }
public void GetElementList(List <object> elementList, SVGPaintable paintable, SVGTransformList summaryTransformList) { bool exitFlag = false; while (!exitFlag && Next()) { //while (Next()) if (node is BlockCloseNode) { exitFlag = true; continue; } //Debug.Log(node.name); switch (node.name) { case SVGNodeName.Rect: { elementList.Add(new SVGRectElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Line: { elementList.Add(new SVGLineElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Circle: { elementList.Add(new SVGCircleElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Ellipse: { elementList.Add(new SVGEllipseElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.PolyLine: { elementList.Add(new SVGPolylineElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Polygon: { elementList.Add(new SVGPolygonElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.Path: { elementList.Add(new SVGPathElement(node, summaryTransformList, paintable)); break; } case SVGNodeName.SVG: { if (node is InlineNode) { break; } elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } case SVGNodeName.Symbol: { if (node is InlineNode) { break; } elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } case SVGNodeName.G: { if (node is InlineNode) { break; } elementList.Add(new SVGElement(this, summaryTransformList, paintable)); break; } /* * case SVGNodeName.ClipPath: * { * paintable.AppendClipPath(new SVGClipPathElement(this, node)); * break; * } */ case SVGNodeName.LinearGradient: { ResolveGradientLinks(); paintable.AppendLinearGradient(new SVGLinearGradientElement(this, node)); break; } case SVGNodeName.RadialGradient: { ResolveGradientLinks(); paintable.AppendRadialGradient(new SVGRadialGradientElement(this, node)); break; } case SVGNodeName.ConicalGradient: { ResolveGradientLinks(); paintable.AppendConicalGradient(new SVGConicalGradientElement(this, node)); break; } case SVGNodeName.Defs: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Title: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Desc: { GetElementList(elementList, paintable, summaryTransformList); break; } case SVGNodeName.Style: { paintable.AddCSS(node.content); break; } case SVGNodeName.Use: { // Debug.Log("Begin Use Command: " + node.attributes.GetValue("id")); string xlink = node.attributes.GetValue("xlink:href"); if (!string.IsNullOrEmpty(xlink)) { if (xlink [0] == '#') { xlink = xlink.Remove(0, 1); } if (_defs.ContainsKey(xlink)) { Node definitionNode = _defs [xlink]; if (definitionNode != null && definitionNode != node) { List <Node> injectNodes = definitionNode.GetNodes(); if (injectNodes != null && injectNodes.Count > 0) { nodes [idx] = new BlockOpenNode(SVGNodeName.Use, node.attributes, node.depth); injectNodes.Add(new BlockCloseNode(SVGNodeName.Use, new AttributeList(), node.depth)); nodes.InsertRange(idx + 1, injectNodes); elementList.Add(new SVGElement(this, summaryTransformList, paintable)); } } } } break; } } } }