From a5e511a60828360dd976b1fcbaa2c745a28936ba Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 8 Feb 2005 09:20:41 +0000 Subject: [PATCH] Support for table-cells as direct children of table-body|header|footer. The table-cells are grouped into table-rows using starts-row and ends-row properties during FO tree building so the layout managers don't have to handle both cases. This will hopefully keep the code simpler. Additional accessors on some FO objects. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198391 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/PropertyList.java | 2 +- src/java/org/apache/fop/fo/flow/Table.java | 5 ++ .../org/apache/fop/fo/flow/TableBody.java | 54 +++++++++++++++++-- .../org/apache/fop/fo/flow/TableCell.java | 10 ++++ src/java/org/apache/fop/fo/flow/TableRow.java | 16 +++++- 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java index 0a0c50ae4..64553c156 100644 --- a/src/java/org/apache/fop/fo/PropertyList.java +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -203,7 +203,7 @@ abstract public class PropertyList { * Use that from the nearest ancestor, including self, which generates * reference areas, or from root FO if no ancestor found. */ - protected void setWritingMode() throws PropertyException { + public void setWritingMode() throws PropertyException { FObj p = fobj.findNearestAncestorFObj(); // If this is a RA or the root, use the property value. if (fobj.generatesReferenceAreas() || p == null) { diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index 1cb67c134..d509a3d80 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -200,6 +200,11 @@ public class Table extends FObj { return breakBefore; } + /** @return the "border-collapse" property. */ + public int getBorderCollapse() { + return borderCollapse; + } + /** @return the "border-separation" property. */ public LengthPairProperty getBorderSeparation() { return borderSeparation; diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index 786bd3148..5f30c618a 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,18 @@ package org.apache.fop.fo.flow; // Java +import java.util.Iterator; import java.util.List; 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; import org.apache.fop.fo.properties.CommonRelativePosition; -import org.apache.fop.layoutmgr.table.Body; /** * Class modelling the fo:table-body object. @@ -48,6 +49,8 @@ public class TableBody extends FObj { private int visibility; // End of property values + private PropertyList savedPropertyList; + /** * @param parent FONode that is the parent of the object */ @@ -68,6 +71,9 @@ public class TableBody extends FObj { // borderEndPrecedence = pList.get(PR_BORDER_END_PRECEDENCE); // borderStartPrecedence = pList.get(PR_BORDER_START_PRECEDENCE); visibility = pList.get(PR_VISIBILITY).getEnum(); + + //Used by convertCellsToRows() + savedPropertyList = pList; } /** @@ -82,10 +88,52 @@ public class TableBody extends FObj { */ protected void endOfNode() throws FOPException { getFOEventHandler().endBody(this); + convertCellsToRows(); } /** - * Return the Common Border, Padding, and Background Properties. + * If table-cells are used as direct children of a table-body|header|footer + * they are replace in this method by proper table-rows. + * @throws FOPException if there's a problem binding the TableRows properties. + */ + private void convertCellsToRows() throws FOPException { + try { + if (childNodes.size() == 0 || childNodes.get(0) instanceof TableRow) { + return; + } + //getLogger().debug("Converting cells to rows..."); + List cells = (List)childNodes.clone(); + childNodes.clear(); + Iterator i = cells.iterator(); + TableRow row = null; + while (i.hasNext()) { + TableCell cell = (TableCell)i.next(); + if (cell.startsRow() && (row != null)) { + childNodes.add(row); + row = null; + } + if (row == null) { + row = new TableRow(this); + PropertyList pList = new StaticPropertyList(row, savedPropertyList); + pList.setWritingMode(); + row.bind(pList); + } + row.addReplacedCell(cell); + if (cell.endsRow()) { + childNodes.add(row); + row = null; + } + } + if (row != null) { + childNodes.add(row); + } + } finally { + savedPropertyList = null; //Release reference + } + } + + /** + * @return the Common Border, Padding, and Background Properties. */ public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { return commonBorderPaddingBackground; diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java index 7b4f16f39..e39b23efb 100644 --- a/src/java/org/apache/fop/fo/flow/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -324,6 +324,16 @@ public class TableCell extends FObj { return displayAlign; } + /** @return true if the cell starts a row. */ + public boolean startsRow() { + return (startsRow == EN_TRUE); + } + + /** @return true if the cell ends a row. */ + public boolean endsRow() { + return (endsRow == EN_TRUE); + } + /** * @see org.apache.fop.fo.FObj#getName() */ diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java index 3583b546f..573bc5594 100644 --- a/src/java/org/apache/fop/fo/flow/TableRow.java +++ b/src/java/org/apache/fop/fo/flow/TableRow.java @@ -25,6 +25,7 @@ import org.apache.fop.datatypes.Length; 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.ValidationException; import org.apache.fop.fo.properties.CommonAccessibility; import org.apache.fop.fo.properties.CommonAural; @@ -56,7 +57,7 @@ public class TableRow extends FObj { private KeepProperty keepWithPrevious; private int visibility; // End of property values - + private boolean setup = false; /** @@ -89,6 +90,19 @@ public class TableRow extends FObj { visibility = pList.get(PR_VISIBILITY).getEnum(); } + /** + * Adds a cell to this row (skips marker handling done by FObj.addChildNode(). + * Used by TableBody during the row building process when only cells are + * used as direct children of a table-body/header/footer. + * @param cell cell to add. + */ + protected void addReplacedCell(TableCell cell) { + if (childNodes == null) { + childNodes = new java.util.ArrayList(); + } + childNodes.add(cell); + } + /** * @see org.apache.fop.fo.FONode#startOfNode */ -- 2.39.5