]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Improve keep handling in table rows
authorKaren Lease <klease@apache.org>
Sun, 1 Dec 2002 11:55:57 +0000 (11:55 +0000)
committerKaren Lease <klease@apache.org>
Sun, 1 Dec 2002 11:55:57 +0000 (11:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195688 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/flow/AbstractTableBody.java
src/org/apache/fop/fo/flow/TableRow.java

index b1657098cdbe06e5a846d6d98d7d5bfe3940e27b..329172512de0a5279a04c3b39a845c09d99219e3 100644 (file)
@@ -124,7 +124,7 @@ public abstract class AbstractTableBody extends FObj {
         area.spaceLeft(), Position.RELATIVE);
         areaContainer.foCreator = this;                  // G Seshadri
         areaContainer.setPage(area.getPage());
-       areaContainer.setParent(area);
+        areaContainer.setParent(area);
         areaContainer.setBackground(propMgr.getBackgroundProps());
         areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
         areaContainer.start();
@@ -152,11 +152,29 @@ public abstract class AbstractTableBody extends FObj {
                                                    == -1) {
                 keepWith.add(lastRow);
             } else {
+                /* This row has no keep-with-previous, or it is the first
+                 * row in this area.
+                 */
                 if (endKeepGroup && keepWith.size() > 0) {
                     keepWith = new ArrayList();
                 }
+                // If we have composed at least one complete row which is not part
+                // of a keep set, we can take following keeps into account again
+                if (endKeepGroup && i > this.marker) {
+                   rowSpanMgr.setIgnoreKeeps(false);
+                }
             }
-
+            
+            /* Tell the row whether it is at the top of this area: if so, the row
+             * should not honor keep-together.
+             */
+            boolean bRowStartsArea = (i == this.marker);
+            if (bRowStartsArea == false && keepWith.size() > 0) {
+                if (children.indexOf(keepWith.get(0)) == this.marker) {
+                   bRowStartsArea = true;
+                }
+            }
+            row.setIgnoreKeepTogether(bRowStartsArea  && startsAC(area));
             int status;
             if (Status.isIncomplete((status = row.layout(areaContainer)))) {
                 // BUG!!! don't distinguish between break-before and after!
@@ -250,5 +268,24 @@ public abstract class AbstractTableBody extends FObj {
         this.resetMarker();
         this.removeID(area.getIDReferences());
     }
-
+    
+    /**
+     * Return true if the passed area is on the left edge of its nearest
+     * absolute AreaContainer (generally a page column).
+     */
+    private boolean startsAC(Area area) {
+        Area parent=null;
+        
+        while ((parent = area.getParent()) != null &&
+               parent.hasNonSpaceChildren() == false) {
+            // The area will be the first non-space child in its parent
+            // Note: it's not added yet!
+            if (parent instanceof AreaContainer &&
+                ((AreaContainer)parent).getPosition() == Position.ABSOLUTE) {
+                return true;
+            }
+            area = parent;
+        }
+        return false;
+    }
 }
index 45d497249b842931e3b6b32f87f8f50ffeba7bb7..e4b7ce48d1d3f0bfa02ef4158a73ee051db80958 100644 (file)
@@ -48,7 +48,9 @@ public class TableRow extends FObj {
     AreaContainer areaContainer;
 
     boolean areaAdded = false;
-
+    
+    boolean bIgnoreKeepTogether = false;
+    
     private RowSpanMgr rowSpanMgr = null;
     private CellArray cellArray = null;
 
@@ -247,7 +249,7 @@ public class TableRow extends FObj {
                               Position.RELATIVE);
         areaContainer.foCreator = this;    // G Seshadri
         areaContainer.setPage(area.getPage());
-       areaContainer.setParent(area);
+        areaContainer.setParent(area);
 
         areaContainer.setBackground(propMgr.getBackgroundProps());
         areaContainer.start();
@@ -303,7 +305,7 @@ public class TableRow extends FObj {
             int rowSpan = cell.getNumRowsSpanned();
             int status;
             if (Status.isIncomplete((status = cell.layout(areaContainer)))) {
-               if ((keepTogether.getType() == KeepValue.KEEP_WITH_ALWAYS)
+               if ((keepTogether.getType() == KeepValue.KEEP_WITH_ALWAYS && bIgnoreKeepTogether==false)
                         || (status == Status.AREA_FULL_NONE)
                         || rowSpan > 1) {
                     // We will put this row into the next column/page
@@ -417,9 +419,10 @@ public class TableRow extends FObj {
     }
 
     public void removeLayout(Area area) {
-        if (areaAdded)
+        if (areaAdded) {
             area.removeChild(areaContainer);
-        areaAdded = false;
+            areaAdded = false;
+        }
         this.resetMarker();
         this.removeID(area.getIDReferences());
     }
@@ -500,5 +503,9 @@ public class TableRow extends FObj {
         }
         return width;
     }
+    
+    void setIgnoreKeepTogether(boolean bIgnoreKeepTogether) {
+        this.bIgnoreKeepTogether = bIgnoreKeepTogether;
+    }
 
 }