/** * Splitting up the text onto pages. * @param text to be split * @return list of Pages. */ public List<Page> splitIntoPages(Text text) { return splitIntoPages(text, false); } /**
/** * Split up the text into lines and pages, that can be displayed. * @param text component that is to be split up. */ private void splitTextToPages(Text text) { final double width = getContentWidth(); final double heigh = contentHeight.doubleValue(); Font font = control.getNavigationLabelFont(); PageSplitter splitter = new PageSplitter(heigh, width, contentContainer.getSpacing(), calculateContentInitialHeigth(), font); splitter.setWordSplitter(new NonAlphaNumWordSplitter()); pages.addAll(splitter.splitIntoPages(text)); } private double getContentWidth() {
if (isLineTooLong(lineWidth)) { String line; if (oneLine.lastIndexOf(" ") > 0) { l.setStyleClass(textStyle); lineWidth = sizing.computeTextWidth(font, l.getLine(), Double.MAX_VALUE); if (!isLineTooLong(lineWidth)) { if (isLineTooLong(lineWidth)) { if (!tokenizer.hasMoreTokens()) { page.addLine(l); Paragraph p = new Paragraph(Joiner.on(' ').join(parts)); tmpText.addParagraph(p); List<Page> tmpPages = splitIntoPages(tmpText, true); if (tmpPages.size() > 1) { throw new IllegalStateException("Got a more than on page out of a single word."); String compacted = l.getLine().replaceAll(" ", ""); l.setLine(compacted); currentPageHeight = updatePageHeight(compacted, currentPageHeight); if (currentPageHeight > pageHeigth) { currentPageHeight = updatePageHeight(line, currentPageHeight); l.setStyleClass(textStyle); page.addLine(l); currentPageHeight = updatePageHeight(oneLine.toString(), currentPageHeight); oneLine = new StringBuilder(); // clear the cache