From 08fb5bab03609f9513474df98745b6df5c419f4c Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 9 Feb 2005 15:38:15 +0000 Subject: [PATCH] No longer fail when no table-columns are defined. The table creates a "default column" which is used to handle any defaults and inheritance. The columns list is populated with at least the default column. The first row is not yet inspected for determining column widths as described in fixed table layout. (see comment in code) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198407 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/flow/Table.java | 17 ++++++++ .../org/apache/fop/layoutmgr/table/Body.java | 25 +++++------- .../layoutmgr/table/TableLayoutManager.java | 39 +++++++++++++++++-- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index ebaa0ce1f..d82a14631 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -24,6 +24,7 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.StaticPropertyList; import org.apache.fop.fo.properties.CommonAccessibility; import org.apache.fop.fo.properties.CommonAural; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; @@ -73,6 +74,11 @@ public class Table extends FObj { private TableBody tableHeader = null; private TableBody tableFooter = null; + /** + * Default table-column used when no columns are specified. It is used + * to handle inheritance (especially visibility) and defaults properly. */ + private TableColumn defaultColumn; + /** * @param parent FONode that is the parent of this object */ @@ -110,6 +116,12 @@ public class Table extends FObj { tableOmitHeaderAtBreak = pList.get(PR_TABLE_OMIT_HEADER_AT_BREAK).getEnum(); //width = pList.get(PR_WIDTH).getLength(); writingMode = pList.get(PR_WRITING_MODE).getEnum(); + + //Create default column in case no table-columns will be defined. + defaultColumn = new TableColumn(this); + PropertyList colPList = new StaticPropertyList(defaultColumn, pList); + colPList.setWritingMode(); + defaultColumn.bind(colPList); } /** @@ -151,6 +163,11 @@ public class Table extends FObj { return (tableLayout != EN_FIXED); } + /** @return the default table column */ + public TableColumn getDefaultColumn() { + return this.defaultColumn; + } + public List getColumns() { return columns; } diff --git a/src/java/org/apache/fop/layoutmgr/table/Body.java b/src/java/org/apache/fop/layoutmgr/table/Body.java index d52bbc37b..9daef193d 100644 --- a/src/java/org/apache/fop/layoutmgr/table/Body.java +++ b/src/java/org/apache/fop/layoutmgr/table/Body.java @@ -18,6 +18,8 @@ package org.apache.fop.layoutmgr.table; +import java.util.List; + import org.apache.fop.fo.flow.TableBody; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.BlockStackingLayoutManager; @@ -32,9 +34,6 @@ import org.apache.fop.area.Area; import org.apache.fop.area.Block; import org.apache.fop.traits.MinOptMax; -import java.util.ArrayList; -import java.util.List; - /** * LayoutManager for a table-header, table-footer and table body FO. * These fo objects have either rows or cells underneath. @@ -43,19 +42,19 @@ import java.util.List; public class Body extends BlockStackingLayoutManager { private TableBody fobj; - private boolean rows = true; private List columns; private int xoffset; private int yoffset; private int bodyHeight; - private Block curBlockArea; + //private Block curBlockArea; - private List childBreaks = new ArrayList(); + private List childBreaks = new java.util.ArrayList(); /** * Create a new body layout manager. + * @param node the table-body FO */ public Body(TableBody node) { super(node); @@ -84,12 +83,6 @@ public class Body extends BlockStackingLayoutManager { MinOptMax stackSize = new MinOptMax(); BreakPoss lastPos = null; - if (columns == null) { - setFinished(true); - log.warn("ignoring fo:table-body with undefined fo:table-columns"); - return null; - } - while ((curLM = (Row)getChildLM()) != null) { // Make break positions // Set up a LayoutContext @@ -151,7 +144,7 @@ public class Body extends BlockStackingLayoutManager { /** * Set the x offset of this body within the table. * This is used to set the row offsets. - * @param value + * @param off the x offset */ public void setXOffset(int off) { xoffset = off; @@ -185,8 +178,8 @@ public class Body extends BlockStackingLayoutManager { while (parentIter.hasNext()) { LeafPosition lfp = (LeafPosition) parentIter.next(); // Add the block areas to Area - PositionIterator breakPosIter = - new BreakPossPosIter(childBreaks, iStartPos, + PositionIterator breakPosIter + = new BreakPossPosIter(childBreaks, iStartPos, lfp.getLeafPos() + 1); iStartPos = lfp.getLeafPos() + 1; int lastheight = 0; @@ -203,7 +196,7 @@ public class Body extends BlockStackingLayoutManager { flush(); childBreaks.clear(); - curBlockArea = null; + //curBlockArea = null; } /** diff --git a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java index a0dbf5e08..89188f907 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java @@ -21,6 +21,8 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableRow; import org.apache.fop.fo.properties.TableColLength; import org.apache.fop.layoutmgr.BlockStackingLayoutManager; import org.apache.fop.layoutmgr.LayoutManager; @@ -62,6 +64,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { private BreakPoss footerBreak; private int referenceIPD; + private boolean autoLayout = true; //TODO space-before|after: handle space-resolution rules private MinOptMax spaceBefore; @@ -78,13 +81,18 @@ public class TableLayoutManager extends BlockStackingLayoutManager { /** * Create a new table layout manager. - * + * @param node the table FO */ public TableLayoutManager(Table node) { super(node); fobj = node; } + /** @return the table FO */ + public Table getTable() { + return this.fobj; + } + /** * Set the columns for this table. * @@ -119,6 +127,11 @@ public class TableLayoutManager extends BlockStackingLayoutManager { super.initProperties(); spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore).getSpace(); spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter).getSpace(); + + if (!fobj.isAutoLayout() + && fobj.getInlineProgressionDimension().getOptimum().getEnum() != EN_AUTO) { + autoLayout = false; + } } private int getIPIndents() { @@ -164,6 +177,10 @@ public class TableLayoutManager extends BlockStackingLayoutManager { fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, referenceIPD); fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, context.getStackLimit().opt); + if (columns == null) { + createColumnsFromFirstRow(); + } + // either works out table of column widths or if proportional-column-width function // is used works out total factor, so that value of single unit can be computed. int sumCols = 0; @@ -265,6 +282,18 @@ public class TableLayoutManager extends BlockStackingLayoutManager { return null; } + private void createColumnsFromFirstRow() { + this.columns = new java.util.ArrayList(); + //TODO Create columns from first row here + //--> rule 2 in "fixed table layout", see CSS2, 17.5.2 + //Alternative: extend columns on-the-fly, but in this case we need the + //new property evaluation context so proportional-column-width() works + //correctly. + if (columns.size() == 0) { + this.columns.add(new Column(getTable().getDefaultColumn())); + } + } + /** * Get the break possibility and height of the table header or footer. * @@ -316,6 +345,8 @@ public class TableLayoutManager extends BlockStackingLayoutManager { double adjust = layoutContext.getSpaceAdjust(); addBlockSpacing(adjust, spaceBefore); spaceBefore = null; + + int startXOffset = fobj.getCommonMarginBlock().startIndent.getValue(); // add column, body then row areas @@ -329,7 +360,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { List list = pos.list; PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1); while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { - childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); + childLM.setXOffset(startXOffset); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); } @@ -344,7 +375,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { lfp.getLeafPos() + 1); iStartPos = lfp.getLeafPos() + 1; while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { - childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); + childLM.setXOffset(startXOffset); childLM.setYOffset(tableHeight); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); @@ -357,7 +388,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { List list = pos.list; PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1); while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { - childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); + childLM.setXOffset(startXOffset); childLM.setYOffset(tableHeight); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); -- 2.39.5