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/12 16:59:07 UTC

svn commit: r555651 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table: RowPainter.java TableContentLayoutManager.java TableHFPenaltyPosition.java TableStepper.java

Author: vhennebert
Date: Thu Jul 12 07:59:06 2007
New Revision: 555651

URL: http://svn.apache.org/viewvc?view=rev&rev=555651
Log:
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

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java?view=diff&rev=555651&r1=555650&r2=555651
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java Thu Jul 12 07:59:06 2007
@@ -28,6 +28,7 @@
 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 @@
         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 @@
             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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java?view=diff&rev=555651&r1=555650&r2=555651
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java Thu Jul 12 07:59:06 2007
@@ -625,7 +625,6 @@
         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 @@
             if (penaltyPos.footerElements != null) {
                 footerElements = penaltyPos.footerElements; 
             }
-            nestedPenaltyArea = penaltyPos.nestedPenaltyLength;
         }
 
         Map markers = getTableLM().getTable().getMarkers();
@@ -695,7 +693,6 @@
         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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java?view=diff&rev=555651&r1=555650&r2=555651
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java Thu Jul 12 07:59:06 2007
@@ -34,8 +34,6 @@
     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 @@
         sb.append(headerElements);
         sb.append(", footer:");
         sb.append(footerElements);
-        sb.append(", inner penalty length:");
-        sb.append(nestedPenaltyLength);
         sb.append(")");
         return sb.toString();
     }

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=555651&r1=555650&r2=555651
==============================================================================
--- 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 12 07:59:06 2007
@@ -32,8 +32,10 @@
 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 @@
          * current one.
          */
         private int width;
+        private int remainingLength;
         private int baseWidth;
         private int totalLength;
         private int includedLength;
@@ -88,8 +91,6 @@
                 }
                 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 @@
             startRow = rowIndex;
             keepWithNextSignal = false;
             computeBaseWidth(rowGroup);
+            remainingLength = totalLength;
             goToNextLegalBreak();
         }
 
@@ -134,8 +136,7 @@
             } 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 @@
 
         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 @@
         }
 
         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 @@
             return includedLength > 0;
         }
 
-        int getLastPenaltyLength() {
-            return lastPenaltyLength;
-        }
-
         boolean isFinished() {
             return includedInLastStep() && (end == elementList.size() - 1);
         }
@@ -223,7 +235,6 @@
     private int activeRowIndex;
     private boolean rowBacktrackForLastStep;
     private boolean skippedStep;
-    private int lastMaxPenaltyLength;
 
     private List activeCells = new LinkedList();
 
@@ -330,8 +341,8 @@
         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 @@
             //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 @@
                         + " - 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 @@
                 }
             }
 
-            //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 @@
                 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 @@
      */
     private int getNextStep() {
         log.trace("Entering getNextStep");
-        this.lastMaxPenaltyLength = 0;
         //Check for forced break conditions
         /*
         if (isBreakCondition()) {
@@ -497,8 +500,6 @@
             if (nextStep > 0) {
                 stepFound = true;
                 minStep = Math.min(minStep, nextStep);
-                lastMaxPenaltyLength = Math.max(lastMaxPenaltyLength, activeCell
-                        .getLastPenaltyLength());
             }
         }
         if (!stepFound) {
@@ -587,5 +588,4 @@
             super(w, null, true);
         }
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org