]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Move the creation of GridUnitParts into ActiveCell
authorVincent Hennebert <vhennebert@apache.org>
Thu, 12 Jul 2007 16:11:32 +0000 (16:11 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Thu, 12 Jul 2007 16:11:32 +0000 (16:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@555677 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java
src/java/org/apache/fop/layoutmgr/table/TableStepper.java

index 52227ef3004e28e0b1f4fc782809631d96a99902..0dcb785fcedf12acb621adbe9a27fe8717d7cbd8 100644 (file)
@@ -62,4 +62,9 @@ class GridUnitPart {
         return sb.toString();
     }
 
+    boolean mustKeepWithPrevious() {
+        return pgu.getFlag(GridUnit.KEEP_WITH_PREVIOUS_PENDING)
+                || (pgu.getRow() != null && pgu.getRow().mustKeepWithPrevious());
+    }
+
 }
index b36930ecbf5affeff80fc248facc65fc704c10e7..43eb690a2bb56978acd449a91350b553e259db2b 100644 (file)
@@ -222,7 +222,37 @@ public class TableStepper {
         boolean isFinished() {
             return includedInLastStep() && (end == elementList.size() - 1);
         }
-    }
+
+        GridUnitPart createGridUnitPart() {
+            if (end + 1 == elementList.size()) {
+                if (pgu.getFlag(GridUnit.KEEP_WITH_NEXT_PENDING)) {
+                    log.debug("PGU has pending keep-with-next");
+                    keepWithNextSignal = true;
+                }
+                if (pgu.getRow() != null && pgu.getRow().mustKeepWithNext()) {
+                    log.debug("table-row causes keep-with-next");
+                    keepWithNextSignal = true;
+                }
+            }
+            if (start == 0 && end == 0
+                    && elementList.size() == 1
+                    && elementList.get(0) instanceof KnuthBoxCellWithBPD) {
+                //Special case: Cell with fixed BPD
+                return new GridUnitPart(pgu, 0, pgu.getElements().size() - 1);
+            } else {
+                return new GridUnitPart(pgu, start, end);
+            }
+        }
+
+        boolean isLastForcedBreak() {
+            return ((KnuthElement)elementList.get(end)).isForcedBreak();
+        }
+
+        int getLastBreakClass() {
+            return ((KnuthPenalty)elementList.get(end)).getBreakClass();
+        }
+}
+
     /** Logger **/
     private static Log log = LogFactory.getLog(TableStepper.class);
 
@@ -352,43 +382,14 @@ public class TableStepper {
             for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
                 ActiveCell activeCell = (ActiveCell) iter.next();
                 if (activeCell.contributesContent()) {
-                    PrimaryGridUnit pgu = activeCell.pgu;
-                    if (activeCell.start == 0 && activeCell.end == 0
-                            && activeCell.elementList.size() == 1
-                            && activeCell.elementList.get(0) instanceof KnuthBoxCellWithBPD) {
-                        //Special case: Cell with fixed BPD
-                        gridUnitParts.add(new GridUnitPart(pgu,
-                                0, pgu.getElements().size() - 1));
-                    } else {
-                        gridUnitParts.add(new GridUnitPart(pgu, activeCell.start, activeCell.end));
-                        if (((KnuthElement)activeCell.elementList.get(activeCell.end)).isForcedBreak()) {
-                            forcedBreak = true;
-                            breakClass = ((KnuthPenalty)activeCell.elementList.get(activeCell.end)).getBreakClass();
-                        }
-                    }
-                    if (activeCell.end + 1 == activeCell.elementList.size()) {
-                        if (pgu.getFlag(GridUnit.KEEP_WITH_NEXT_PENDING)) {
-                            log.debug("PGU has pending keep-with-next");
-                            activeCell.keepWithNextSignal = true;
-                        }
-                        if (pgu.getRow() != null && pgu.getRow().mustKeepWithNext()) {
-                            log.debug("table-row causes keep-with-next");
-                            activeCell.keepWithNextSignal = true;
-                        }
+                    GridUnitPart gup = activeCell.createGridUnitPart();
+                    gridUnitParts.add(gup);
+                    forcedBreak = activeCell.isLastForcedBreak();
+                    if (forcedBreak) {
+                        breakClass = activeCell.getLastBreakClass();
                     }
-                    if (activeCell.start == 0 && activeCell.end >= 0) {
-                        if (pgu.getFlag(GridUnit.KEEP_WITH_PREVIOUS_PENDING)) {
-                            log.debug("PGU has pending keep-with-previous");
-                            if (returnList.size() == 0) {
-                                context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
-                            }
-                        }
-                        if (pgu.getRow() != null && pgu.getRow().mustKeepWithPrevious()) {
-                            log.debug("table-row causes keep-with-previous");
-                            if (returnList.size() == 0) {
-                                context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
-                            }
-                        }
+                    if (returnList.size() == 0 && gup.isFirstPart() && gup.mustKeepWithPrevious()) {
+                        context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
                     }
                 }
             }