parseNode method

dynamic parseNode(
  1. dynamic node,
  2. dynamic style
)

Implementation

parseNode(node, style) {
  if (node.nodeType != 1) return;

  var transform = getNodeTransform(node);

  var traverseChildNodes = true;

  var path;

  switch (node.nodeName) {
    case 'svg':
      break;

    case 'style':
      parseCSSStylesheet(node);
      break;

    case 'g':
      style = parseStyle(node, style);
      break;

    case 'path':
      style = parseStyle(node, style);
      if (node.hasAttribute('d')) {
        path = parsePathNode(node);
      }
      break;

    case 'rect':
      style = parseStyle(node, style);
      path = parseRectNode(node);
      break;

    case 'polygon':
      style = parseStyle(node, style);
      path = parsePolygonNode(node);
      break;

    case 'polyline':
      style = parseStyle(node, style);
      path = parsePolylineNode(node);
      break;

    case 'circle':
      style = parseStyle(node, style);
      path = parseCircleNode(node);
      break;

    case 'ellipse':
      style = parseStyle(node, style);
      path = parseEllipseNode(node);
      break;

    case 'line':
      style = parseStyle(node, style);
      path = parseLineNode(node);
      break;

    case 'defs':
      traverseChildNodes = false;
      break;

    case 'use':
      style = parseStyle(node, style);
      var usedNodeId = node.href.baseVal.substring(1);
      var usedNode = node.viewportElement.getElementById(usedNodeId);
      if (usedNode != null) {
        parseNode(usedNode, style);
      } else {
        print(
            "SVGLoader: 'use node' references non-existent node id: $usedNodeId");
      }

      break;

    default:
    // console.log( node );

  }

  if (path != null) {
    if (style["fill"] != null && style["fill"] != 'none') {
      path.color.setStyle(style["fill"]);
    }

    transformPath(path, currentTransform);

    paths.add(path);

    path.userData = {"node": node, "style": style};
  }

  if (traverseChildNodes) {
    var nodes = node.childNodes;

    for (var i = 0; i < nodes.length; i++) {
      parseNode(nodes[i], style);
    }
  }

  if (transform != null) {
    transformStack.removeLast();

    if (transformStack.isNotEmpty) {
      currentTransform.copy(transformStack[transformStack.length - 1]);
    } else {
      currentTransform.identity();
    }
  }
}