You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2007/07/19 16:55:05 UTC
svn commit: r557649 - in
/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table:
ActiveCell.java TableStepper.java
Author: vhennebert
Date: Thu Jul 19 07:55:04 2007
New Revision: 557649
URL: http://svn.apache.org/viewvc?view=rev&rev=557649
Log:
Code cleanup and javadocs
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java?view=diff&rev=557649&r1=557648&r2=557649
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java Thu Jul 19 07:55:04 2007
@@ -27,6 +27,9 @@
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 @@
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 @@
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 @@
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 @@
//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 @@
}
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 @@
}
}
+ /**
+ * 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 @@
}
}
+ /**
+ * 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)) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java?view=diff&rev=557649&r1=557648&r2=557649
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java Thu Jul 19 07:55:04 2007
@@ -108,8 +108,8 @@
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++) {
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org