From 0da37cf697486162d5e898b307af375d91431dc5 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Thu, 19 Jul 2007 14:55:04 +0000 Subject: [PATCH] Code cleanup and javadocs git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@557649 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/table/ActiveCell.java | 86 +++++++++++++++---- .../fop/layoutmgr/table/TableStepper.java | 4 +- 2 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java b/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java index e9ae9245b..86ef71a6c 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java +++ b/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java @@ -27,6 +27,9 @@ import org.apache.fop.layoutmgr.KnuthBox; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthPenalty; +/** + * A cell playing in the construction of steps for a row-group. + */ class ActiveCell { private PrimaryGridUnit pgu; /** Knuth elements for this active cell. */ @@ -40,20 +43,22 @@ class ActiveCell { private int start; /** Index, in the list of Knuth elements, of the element ending the current step. */ private int end; - /** - * Total length of the Knuth elements already included in the steps, up to the - * current one. - */ - private int width; + /** Length of the Knuth elements up to the next feasible break. */ + private int nextStepLength; + /** Length of the Knuth elements not yet included in the steps. */ private int remainingLength; + /** Heights of the rows (in the row-group) preceding the one where this cell starts. */ private int previousRowsLength; + /** Total length of this cell's content. */ private int totalLength; + /** Length of the Knuth elements already included in the steps. */ private int includedLength; private int borderBefore; private int borderAfter; private int paddingBefore; private int paddingAfter; private boolean keepWithNextSignal; + /** Length of the penalty ending the last step, if any. */ private int lastPenaltyLength; ActiveCell(PrimaryGridUnit pgu, EffRow row, int rowIndex, int previousRowsLength, TableLayoutManager tableLM) { @@ -86,7 +91,7 @@ class ActiveCell { knuthIter = elementList.listIterator(); includedLength = -1; // Avoid troubles with cells having content of zero length this.previousRowsLength = previousRowsLength; - width = previousRowsLength; + nextStepLength = previousRowsLength; totalLength = ElementListUtils.calcContentLength(elementList); if (pgu.getTable().isSeparateBorderModel()) { borderBefore = pgu.getBorders().getBorderBeforeWidth(false) @@ -107,11 +112,24 @@ class ActiveCell { goToNextLegalBreak(); } + /** + * Returns true if this cell ends on the given row. + * + * @param rowIndex index of a row in the row-group, zero-based + * @return true if this cell ends on the given row + */ boolean endsOnRow(int rowIndex) { return rowIndex == endRowIndex; } - int getRemainingHeight(int activeRowIndex, EffRow[] rowGroup) { + /** + * Returns the length of this cell's content not yet included in the steps, plus + * the cell's borders and paddings if applicable. + * + * @param activeRowIndex index of the row currently considered + * @return the remaining length, or zero if the cell doesn't end on the given row. + */ + int getRemainingHeight(int activeRowIndex) { if (!endsOnRow(activeRowIndex)) { return 0; } else if (includedLength == totalLength) { @@ -138,25 +156,30 @@ class ActiveCell { //Second legal break point breakFound = true; } else { - width += el.getW(); + nextStepLength += el.getW(); } prevIsBox = false; } else { prevIsBox = true; - width += el.getW(); + nextStepLength += el.getW(); } } end = knuthIter.nextIndex() - 1; } + /** + * Returns the total length up to the next legal break, not yet included in the steps. + * + * @return the total length up to the next legal break + */ int getNextStep() { if (!includedInLastStep()) { - return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; + return nextStepLength + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; } else { start = end + 1; if (knuthIter.hasNext()) { goToNextLegalBreak(); - return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; + return nextStepLength + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; } else { return 0; } @@ -164,12 +187,19 @@ class ActiveCell { } private boolean includedInLastStep() { - return includedLength == width; + return includedLength == nextStepLength; } + /** + * Signals the length of the chosen next step, so that this cell determines + * whether its own step may be included or not. + * + * @param minStep length of the chosen next step + * @return + */ boolean signalMinStep(int minStep) { - if (width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter <= minStep) { - includedLength = width; + if (nextStepLength + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter <= minStep) { + includedLength = nextStepLength; computeRemainingLength(); return false; } else { @@ -177,8 +207,13 @@ class ActiveCell { } } + /** + * Computes the length of the cell's content after the current legal break. + * Discards every glue or penalty following the break if needed. The cell's + * borders and paddings are not considered here. + */ private void computeRemainingLength() { - remainingLength = totalLength - width; + remainingLength = totalLength - nextStepLength; // Save the current location in the element list int oldIndex = knuthIter.nextIndex(); KnuthElement el; @@ -194,18 +229,39 @@ class ActiveCell { } } + /** + * Returns true if some content of this cell is part of the chosen next step. + * + * @return true if this cell's next step is inferior or equal to the next minimal step + */ boolean contributesContent() { return includedInLastStep() && end >= start; } + /** + * Returns true if this cell has already started to contribute some content to the steps. + * + * @return true if this cell's first step is inferior or equal to the current one + */ boolean hasStarted() { return includedLength > 0; } + /** + * Returns true if this cell has contributed all of its content to the steps. + * + * @return true if the end of this cell is reached + */ boolean isFinished() { return includedInLastStep() && (end == elementList.size() - 1); } + /** + * Creates and returns a GridUnitPart instance for the content of this cell which + * is included in the next step. + * + * @return a GridUnitPart instance + */ GridUnitPart createGridUnitPart() { if (end + 1 == elementList.size()) { if (pgu.getFlag(GridUnit.KEEP_WITH_NEXT_PENDING)) { diff --git a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java index 8dad6d520..945f9aa4b 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java @@ -108,8 +108,8 @@ public class TableStepper { int maxW = 0; if (!rowBacktrackForLastStep) { for (Iterator iter = activeCells.iterator(); iter.hasNext();) { - maxW = Math.max(maxW, ((ActiveCell) iter.next()).getRemainingHeight(activeRowIndex, - rowGroup)); + maxW = Math.max(maxW, + ((ActiveCell) iter.next()).getRemainingHeight(activeRowIndex)); } } for (int i = activeRowIndex + (rowBacktrackForLastStep ? 0 : 1); i < rowGroup.length; i++) { -- 2.39.5