From: Vincent Hennebert Date: Thu, 12 Jul 2007 14:59:06 +0000 (+0000) Subject: Fixes in the steps computation: X-Git-Tag: fop-0_94~40 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=945d1cfaf3668b6bc230225f60341629d559c172;p=xmlgraphics-fop.git Fixes in the steps computation: - directly include the penalties of the cell contents in the step computation; no longer use a nestedPenaltyLength - compute the real remaining length, i.e., discarding all the glues and penalties after the candidate break - if step + maxRemainingLength < totalLength, a glue must be added to hold the additional length when the row group is not broken git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@555651 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java index 4eac98953..60f7333ef 100644 --- a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java +++ b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.fo.flow.TableRow; import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.layoutmgr.ElementListUtils; +import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthPossPosIter; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.SpaceResolver; @@ -91,11 +92,6 @@ class RowPainter { return this.accumulatedBPD; } - public void notifyNestedPenaltyArea(int length) { - yoffset += length; - accumulatedBPD += length; - } - /** * Records the fragment of row represented by the given position. If it belongs to * another (grid) row than the current one, that latter is painted and flushed first. @@ -233,8 +229,18 @@ class RowPainter { log.trace("getting len for " + columnIndex + " " + start + "-" + end); } + int actualStart = start; + // Skip from the content length calculation glues and penalties occuring at the + // beginning of the page + while (actualStart <= end && !((KnuthElement)pgu.getElements().get(actualStart)).isBox()) { + actualStart++; + } int len = ElementListUtils.calcContentLength( - pgu.getElements(), start, end); + pgu.getElements(), actualStart, end); + KnuthElement el = (KnuthElement)pgu.getElements().get(end); + if (el.isPenalty()) { + len += el.getW(); + } partBPD[columnIndex] = len; if (log.isTraceEnabled()) { log.trace("len of part: " + len); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java index 8abe1a3e8..078b99df5 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java @@ -625,7 +625,6 @@ public class TableContentLayoutManager implements PercentBaseContext { List positions = new java.util.ArrayList(); List headerElements = null; List footerElements = null; - int nestedPenaltyArea = 0; Position firstPos = null; Position lastPos = null; Position lastCheckPos = null; @@ -675,7 +674,6 @@ public class TableContentLayoutManager implements PercentBaseContext { if (penaltyPos.footerElements != null) { footerElements = penaltyPos.footerElements; } - nestedPenaltyArea = penaltyPos.nestedPenaltyLength; } Map markers = getTableLM().getTable().getMarkers(); @@ -695,7 +693,6 @@ public class TableContentLayoutManager implements PercentBaseContext { Iterator posIter = positions.iterator(); iterateAndPaintPositions(posIter, painter); - painter.notifyNestedPenaltyArea(nestedPenaltyArea); if (footerElements != null) { //Positions for footers are simply added at the end PositionIterator nestedIter = new KnuthPossPosIter(footerElements); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java b/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java index a23c7a705..afa166985 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java @@ -34,8 +34,6 @@ class TableHFPenaltyPosition extends Position { protected List headerElements; /** Element list for the footer */ protected List footerElements; - /** Penalty length to be respected for nested content */ - protected int nestedPenaltyLength; /** * Creates a new TableHFPenaltyPosition @@ -52,8 +50,6 @@ class TableHFPenaltyPosition extends Position { sb.append(headerElements); sb.append(", footer:"); sb.append(footerElements); - sb.append(", inner penalty length:"); - sb.append(nestedPenaltyLength); sb.append(")"); return sb.toString(); } diff --git a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java index 4ac0b8604..b36930ecb 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java @@ -32,8 +32,10 @@ import org.apache.fop.layoutmgr.BreakElement; import org.apache.fop.layoutmgr.ElementListUtils; import org.apache.fop.layoutmgr.KnuthBox; import org.apache.fop.layoutmgr.KnuthElement; +import org.apache.fop.layoutmgr.KnuthGlue; import org.apache.fop.layoutmgr.KnuthPenalty; import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.Position; /** * This class processes row groups to create combined element lists for tables. @@ -56,6 +58,7 @@ public class TableStepper { * current one. */ private int width; + private int remainingLength; private int baseWidth; private int totalLength; private int includedLength; @@ -88,8 +91,6 @@ public class TableStepper { } elementList.add(new KnuthBoxCellWithBPD(height)); } else { - //Copy elements (LinkedList) to array lists to improve - //element access performance elementList = pgu.getElements(); // if (log.isTraceEnabled()) { // log.trace("column " + (column+1) + ": recording " + elementLists.size() + " element(s)"); @@ -112,6 +113,7 @@ public class TableStepper { startRow = rowIndex; keepWithNextSignal = false; computeBaseWidth(rowGroup); + remainingLength = totalLength; goToNextLegalBreak(); } @@ -134,8 +136,7 @@ public class TableStepper { } else if (includedLength == totalLength) { return 0; } else { - return totalLength - Math.max(0, includedLength) - + borderBefore + borderAfter + paddingBefore + paddingAfter; + return remainingLength + borderBefore + borderAfter + paddingBefore + paddingAfter; } } @@ -169,13 +170,13 @@ public class TableStepper { int getNextStep() { if (!includedInLastStep()) { - return width + borderBefore + borderAfter + paddingBefore + paddingAfter; + return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; } else { start = end + 1; if (end < elementList.size() - 1) { goToNextLegalBreak(); - return width + borderBefore + borderAfter + paddingBefore + paddingAfter; + return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; } else { return 0; } @@ -187,14 +188,29 @@ public class TableStepper { } boolean signalMinStep(int minStep) { - if (width + borderBefore + borderAfter + paddingBefore + paddingAfter <= minStep) { + if (width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter <= minStep) { includedLength = width; + computeRemainingLength(); return false; } else { return baseWidth + borderBefore + borderAfter + paddingBefore + paddingAfter > minStep; } } + private void computeRemainingLength() { + remainingLength = totalLength - width; + int index = end + 1; + while (index < elementList.size()) { + KnuthElement el = (KnuthElement)elementList.get(index); + if (el.isBox()) { + break; + } else if (el.isGlue()) { + remainingLength -= el.getW(); + } + index++; + } + } + boolean contributesContent() { return includedInLastStep() && end >= start; } @@ -203,10 +219,6 @@ public class TableStepper { return includedLength > 0; } - int getLastPenaltyLength() { - return lastPenaltyLength; - } - boolean isFinished() { return includedInLastStep() && (end == elementList.size() - 1); } @@ -223,7 +235,6 @@ public class TableStepper { private int activeRowIndex; private boolean rowBacktrackForLastStep; private boolean skippedStep; - private int lastMaxPenaltyLength; private List activeCells = new LinkedList(); @@ -330,8 +341,8 @@ public class TableStepper { while ((step = getNextStep()) >= 0) { int normalRow = activeRowIndex; int increase = step - laststep; - int penaltyLen = step + getMaxRemainingHeight() - totalHeight; - int boxLen = step - addedBoxLen - penaltyLen; + int penaltyOrGlueLen = step + getMaxRemainingHeight() - totalHeight; + int boxLen = step - addedBoxLen - Math.max(0, penaltyOrGlueLen); addedBoxLen += boxLen; boolean forcedBreak = false; @@ -384,7 +395,6 @@ public class TableStepper { //log.debug(">>> guPARTS: " + gridUnitParts); //Create elements for step - int effPenaltyLen = penaltyLen; TableContentPosition tcpos = new TableContentPosition(getTableLM(), gridUnitParts, rowGroup[normalRow]); if (returnList.size() == 0) { @@ -396,6 +406,8 @@ public class TableStepper { + " - row=" + activeRowIndex + " - " + tcpos); } returnList.add(new KnuthBox(boxLen, tcpos, false)); + + int effPenaltyLen = Math.max(0, penaltyOrGlueLen); TableHFPenaltyPosition penaltyPos = new TableHFPenaltyPosition(getTableLM()); if (bodyType == TableRowIterator.BODY) { if (!getTableLM().getTable().omitHeaderAtBreak()) { @@ -408,17 +420,6 @@ public class TableStepper { } } - //Handle a penalty length coming from nested content - //Example: nested table with header/footer - if (this.lastMaxPenaltyLength != 0) { - penaltyPos.nestedPenaltyLength = this.lastMaxPenaltyLength; - if (log.isDebugEnabled()) { - log.debug("Additional penalty length from table-cell break: " - + this.lastMaxPenaltyLength); - } - } - effPenaltyLen += this.lastMaxPenaltyLength; - int p = 0; boolean allCellsHaveContributed = true; signalKeepWithNext = false; @@ -449,11 +450,14 @@ public class TableStepper { p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in XSL 1.0) } returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, breakClass, context)); + if (penaltyOrGlueLen < 0) { + returnList.add(new KnuthGlue(-penaltyOrGlueLen, 0, 0, new Position(null), true)); + } if (log.isDebugEnabled()) { log.debug("step=" + step + " (+" + increase + ")" + " box=" + boxLen - + " penalty=" + penaltyLen + + " penalty=" + penaltyOrGlueLen + " effPenalty=" + effPenaltyLen); } @@ -477,7 +481,6 @@ public class TableStepper { */ private int getNextStep() { log.trace("Entering getNextStep"); - this.lastMaxPenaltyLength = 0; //Check for forced break conditions /* if (isBreakCondition()) { @@ -497,8 +500,6 @@ public class TableStepper { if (nextStep > 0) { stepFound = true; minStep = Math.min(minStep, nextStep); - lastMaxPenaltyLength = Math.max(lastMaxPenaltyLength, activeCell - .getLastPenaltyLength()); } } if (!stepFound) { @@ -587,5 +588,4 @@ public class TableStepper { super(w, null, true); } } - }