From 94a6ff7f78c00f612249323b06179e902f277a48 Mon Sep 17 00:00:00 2001 From: Peter Herweg Date: Wed, 25 Jan 2006 19:11:15 +0000 Subject: [PATCH] added support for number-columns-spanned and number-rows-spanned in the same cell git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@372292 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/rtf/RTFHandler.java | 90 ++++++++++++++----- .../rtf/rtflib/rtfdoc/ITableColumnsInfo.java | 6 ++ .../rtf/rtflib/rtfdoc/RtfTableCell.java | 2 +- .../render/rtf/rtflib/tools/TableContext.java | 52 ++++++++++- 4 files changed, 124 insertions(+), 26 deletions(-) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 7e558bab3..f7c23abe6 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -537,11 +537,15 @@ public class RTFHandler extends FOEventHandler { } try { - Integer iWidth = new Integer(tc.getColumnWidth().getValue() / 1000); + Integer iWidth = + new Integer(tc.getColumnWidth().getValue() / 1000); String strWidth = iWidth.toString() + "pt"; - Float width = new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)); + Float width = new Float( + FoUnitsConverter.getInstance().convertToTwips(strWidth)); builderContext.getTableContext().setNextColumnWidth(width); - builderContext.getTableContext().setNextColumnRowSpanning(new Integer(0), null); + builderContext.getTableContext().setNextColumnRowSpanning( + new Integer(0), null); + builderContext.getTableContext().setNextFirstSpanningCol(false); } catch (Exception e) { log.error("startColumn: " + e.getMessage()); throw new RuntimeException(e.getMessage()); @@ -722,6 +726,31 @@ public class RTFHandler extends FOEventHandler { if (bDefer) { return; } + + try { + TableContext tctx = builderContext.getTableContext(); + final RtfTableRow row = (RtfTableRow)builderContext.getContainer(RtfTableRow.class, + true, null); + + //while the current column is in row-spanning, act as if + //a vertical merged cell would have been specified. + while (tctx.getNumberOfColumns() > tctx.getColumnIndex() + && tctx.getColumnRowSpanningNumber().intValue() > 0) { + RtfTableCell vCell = row.newTableCellMergedVertically( + (int)tctx.getColumnWidth(), + tctx.getColumnRowSpanningAttrs()); + + if (!tctx.getFirstSpanningCol()) { + vCell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS); + } + + tctx.selectNextColumn(); + } + } catch (Exception e) { + log.error("endRow: " + e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + builderContext.popContainer(); builderContext.getTableContext().decreaseRowSpannings(); @@ -748,8 +777,14 @@ public class RTFHandler extends FOEventHandler { //a vertical merged cell would have been specified. while (tctx.getNumberOfColumns() > tctx.getColumnIndex() && tctx.getColumnRowSpanningNumber().intValue() > 0) { - row.newTableCellMergedVertically((int)tctx.getColumnWidth(), + RtfTableCell vCell = row.newTableCellMergedVertically( + (int)tctx.getColumnWidth(), tctx.getColumnRowSpanningAttrs()); + + if (!tctx.getFirstSpanningCol()) { + vCell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS); + } + tctx.selectNextColumn(); } @@ -759,37 +794,50 @@ public class RTFHandler extends FOEventHandler { // create an RtfTableCell in the current RtfTableRow RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc); RtfTableCell cell = row.newTableCell((int)width, atts); + + //process number-rows-spanned attribute + if (numberRowsSpanned > 1) { + // Start vertical merge + cell.setVMerge(RtfTableCell.MERGE_START); -// process number-columns-spanned attribute + // set the number of rows spanned + tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), + cell.getRtfAttributes()); + } else { + tctx.setCurrentColumnRowSpanning( + new Integer(numberRowsSpanned), null); + } + + //process number-columns-spanned attribute if (numberColumnsSpanned > 0) { // Get the number of columns spanned RtfTable table = row.getTable(); + tctx.setCurrentFirstSpanningCol(true); // We widthdraw one cell because the first cell is already created // (it's the current cell) ! - int i = numberColumnsSpanned - 1; - while (i > 0) { + for (int i = 0; i < numberColumnsSpanned - 1; ++i) { tctx.selectNextColumn(); - row.newTableCellMergedHorizontally( + tctx.setCurrentFirstSpanningCol(false); + RtfTableCell hCell = row.newTableCellMergedHorizontally( 0, null); - i--; + if (numberRowsSpanned > 1) { + // Start vertical merge + hCell.setVMerge(RtfTableCell.MERGE_START); + + // set the number of rows spanned + tctx.setCurrentColumnRowSpanning( + new Integer(numberRowsSpanned), + cell.getRtfAttributes()); + } else { + tctx.setCurrentColumnRowSpanning( + new Integer(numberRowsSpanned), null); + } } } - //process number-rows-spanned attribute - if (numberRowsSpanned > 1) { - // Start vertical merge - cell.setVMerge(RtfTableCell.MERGE_START); - - // set the number of rows spanned - tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), - cell.getRtfAttributes()); - } else { - tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), null); - } - builderContext.pushContainer(cell); } catch (Exception e) { log.error("startCell: " + e.getMessage()); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java index 1f0f2c400..6da766988 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java @@ -50,4 +50,10 @@ public interface ITableColumnsInfo { /** @return number of columns */ int getNumberOfColumns(); + + /** + * + * @return true, if it's the first of multiple spanning columns + */ + public boolean getFirstSpanningCol(); } \ No newline at end of file diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java index f55940a2f..1b4a26fc4 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java @@ -225,7 +225,7 @@ public class RtfTableCell if (attrib.getValue("number-columns-spanned") != null) { // Get the number of columns spanned int nbMergedCells = ((Integer)attrib.getValue("number-columns-spanned")).intValue(); - + RtfTable tab = getRow().getTable(); // Get the context of the current table in order to get the width of each column diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java index fadb5236f..0f5f67635 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java @@ -45,7 +45,6 @@ public class TableContext implements ITableColumnsInfo { private int colIndex; /** - * Added by Peter Herweg on 2002-06-29 * This ArrayList contains one element for each column in the table. * value == 0 means there is no row-spanning * value > 0 means there is row-spanning @@ -54,13 +53,19 @@ public class TableContext implements ITableColumnsInfo { private final List colRowSpanningNumber = new java.util.ArrayList(); /** - * Added by Peter Herweg on 2002-06-29 * If there has a vertical merged cell to be created, its attributes are * inherited from the corresponding MERGE_START-cell. * For this purpose the attributes of a cell are stored in this array, as soon * as a number-rows-spanned attribute has been found. */ private final List colRowSpanningAttrs = new java.util.ArrayList(); + + /** + * This ArrayList contains one element for each column in the table. + * value == true means, it's the first of multiple spanned columns + * value == false meanst, it's NOT the first of multiple spanned columns + */ + private final List colFirstSpanningCol = new java.util.ArrayList(); private boolean bNextRowBelongsToHeader = false; @@ -113,6 +118,15 @@ public class TableContext implements ITableColumnsInfo { public Integer getColumnRowSpanningNumber() { return (Integer)colRowSpanningNumber.get(colIndex); } + + /** + * + * @return true, if it's the first of multiple spanning columns + */ + public boolean getFirstSpanningCol() { + Boolean b = (Boolean) colFirstSpanningCol.get(colIndex); + return b.booleanValue(); + } /** * @@ -141,6 +155,31 @@ public class TableContext implements ITableColumnsInfo { colRowSpanningNumber.add(iRowSpanning); colRowSpanningAttrs.add(colIndex, attrs); } + + /** + * + * @param bFirstSpanningCol specifies, if it's the first of + * multiple spanned columns + */ + public void setCurrentFirstSpanningCol( + boolean bFirstSpanningCol) { + + if (colIndex < colRowSpanningNumber.size()) { + colFirstSpanningCol.set(colIndex, new Boolean(bFirstSpanningCol)); + } else { + colFirstSpanningCol.add(new Boolean(bFirstSpanningCol)); + } + } + + /** + * + * @param bFirstSpanningCol specifies, if it's the first of + * multiple spanned columns + */ + public void setNextFirstSpanningCol( + boolean bFirstSpanningCol) { + colFirstSpanningCol.add(new Boolean(bFirstSpanningCol)); + } /** * Added by Peter Herweg on 2002-06-29 @@ -160,6 +199,7 @@ public class TableContext implements ITableColumnsInfo { if (i.intValue() == 0) { colRowSpanningAttrs.set(z, null); + colFirstSpanningCol.set(z, new Boolean(false)); } } } @@ -206,13 +246,17 @@ public class TableContext implements ITableColumnsInfo { colIndex = index; } - /** Added by Boris Poudérous on 07/22/2002 */ + /** + * @return Index of current column + */ public int getColumnIndex() { return colIndex; } /** - end - */ - /** Added by Boris Poudérous on 07/22/2002 */ + /** + * @return Number of columns + */ public int getNumberOfColumns() { return colWidths.size(); } -- 2.39.5