private BalancingResult applyBestResult() { final float hCenter = horCenter(); List<Element> elements = sequence.getElements(); setColumn((float) bestResult.leftColumnHeight, hCenter, true, true, singleColumnRect, leftCTB); setColumn( (float) bestResult.rightColumnHeight, hCenter, false, false, singleColumnRect, rightCTB); if (b.drawBorders) { b.getCanvasBuilder().drawGrayRectangle(leftCTB.getSimpleColumnRectangle(), BaseColor.RED); b.getCanvasBuilder().drawGrayRectangle(rightCTB.getSimpleColumnRectangle(), BaseColor.GREEN); } leftCTB.clearContent(); rightCTB.clearContent(); final DirectContentAdder.Result addResult = new DirectContentAdder(leftCTB) .setStartWith(initialLeftCTB) .setStartAtIndex(startAtElement) .setSwitchToRightCTB(rightCTB) .setSimulate(false) .go(); float yLine = Math.min(leftCTB.getYLine(), rightCTB.getYLine()); final BalancingResult r; if (addResult.hasContentLeft(elements.size())) { final ColumnTextBuilder contentCopy = addResult.contentLeft == null ? null : b.newColumnTextBuilder().setACopy(addResult.contentLeft); r = startWithANewPage(contentCopy, addResult.index); } else { r = new BalancingResult(yLine); // if(updateAfterRun != null){ // updateAfterRun.growBottom(origRectangle.getTop() - yLine); // } } if (updateAfterRun != null) { updateAfterRun.setSimpleColumn( b.reuseRectangleBuilder(new Rectangle(origRectangle.get())) .setTop(yLine) .setBottom(b.getDocument().bottom()) .get()); } return r; }
public Result go() { if (quickHeight != 0) { if (rightCTB != null) { throw new IllegalStateException("if quickHeight !=0 then rightCTB == null!"); } } Preconditions.checkNotNull(dest); ColumnTextBuilder currentCtb = dest; List<Element> elements = sequence.getElements(); int i; if (quickHeight != 0) { currentCtb.adjustBottom((float) quickHeight); } if (startWith != null) { currentCtb.copyContentFrom(startWith); float yBefore = currentCtb.getYLine(); int status = currentCtb.go(simulate); if (setHeights) { startContentHeight = yBefore - currentCtb.getYLine(); } if (ColumnText.hasMoreText(status)) { if (rightCTB != null) { // => quickHeight == 0 rightCTB.copyContentFrom(currentCtb); currentCtb = rightCTB; yBefore = currentCtb.getYLine(); status = currentCtb.go(simulate); if (setHeights) { startContentHeight += yBefore - currentCtb.getYLine(); } if (ColumnText.hasMoreText(status)) { return new Result(ColumnText.NO_MORE_COLUMN, startAtIndex, currentCtb); } } else { return new Result(ColumnText.NO_MORE_COLUMN, startAtIndex, currentCtb); } } } // optimisation mode if (quickHeight != 0) { for (i = startAtIndex; i < elements.size(); i++) { Element el = elements.get(i); if (currentCtb.fits(el)) { if (el instanceof SpaceElement) { SpaceElement spaceElement = (SpaceElement) el; spaceElement.add(currentCtb, simulate); currentCtb.go(simulate); } else { currentCtb.addElement(el).go(simulate); } } else { break; } } return new Result(ColumnText.NO_MORE_TEXT, i, null); } for (i = startAtElement; i < elements.size(); i++) { Element el = elements.get(i); float yBefore = currentCtb.getYLine(); if (el instanceof SpaceElement) { SpaceElement space = (SpaceElement) el; if (space.fits(currentCtb, currentCtb.getBottom())) { space.add(currentCtb, simulate); } else { if (currentCtb == dest) { currentCtb = rightCTB; } else if (currentCtb == rightCTB) { return new Result(ColumnText.NO_MORE_COLUMN, i + 1, currentCtb.clearContent()); } } } else { currentCtb.addElement(el); if (ColumnText.hasMoreText(currentCtb.go(simulate))) { if (currentCtb == dest) { if (rightCTB == null) { return new Result(ColumnText.NO_MORE_COLUMN, i + 1, currentCtb); } else { rightCTB.copyContentFrom(currentCtb); currentCtb = rightCTB; final int status = currentCtb.go(simulate); if (ColumnText.hasMoreText(status)) { return new Result(ColumnText.NO_MORE_COLUMN, i + 1, currentCtb); } } } else { return new Result(ColumnText.NO_MORE_COLUMN, i + 1, currentCtb); } } } if (setHeights) { sequence.setHeight(i, yBefore - currentCtb.getYLine()); } } return new Result(ColumnText.NO_MORE_TEXT, elements.size(), null); }