Author: vhennebert
Date: Mon Feb 11 10:10:09 2008
New Revision: 620558

URL: http://svn.apache.org/viewvc?rev=620558&view=rev
Log:
Added full support for breaks inside table-cell elements

Added:
    
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_break-after_inside.xml
   (with props)
    
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_break-before_inside.xml
   (with props)
    
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_breaks.xml
   (with props)
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
    xmlgraphics/fop/trunk/status.xml

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?rev=620558&r1=620557&r2=620558&view=diff
==============================================================================
--- 
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 
Mon Feb 11 10:10:09 2008
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.flow.table.ConditionalBorder;
 import org.apache.fop.fo.flow.table.EffRow;
 import org.apache.fop.fo.flow.table.GridUnit;
@@ -96,6 +97,13 @@
         /** Length of the penalty ending this step, if any. */
         private int penaltyLength;
         /**
+         * One of [EMAIL PROTECTED] Constants#EN_AUTO}, [EMAIL PROTECTED] 
Constants#EN_COLUMN},
+         * [EMAIL PROTECTED] Constants#EN_PAGE}, [EMAIL PROTECTED] 
Constants#EN_EVEN_PAGE},
+         * [EMAIL PROTECTED] Constants#EN_ODD_PAGE}. Set to auto if the break 
isn't at a penalty
+         * element.
+         */
+        private int breakClass;
+        /**
          * Length of the optional content at the beginning of the step. That 
is, content
          * that will not appear if this step starts a new page.
          */
@@ -117,6 +125,7 @@
             this.totalLength   = other.totalLength;
             this.penaltyLength = other.penaltyLength;
             this.condBeforeContentLength = other.condBeforeContentLength;
+            this.breakClass    = other.breakClass;
         }
 
         /** [EMAIL PROTECTED] */
@@ -210,6 +219,7 @@
     private void gotoNextLegalBreak() {
         afterNextStep.penaltyLength = 0;
         afterNextStep.condBeforeContentLength = 0;
+        afterNextStep.breakClass = Constants.EN_AUTO;
         boolean breakFound = false;
         boolean prevIsBox = false;
         boolean boxFound = false;
@@ -219,8 +229,12 @@
                 prevIsBox = false;
                 if (el.getP() < KnuthElement.INFINITE) {
                     // First legal break point
-                    afterNextStep.penaltyLength = el.getW();
                     breakFound = true;
+                    afterNextStep.penaltyLength = el.getW();
+                    KnuthPenalty p = (KnuthPenalty) el;
+                    if (p.isForcedBreak()) {
+                        afterNextStep.breakClass = p.getBreakClass();
+                    }
                 }
             } else if (el.isGlue()) {
                 if (prevIsBox) {
@@ -276,7 +290,7 @@
      * @see #signalRowLastStep(int)
      */
     private void increaseCurrentStep(int limit) {
-        while (afterNextStep.totalLength <= limit) {
+        while (afterNextStep.totalLength <= limit && nextStep.breakClass == 
Constants.EN_AUTO) {
             nextStep.set(afterNextStep);
             if (afterNextStep.end >= elementList.size() - 1) {
                 break;
@@ -338,11 +352,18 @@
      * its own step may be included or not.
      * 
      * @param minStep length of the chosen next step
+     * @return the break class of the step, if any. One of [EMAIL PROTECTED] 
Constants#EN_AUTO},
+     * [EMAIL PROTECTED] Constants#EN_COLUMN}, [EMAIL PROTECTED] 
Constants#EN_PAGE},
+     * [EMAIL PROTECTED] Constants#EN_EVEN_PAGE}, [EMAIL PROTECTED] 
Constants#EN_ODD_PAGE}. EN_AUTO if this
+     * cell's step is not included in the next step.
      */
-    void signalNextStep(int minStep) {
+    int signalNextStep(int minStep) {
         if (nextStep.totalLength <= minStep) {
             includedLength = nextStep.contentLength;
             remainingLength = totalLength - includedLength - 
afterNextStep.condBeforeContentLength;
+            return nextStep.breakClass;
+        } else {
+            return Constants.EN_AUTO;
         }
     }
 

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?rev=620558&r1=620557&r2=620558&view=diff
==============================================================================
--- 
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 
Mon Feb 11 10:10:09 2008
@@ -84,6 +84,13 @@
      */
     private boolean rowHeightSmallerThanFirstStep;
 
+    /**
+     * The class of the next break. One of [EMAIL PROTECTED] 
Constants#EN_AUTO},
+     * [EMAIL PROTECTED] Constants#EN_COLUMN}, [EMAIL PROTECTED] 
Constants#EN_PAGE},
+     * [EMAIL PROTECTED] Constants#EN_EVEN_PAGE}, [EMAIL PROTECTED] 
Constants#EN_ODD_PAGE}. Defaults to
+     * EN_AUTO.
+     */
+    private int nextBreakClass;
 
     /**
      * Main constructor
@@ -190,18 +197,10 @@
                 }
             }
 
-            boolean forcedBreak = false;
-            int breakClass = -1;
             //Put all involved grid units into a list
             List cellParts = new java.util.ArrayList(columnCount);
             for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
                 ActiveCell activeCell = (ActiveCell) iter.next();
-                if (activeCell.contributesContent()) {
-                    forcedBreak = activeCell.isLastForcedBreak();
-                    if (forcedBreak) {
-                        breakClass = activeCell.getLastBreakClass();
-                    }
-                }
                 CellPart part = activeCell.createCellPart();
                 cellParts.add(part);
                 if (returnList.size() == 0 && part.isFirstPart()
@@ -244,14 +243,15 @@
             if (signalKeepWithNext || getTableLM().mustKeepTogether()) {
                 p = KnuthPenalty.INFINITE;
             }
-            if (forcedBreak) {
+            if (nextBreakClass != Constants.EN_AUTO) {
+                log.trace("Forced break encountered");
                 p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in 
XSL 1.0)
             }
             if (rowHeightSmallerThanFirstStep) {
                 rowHeightSmallerThanFirstStep = false;
                 p = KnuthPenalty.INFINITE;
             }
-            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, 
breakClass, context));
+            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, 
nextBreakClass, context));
             if (penaltyOrGlueLen < 0) {
                 returnList.add(new KnuthGlue(-penaltyOrGlueLen, 0, 0, new 
Position(null), true));
             }
@@ -378,9 +378,36 @@
      * @param step the next step
      */
     private void signalNextStep(int step) {
+        nextBreakClass = Constants.EN_AUTO;
         for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
             ActiveCell activeCell = (ActiveCell) iter.next();
-            activeCell.signalNextStep(step);
+            nextBreakClass = compareBreakClasses(nextBreakClass, 
activeCell.signalNextStep(step));
+        }
+    }
+
+    // TODO replace that with a proper 1.5 enumeration ASAP
+    // TODO this has nothing to do here
+    private static int getBreakClassPriority(int breakClass) {
+        switch (breakClass) {
+        case Constants.EN_AUTO:      return 0;
+        case Constants.EN_COLUMN:    return 1;
+        case Constants.EN_PAGE:      return 2;
+        case Constants.EN_EVEN_PAGE: return 3;
+        case Constants.EN_ODD_PAGE:  return 3;
+        default: throw new IllegalArgumentException();
+        }
+    }
+
+    // TODO even-page and odd-page can't be compared to each other and instead 
create a
+    // conflict situation. For now the first encountered break will win, but 
eventually
+    // some warning message should be sent to the user.
+    private static int compareBreakClasses(int b1, int b2) {
+        int p1 = getBreakClassPriority(b1);
+        int p2 = getBreakClassPriority(b2);
+        if (p1 < p2) {
+            return b2;
+        } else {
+            return b1;
         }
     }
 

Modified: xmlgraphics/fop/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=620558&r1=620557&r2=620558&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Mon Feb 11 10:10:09 2008
@@ -28,6 +28,9 @@
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Layout" dev="VH" type="add">
+        Added full support for breaks inside the cells of a table.
+      </action>
       <action context="Code" dev="AD" type="fix" fixes-bug="41631">
         Added correct percentage resolution for arguments to the 
proportional-column-width() function.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to