public ArrayList<RawNode> splitWidth(double width) { ArrayList<RawNode> newNodes = new ArrayList<RawNode>(); int start = 0; for (int i = 3; i < rawString.length(); i += 5) { if (getStringBounds(rawString.substring(start, i), getAttribFont()).getWidth() >= (width - 5)) { RawNode nn = new RawNode(rawString.substring(start, i - 5)); nn.addAttributes(getAttributes()); newNodes.add(nn); start = (i - 5); } } if (start < rawString.length() - 1) { RawNode nn = new RawNode(rawString.substring(start, rawString.length())); nn.addAttributes(getAttributes()); newNodes.add(nn); } return newNodes; }
public void pack(Coord sz) { // split big nodes for (int i = 0; i < nodeList.size(); i++) { if (nodeList.get(i).getNodeWidth() >= (sz.x - 3)) { RawNode bigNode = (RawNode) nodeList.get(i); nodeList.remove(i); int z = i; for (RawNode n : bigNode.splitWidth(sz.x)) { nodeList.add(z, n); z++; } } } lines.clear(); lines.add(0); double wbuf = 0; for (int i = 0; i < nodeList.size(); i++) { wbuf += nodeList.get(i).getNodeWidth(); if (wbuf >= sz.x) { wbuf = nodeList.get(i).getNodeWidth(); lines.add(i); } } }