public static String computePrintedText(RenderBox renderBox) { StringBuilder b = new StringBuilder(); RenderNode lineChild = renderBox.getFirstChild(); while (lineChild != null) { if (lineChild instanceof RenderableText) { RenderableText text = (RenderableText) lineChild; b.append(text.getRawText()); } else if (lineChild instanceof SpacerRenderNode) { SpacerRenderNode spacer = (SpacerRenderNode) lineChild; for (int i = 0; i < spacer.getSpaceCount(); i += 1) b.append(' '); } else if (lineChild instanceof RenderBox) { b.append(computePrintedText((RenderBox) lineChild)); } lineChild = lineChild.getNext(); } return b.toString(); }
protected void processOtherNode(final RenderNode node) { try { final int nodeType = node.getNodeType(); if (nodeType == LayoutNodeTypes.TYPE_NODE_TEXT || nodeType == LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT) { super.processOtherNode(node); return; } if (node.isVirtualNode()) { return; } if (nodeType == LayoutNodeTypes.TYPE_NODE_SPACER) { final SpacerRenderNode spacer = (SpacerRenderNode) node; final int count = Math.max(1, spacer.getSpaceCount()); for (int i = 0; i < count; i++) { xmlWriter.writeText(" "); } } } catch (final IOException e) { throw new RuntimeException("Failed", e); } }