diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2007-11-02 11:01:41 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2007-11-02 11:01:41 +0000 |
commit | 6f01fbd0f9ddeef6669b6b4850cb632772e6bdfb (patch) | |
tree | 2328cd62a6529018c42b97597481c7fe8ebd2009 /src/java/org/apache/fop/fo/flow | |
parent | a3d7ceee3d54b1290b4f705280002d5607a2c69a (diff) | |
download | xmlgraphics-fop-6f01fbd0f9ddeef6669b6b4850cb632772e6bdfb.tar.gz xmlgraphics-fop-6f01fbd0f9ddeef6669b6b4850cb632772e6bdfb.zip |
Reworked the creation of implicit columns to match new behaviour: the number of columns of a table without explicit fo:table-column is set by the row that has the most columns.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@591299 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo/flow')
-rw-r--r-- | src/java/org/apache/fop/fo/flow/Table.java | 76 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/TableBody.java | 16 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/TableCellContainer.java | 35 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/TableColumn.java | 17 |
4 files changed, 82 insertions, 62 deletions
diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index 2dfc06fdf..87f224c65 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -35,6 +35,7 @@ import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.LengthPairProperty; import org.apache.fop.fo.properties.LengthRangeProperty; +import org.apache.fop.fo.properties.TableColLength; import org.xml.sax.Locator; /** @@ -84,6 +85,7 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { private boolean tableBodyFound = false; private boolean hasExplicitColumns = false; + private boolean columnsFinalized = false; /** * The table's property list. Used in case the table has @@ -244,46 +246,68 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } else { columns.add((TableColumn) child); } - return; - case FO_TABLE_FOOTER: - tableFooter = (TableBody) child; break; case FO_TABLE_HEADER: - tableHeader = (TableBody) child; + case FO_TABLE_FOOTER: + case FO_TABLE_BODY: + if (hasExplicitColumns && !columnsFinalized) { + columnsFinalized = true; + finalizeColumns(); + } + switch (childId) { + case FO_TABLE_FOOTER: + tableFooter = (TableBody) child; + break; + case FO_TABLE_HEADER: + tableHeader = (TableBody) child; + break; + default: + super.addChildNode(child); + } break; default: super.addChildNode(child); } } + private void finalizeColumns() throws FOPException { + for (int i = 0; i < columns.size(); i++) { + if (columns.get(i) == null) { + columns.set(i, createImplicitColumn(i + 1)); + } + } + } + /** {@inheritDoc} */ public Table getTable() { return this; } /** - * Adds a default column to the columns list (called from - * TableBody.addChildNode() when the table has no explicit - * columns, and if processing the first row) + * Creates the appropriate number of additional implicit columns to match the given + * column number. Used when the table has no explicit column: the number of columns is + * then determined by the row that has the most columns. * - * @param colWidth the column's width (null if the default should be used) - * @param colNr the column-number from the cell - * @throws FOPException if there was an error creating the property list + * @param columnNumber the table must at least have this number of column + * @throws FOPException if there was an error creating the property list for implicit + * columns */ - void addDefaultColumn(Length colWidth, int colNr) + void ensureColumnNumber(int columnNumber) throws FOPException { + for (int i = columns.size() + 1; i <= columnNumber; i++) { + columns.add(createImplicitColumn(i)); + } + } + + private TableColumn createImplicitColumn(int colNumber) throws FOPException { - TableColumn defaultColumn = new TableColumn(this, true); + TableColumn implicitColumn = new TableColumn(this, true); PropertyList pList = new StaticPropertyList( - defaultColumn, this.propList); + implicitColumn, this.propList); pList.setWritingMode(); - defaultColumn.bind(pList); - if (colWidth != null) { - defaultColumn.setColumnWidth(colWidth); - } - if (colNr != 0) { - defaultColumn.setColumnNumber(colNr); - } - addColumnNode(defaultColumn); + implicitColumn.bind(pList); + implicitColumn.setColumnWidth(new TableColLength(1.0, implicitColumn)); + implicitColumn.setColumnNumber(colNumber); + return implicitColumn; } /** @@ -335,17 +359,13 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } /** - * Returns the column at the given index, if any. + * Returns the column at the given index. * * @param index index of the column to be retrieved, 0-based - * @return the corresponding column, or null if their is no column at the given index + * @return the corresponding column (may be an implicitly created column) */ TableColumn getColumn(int index) { - if (index >= columns.size()) { - return null; - } else { - return (TableColumn) columns.get(index); - } + return (TableColumn) columns.get(index); } /** diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index e18675aa0..72c0ff610 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -19,7 +19,8 @@ package org.apache.fop.fo.flow; -// Java +import java.util.ArrayList; + import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; @@ -76,11 +77,16 @@ public class TableBody extends TableCellContainer { Attributes attlist, PropertyList pList) throws FOPException { if (!inMarker()) { - int cap = getTable().getNumberOfColumns(); - if (cap == 0) { - cap = 10; // Default value for ArrayList + Table t = getTable(); + if (t.hasExplicitColumns()) { + int size = t.getNumberOfColumns(); + pendingSpans = new ArrayList(size); + for (int i = 0; i < size; i++) { + pendingSpans.add(null); + } + } else { + pendingSpans = new ArrayList(); } - pendingSpans = new java.util.ArrayList(cap); columnNumberManager = new ColumnNumberManager(); } super.processNode(elementName, locator, attlist, pList); diff --git a/src/java/org/apache/fop/fo/flow/TableCellContainer.java b/src/java/org/apache/fop/fo/flow/TableCellContainer.java index 348ae93f2..9f9b72d75 100644 --- a/src/java/org/apache/fop/fo/flow/TableCellContainer.java +++ b/src/java/org/apache/fop/fo/flow/TableCellContainer.java @@ -68,14 +68,21 @@ public abstract class TableCellContainer extends TableFObj implements ColumnNumb int rowSpan = cell.getNumberRowsSpanned(); Table t = getTable(); - if (t.hasExplicitColumns() && colNumber + colSpan - 1 > t.getNumberOfColumns()) { - throw new ValidationException(FONode.errorText(locator) + "column-number or number " - + "of cells in the row overflows the number of fo:table-column specified " - + "for the table."); + if (t.hasExplicitColumns()) { + if (colNumber + colSpan - 1 > t.getNumberOfColumns()) { + throw new ValidationException(FONode.errorText(locator) + "column-number or " + + "number of cells in the row overflows the number of fo:table-column " + + "specified for the table."); + } + } else { + t.ensureColumnNumber(colNumber + colSpan - 1); + // re-cap the size of pendingSpans + while (pendingSpans.size() < colNumber + colSpan - 1) { + pendingSpans.add(null); + } } if (firstRow) { handleCellWidth(cell, colNumber, colSpan); - updatePendingSpansSize(cell, colNumber, colSpan); } /* if the current cell spans more than one row, @@ -101,26 +108,12 @@ public abstract class TableCellContainer extends TableFObj implements ColumnNumb for (int i = colNumber; i < colNumber + colSpan; ++i) { TableColumn col = t.getColumn(i - 1); - if (col == null) { - t.addDefaultColumn(colWidth, - i == colNumber - ? cell.getColumnNumber() - : 0); - } else { - if (!col.isDefaultColumn() - && colWidth != null) { - col.setColumnWidth(colWidth); - } + if (colWidth != null) { + col.setColumnWidth(colWidth); } } } - private void updatePendingSpansSize(TableCell cell, int colNumber, int colSpan) { - while (pendingSpans.size() < colNumber + colSpan - 1) { - pendingSpans.add(null); - } - } - /** {@inheritDoc} */ public ColumnNumberManager getColumnNumberManager() { return columnNumberManager; diff --git a/src/java/org/apache/fop/fo/flow/TableColumn.java b/src/java/org/apache/fop/fo/flow/TableColumn.java index 775b27ff3..89d967303 100644 --- a/src/java/org/apache/fop/fo/flow/TableColumn.java +++ b/src/java/org/apache/fop/fo/flow/TableColumn.java @@ -46,7 +46,7 @@ public class TableColumn extends TableFObj { // private int visibility; // End of property values - private boolean defaultColumn; + private boolean implicitColumn; private PropertyList pList = null; /** @@ -58,11 +58,12 @@ public class TableColumn extends TableFObj { /** * @param parent FONode that is the parent of this object - * @param defaultColumn true if this table-column has been manually created as a default column + * @param implicit true if this table-column has automatically been created (does not + * correspond to an explicit fo:table-column in the input document) */ - public TableColumn(FONode parent, boolean defaultColumn) { + public TableColumn(FONode parent, boolean implicit) { super(parent); - this.defaultColumn = defaultColumn; + this.implicitColumn = implicit; } @@ -93,7 +94,7 @@ public class TableColumn extends TableFObj { * warn only for explicit columns */ if (columnWidth.getEnum() == EN_AUTO) { - if (!this.defaultColumn && !getTable().isAutoLayout()) { + if (!this.implicitColumn && !getTable().isAutoLayout()) { log.warn("table-layout=\"fixed\" and column-width unspecified " + "=> falling back to proportional-column-width(1)"); } @@ -105,7 +106,7 @@ public class TableColumn extends TableFObj { * we need a reference to the column's property list * (cleared in Table.endOfNode()) */ - if (!this.defaultColumn) { + if (!this.implicitColumn) { this.pList = pList; } } @@ -199,8 +200,8 @@ public class TableColumn extends TableFObj { * user feedback (see ColumnSetup). * @return true if this table-column has been created as default column */ - public boolean isDefaultColumn() { - return defaultColumn; + public boolean isImplicitColumn() { + return implicitColumn; } /** {@inheritDoc} */ |