private static Map<String, RectBound> prepareGrid(Document iDoc) throws Exception {
    Map<String, RectBound> map = new HashMap<String, RectBound>();

    Node iSvg = iDoc.getChildNodes().item(1);
    Node iG = iSvg.getChildNodes().item(3);

    NodeList childNodes = iG.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      try {
        i = findNodeIndex(iG, NodeName.PATH, ATTR_STYLE, BORDER_STYLE, i);
        Node iBorderNode = childNodes.item(i);
        RectBound borderRect = toRectBound(iBorderNode.getAttributes().getNamedItem("d").getNodeValue());
        i = i + 1;
        Node iNextBorderNode = childNodes.item(i);
        if (!isBorder(iNextBorderNode)) {
          throw new IllegalStateException("Was expecting a second border after " + iBorderNode.getAttributes().getNamedItem("id").getNodeValue());
        }
        NamedNodeMap attributes = iNextBorderNode.getAttributes();
        RectBound textRect = toRectBound(attributes.getNamedItem("d").getNodeValue());

        StringBuilder sb = new StringBuilder();
        boolean hasMore = false;
        List<Node> iTextList = findTextNodeInRect(iG, textRect);
        for (Node iText : iTextList) {
          Node iTspan = iText.getFirstChild();
          if (!nodeEquals(NodeName.TSPAN, iTspan)) {
            throw new IllegalStateException("Was expecting a tspan after text");
          }
          if (hasMore) {
            sb.append(" ");
          }
          sb.append(iTspan.getTextContent());
          hasMore = true;
        }
        String name = sb.toString();

        name = name.toLowerCase().replaceAll(" ", "_").replaceAll("/", "_").replaceAll("\\.\\.\\.", "_").replaceAll("\\.", "").replaceAll(",", "").replaceAll("\\+", "plus").replaceAll("&", "and").replaceAll("__", "_");
        if (name.equals("c__cplusplus")) {
          name = "c_cplusplus";
        }
        else if (name.equals("façade")) {
          name = "facade";
        }
        else if (name.equals("file")) {
          name = "text_document";
        }

        name = ensureUnique(map, name);
        map.put(name, borderRect);
      }
      catch (NotFoundException e) {
        i = childNodes.getLength();
      }
    }

    return map;
  }