]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Better validity checking for table FOs.
authorJoerg Pietschmann <pietsch@apache.org>
Sat, 20 Jul 2002 12:50:00 +0000 (12:50 +0000)
committerJoerg Pietschmann <pietsch@apache.org>
Sat, 20 Jul 2002 12:50:00 +0000 (12:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195013 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/flow/AbstractTableBody.java [new file with mode: 0644]
src/org/apache/fop/fo/flow/TableBody.java
src/org/apache/fop/fo/flow/TableCell.java
src/org/apache/fop/fo/flow/TableColumn.java
src/org/apache/fop/fo/flow/TableRow.java

diff --git a/src/org/apache/fop/fo/flow/AbstractTableBody.java b/src/org/apache/fop/fo/flow/AbstractTableBody.java
new file mode 100644 (file)
index 0000000..c814730
--- /dev/null
@@ -0,0 +1,259 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.fo.flow;
+
+// FOP
+import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.*;
+import org.apache.fop.datatypes.*;
+import org.apache.fop.layout.*;
+import org.apache.fop.apps.FOPException;
+
+// Java
+import java.util.Vector;
+import java.util.Enumeration;
+
+public abstract class AbstractTableBody extends FObj {
+
+    int spaceBefore;
+    int spaceAfter;
+    String id;
+
+    Vector columns;
+    RowSpanMgr rowSpanMgr;    // manage information about spanning rows
+
+    AreaContainer areaContainer;
+
+    public AbstractTableBody(FObj parent, PropertyList propertyList)
+        throws FOPException {
+        super(parent, propertyList);
+        if (!(parent instanceof Table)) {
+          throw new FOPException("A table body must be child of fo:table,"
+                                   + " not " + parent.getName());
+        }
+    }
+
+    public void setColumns(Vector columns) {
+        this.columns = columns;
+    }
+
+    public void setYPosition(int value) {
+        areaContainer.setYPosition(value);
+    }
+
+    public int getYPosition() {
+        return areaContainer.getCurrentYPosition();
+    }
+
+    public int getHeight() {
+        return areaContainer.getHeight() + spaceBefore + spaceAfter;
+    }
+
+    public Status layout(Area area) throws FOPException {
+        if (this.marker == BREAK_AFTER) {
+            return new Status(Status.OK);
+        }
+
+        if (this.marker == START) {
+
+            // Common Accessibility Properties
+            AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
+
+            // Common Aural Properties
+            AuralProps mAurProps = propMgr.getAuralProps();
+
+            // Common Border, Padding, and Background Properties
+            BorderAndPadding bap = propMgr.getBorderAndPadding();
+            BackgroundProps bProps = propMgr.getBackgroundProps();
+
+            // Common Relative Position Properties        
+            RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
+        
+            // this.properties.get("id");
+
+            this.spaceBefore =
+                this.properties.get("space-before.optimum").getLength().mvalue();
+            this.spaceAfter =
+                this.properties.get("space-after.optimum").getLength().mvalue();
+            this.id = this.properties.get("id").getString();
+
+            area.getIDReferences().createID(id);
+
+            if (area instanceof BlockArea) {
+                area.end();
+            }
+
+            if (rowSpanMgr == null) {
+                rowSpanMgr = new RowSpanMgr(columns.size());
+            }
+
+            // if (this.isInListBody) {
+            // startIndent += bodyIndent + distanceBetweenStarts;
+            // }
+
+            this.marker = 0;
+
+        }
+
+        if ((spaceBefore != 0) && (this.marker == 0)) {
+            area.increaseHeight(spaceBefore);
+        }
+
+        if (marker == 0) {
+            // configure id
+            area.getIDReferences().configureID(id, area);
+        }
+
+        int spaceLeft = area.spaceLeft();
+
+        /*
+         * Note: the parent FO must be a Table. The parent Area is the Block
+         * type area created by the Table, which is also a reference area.
+         * The content "width" (IPD) of the TableBody is the same as that
+         * of the containing table area, and its relative position is 0,0.
+         * Strictly speaking (CR), this FO should generate no areas!
+         */
+        this.areaContainer =
+            new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0,
+                              area.getContentHeight(),
+                              area.getContentWidth(),    // IPD
+        area.spaceLeft(), Position.RELATIVE);
+        areaContainer.foCreator = this;                  // G Seshadri
+        areaContainer.setPage(area.getPage());
+        areaContainer.setBackground(propMgr.getBackgroundProps());
+        areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
+        areaContainer.start();
+
+        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
+        areaContainer.setIDReferences(area.getIDReferences());
+
+        Vector keepWith = new Vector();
+        int numChildren = this.children.size();
+        TableRow lastRow = null;
+        boolean endKeepGroup = true;
+        for (int i = this.marker; i < numChildren; i++) {
+            Object child = children.elementAt(i);
+            if (!(child instanceof TableRow)) {
+                throw new FOPException("Currently only Table Rows are supported in table body, header and footer");
+            }
+            TableRow row = (TableRow)child;
+
+            row.setRowSpanMgr(rowSpanMgr);
+            row.setColumns(columns);
+            row.doSetup(areaContainer);
+            if (row.getKeepWithPrevious().getType()
+                    != KeepValue.KEEP_WITH_AUTO && lastRow != null
+                                                && keepWith.indexOf(lastRow)
+                                                   == -1) {
+                keepWith.addElement(lastRow);
+            } else {
+                if (endKeepGroup && keepWith.size() > 0) {
+                    keepWith = new Vector();
+                }
+            }
+
+            Status status;
+            if ((status = row.layout(areaContainer)).isIncomplete()) {
+                // BUG!!! don't distinguish between break-before and after!
+                if (status.isPageBreak()) {
+                    this.marker = i;
+                    area.addChild(areaContainer);
+                    // areaContainer.end();
+
+                    area.increaseHeight(areaContainer.getHeight());
+                    area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
+                    if (i == numChildren - 1) {
+                        this.marker = BREAK_AFTER;
+                        if (spaceAfter != 0) {
+                            area.increaseHeight(spaceAfter);
+                        }
+                    }
+                    return status;
+                }
+                if ((keepWith.size() > 0)
+                    && (!rowSpanMgr.ignoreKeeps())) {
+                    // && status.getCode() == Status.AREA_FULL_NONE
+                    // FIXME!!! Handle rows spans!!!
+                    row.removeLayout(areaContainer);
+                    for (Enumeration e = keepWith.elements();
+                            e.hasMoreElements(); ) {
+                        TableRow tr = (TableRow)e.nextElement();
+                        tr.removeLayout(areaContainer);
+                        i--;
+                    }
+                    if (i == 0) {
+                        resetMarker();
+
+                        // Fix for infinite loop bug if keeps are too big for page
+                        rowSpanMgr.setIgnoreKeeps(true);
+
+                        return new Status(Status.AREA_FULL_NONE);
+                    }
+                }
+                this.marker = i;
+                if ((i != 0) && (status.getCode() == Status.AREA_FULL_NONE)) {
+                    status = new Status(Status.AREA_FULL_SOME);
+                }
+                if (!((i == 0) && (areaContainer.getContentHeight() <= 0))) {
+                    area.addChild(areaContainer);
+                    // areaContainer.end();
+
+                    area.increaseHeight(areaContainer.getHeight());
+                    area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
+                }
+
+                // Fix for infinite loop bug if spanned rows are too big for page
+                rowSpanMgr.setIgnoreKeeps(true);
+
+                return status;
+            } else if (status.getCode() == Status.KEEP_WITH_NEXT
+                       || rowSpanMgr.hasUnfinishedSpans()) {
+                keepWith.addElement(row);
+                endKeepGroup = false;
+            } else {
+                endKeepGroup = true;
+            }
+            lastRow = row;
+            area.setMaxHeight(area.getMaxHeight() - spaceLeft
+                              + this.areaContainer.getMaxHeight());
+            spaceLeft = area.spaceLeft();
+        }
+        area.addChild(areaContainer);
+        areaContainer.end();
+
+        area.increaseHeight(areaContainer.getHeight());
+
+        area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
+
+        if (spaceAfter != 0) {
+            area.increaseHeight(spaceAfter);
+            area.setMaxHeight(area.getMaxHeight() - spaceAfter);
+        }
+
+        if (area instanceof BlockArea) {
+            area.start();
+        }
+
+        return new Status(Status.OK);
+    }
+
+    public void removeLayout(Area area) {
+        if (areaContainer != null) {
+            area.removeChild(areaContainer);
+        }
+        if (spaceBefore != 0) {
+            area.increaseHeight(-spaceBefore);
+        }
+        if (spaceAfter != 0) {
+            area.increaseHeight(-spaceAfter);
+        }
+        this.resetMarker();
+        this.removeID(area.getIDReferences());
+    }
+
+}
index 10dba40c8998cbea8fcb8ce519a60258e6d17d44..f153bfe7b7a71ebac8c4754e230de4386546bbae 100644 (file)
@@ -18,7 +18,7 @@ import org.apache.fop.apps.FOPException;
 import java.util.Vector;
 import java.util.Enumeration;
 
-public class TableBody extends FObj {
+public class TableBody extends AbstractTableBody {
 
     public static class Maker extends FObj.Maker {
         public FObj make(FObj parent,
@@ -32,236 +32,9 @@ public class TableBody extends FObj {
         return new TableBody.Maker();
     }
 
-    int spaceBefore;
-    int spaceAfter;
-    String id;
-
-    Vector columns;
-    RowSpanMgr rowSpanMgr;    // manage information about spanning rows
-
-    AreaContainer areaContainer;
-
     public TableBody(FObj parent, PropertyList propertyList) {
         super(parent, propertyList);
         this.name = "fo:table-body";
     }
 
-    public void setColumns(Vector columns) {
-        this.columns = columns;
-    }
-
-    public void setYPosition(int value) {
-        areaContainer.setYPosition(value);
-    }
-
-    public int getYPosition() {
-        return areaContainer.getCurrentYPosition();
-    }
-
-    public int getHeight() {
-        return areaContainer.getHeight() + spaceBefore + spaceAfter;
-    }
-
-    public Status layout(Area area) throws FOPException {
-        if (this.marker == BREAK_AFTER) {
-            return new Status(Status.OK);
-        }
-
-        if (this.marker == START) {
-
-            // Common Accessibility Properties
-            AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
-
-            // Common Aural Properties
-            AuralProps mAurProps = propMgr.getAuralProps();
-
-            // Common Border, Padding, and Background Properties
-            BorderAndPadding bap = propMgr.getBorderAndPadding();
-            BackgroundProps bProps = propMgr.getBackgroundProps();
-
-            // Common Relative Position Properties        
-            RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
-        
-            // this.properties.get("id");
-
-            this.spaceBefore =
-                this.properties.get("space-before.optimum").getLength().mvalue();
-            this.spaceAfter =
-                this.properties.get("space-after.optimum").getLength().mvalue();
-            this.id = this.properties.get("id").getString();
-
-            area.getIDReferences().createID(id);
-
-            if (area instanceof BlockArea) {
-                area.end();
-            }
-
-            if (rowSpanMgr == null) {
-                rowSpanMgr = new RowSpanMgr(columns.size());
-            }
-
-            // if (this.isInListBody) {
-            // startIndent += bodyIndent + distanceBetweenStarts;
-            // }
-
-            this.marker = 0;
-
-        }
-
-        if ((spaceBefore != 0) && (this.marker == 0)) {
-            area.increaseHeight(spaceBefore);
-        }
-
-        if (marker == 0) {
-            // configure id
-            area.getIDReferences().configureID(id, area);
-        }
-
-        int spaceLeft = area.spaceLeft();
-
-        /*
-         * Note: the parent FO must be a Table. The parent Area is the Block
-         * type area created by the Table, which is also a reference area.
-         * The content "width" (IPD) of the TableBody is the same as that
-         * of the containing table area, and its relative position is 0,0.
-         * Strictly speaking (CR), this FO should generate no areas!
-         */
-        this.areaContainer =
-            new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0,
-                              area.getContentHeight(),
-                              area.getContentWidth(),    // IPD
-        area.spaceLeft(), Position.RELATIVE);
-        areaContainer.foCreator = this;                  // G Seshadri
-        areaContainer.setPage(area.getPage());
-        areaContainer.setBackground(propMgr.getBackgroundProps());
-        areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
-        areaContainer.start();
-
-        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
-        areaContainer.setIDReferences(area.getIDReferences());
-
-        Vector keepWith = new Vector();
-        int numChildren = this.children.size();
-        TableRow lastRow = null;
-        boolean endKeepGroup = true;
-        for (int i = this.marker; i < numChildren; i++) {
-            Object child = children.elementAt(i);
-            if (!(child instanceof TableRow)) {
-                throw new FOPException("Currently only Table Rows are supported in table body, header and footer");
-            }
-            TableRow row = (TableRow)child;
-
-            row.setRowSpanMgr(rowSpanMgr);
-            row.setColumns(columns);
-            row.doSetup(areaContainer);
-            if (row.getKeepWithPrevious().getType()
-                    != KeepValue.KEEP_WITH_AUTO && lastRow != null
-                                                && keepWith.indexOf(lastRow)
-                                                   == -1) {
-                keepWith.addElement(lastRow);
-            } else {
-                if (endKeepGroup && keepWith.size() > 0) {
-                    keepWith = new Vector();
-                }
-            }
-
-            Status status;
-            if ((status = row.layout(areaContainer)).isIncomplete()) {
-                // BUG!!! don't distinguish between break-before and after!
-                if (status.isPageBreak()) {
-                    this.marker = i;
-                    area.addChild(areaContainer);
-                    // areaContainer.end();
-
-                    area.increaseHeight(areaContainer.getHeight());
-                    area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
-                    if (i == numChildren - 1) {
-                        this.marker = BREAK_AFTER;
-                        if (spaceAfter != 0) {
-                            area.increaseHeight(spaceAfter);
-                        }
-                    }
-                    return status;
-                }
-                if ((keepWith.size() > 0)
-                    && (!rowSpanMgr.ignoreKeeps())) {
-                    // && status.getCode() == Status.AREA_FULL_NONE
-                    // FIXME!!! Handle rows spans!!!
-                    row.removeLayout(areaContainer);
-                    for (Enumeration e = keepWith.elements();
-                            e.hasMoreElements(); ) {
-                        TableRow tr = (TableRow)e.nextElement();
-                        tr.removeLayout(areaContainer);
-                        i--;
-                    }
-                    if (i == 0) {
-                        resetMarker();
-
-                        // Fix for infinite loop bug if keeps are too big for page
-                        rowSpanMgr.setIgnoreKeeps(true);
-
-                        return new Status(Status.AREA_FULL_NONE);
-                    }
-                }
-                this.marker = i;
-                if ((i != 0) && (status.getCode() == Status.AREA_FULL_NONE)) {
-                    status = new Status(Status.AREA_FULL_SOME);
-                }
-                if (!((i == 0) && (areaContainer.getContentHeight() <= 0))) {
-                    area.addChild(areaContainer);
-                    // areaContainer.end();
-
-                    area.increaseHeight(areaContainer.getHeight());
-                    area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
-                }
-
-                // Fix for infinite loop bug if spanned rows are too big for page
-                rowSpanMgr.setIgnoreKeeps(true);
-
-                return status;
-            } else if (status.getCode() == Status.KEEP_WITH_NEXT
-                       || rowSpanMgr.hasUnfinishedSpans()) {
-                keepWith.addElement(row);
-                endKeepGroup = false;
-            } else {
-                endKeepGroup = true;
-            }
-            lastRow = row;
-            area.setMaxHeight(area.getMaxHeight() - spaceLeft
-                              + this.areaContainer.getMaxHeight());
-            spaceLeft = area.spaceLeft();
-        }
-        area.addChild(areaContainer);
-        areaContainer.end();
-
-        area.increaseHeight(areaContainer.getHeight());
-
-        area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
-
-        if (spaceAfter != 0) {
-            area.increaseHeight(spaceAfter);
-            area.setMaxHeight(area.getMaxHeight() - spaceAfter);
-        }
-
-        if (area instanceof BlockArea) {
-            area.start();
-        }
-
-        return new Status(Status.OK);
-    }
-
-    public void removeLayout(Area area) {
-        if (areaContainer != null) {
-            area.removeChild(areaContainer);
-        }
-        if (spaceBefore != 0) {
-            area.increaseHeight(-spaceBefore);
-        }
-        if (spaceAfter != 0) {
-            area.increaseHeight(-spaceAfter);
-        }
-        this.resetMarker();
-        this.removeID(area.getIDReferences());
-    }
-
 }
index ba728190fc300d50f4008e4fdeaedf9524f2750d..83571ae4a276f970fb6d97ffec22f06af5a4484a 100644 (file)
@@ -95,9 +95,14 @@ public class TableCell extends FObj {
 
     AreaContainer cellArea;
 
-    public TableCell(FObj parent, PropertyList propertyList) {
+    public TableCell(FObj parent, PropertyList propertyList)
+        throws FOPException {
         super(parent, propertyList);
         this.name = "fo:table-cell";
+        if (!(parent instanceof TableRow)) {
+            throw new FOPException("A table cell must be child of fo:table-row,"
+                                   + " not " + parent.getName());
+        }
         doSetup();    // init some basic property values
     }
 
index 11e2a5e3dfb65ff6ce08ffaa09d9d394b3f8e364..2a3b4a0e12d0958eca32698202ed153a796007ab 100644 (file)
@@ -38,9 +38,14 @@ public class TableColumn extends FObj {
         return new TableColumn.Maker();
     }
 
-    public TableColumn(FObj parent, PropertyList propertyList) {
+    public TableColumn(FObj parent, PropertyList propertyList)
+        throws FOPException {
         super(parent, propertyList);
         this.name = "fo:table-column";
+        if (!(parent instanceof Table)) {
+            throw new FOPException("A table column must be child of fo:table, not "
+                                   + parent.getName());
+        }
     }
 
     public Length getColumnWidthAsLength() {
index 83762c8b9bede2ce11005c1610dfeb9604d4bfc2..2eb4e75bd6d3f2d216577ffcb460791ab13097e5 100644 (file)
@@ -171,9 +171,15 @@ public class TableRow extends FObj {
     }
 
 
-    public TableRow(FObj parent, PropertyList propertyList) {
+    public TableRow(FObj parent, PropertyList propertyList)
+        throws FOPException {
         super(parent, propertyList);
         this.name = "fo:table-row";
+        if (!(parent instanceof AbstractTableBody)) {
+            throw new FOPException("A table row must be child of fo:table-body,"
+                                   + " fo:table-header or fo:table-footer, not "
+                                   + parent.getName());
+        }
     }
 
     public void setColumns(Vector columns) {