aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorPeter Herweg <pherweg@apache.org>2006-01-23 22:07:24 +0000
committerPeter Herweg <pherweg@apache.org>2006-01-23 22:07:24 +0000
commit4e8413db450f4cd73e3d5f6b2ffdaf6ad222f454 (patch)
tree85fe9d9156f3b0691c23ca05b835fb6feceaf295 /src/java
parent90e5a9b89fcfd55bedc8870af717f507c1c69184 (diff)
downloadxmlgraphics-fop-4e8413db450f4cd73e3d5f6b2ffdaf6ad222f454.tar.gz
xmlgraphics-fop-4e8413db450f4cd73e3d5f6b2ffdaf6ad222f454.zip
number-columns-spanned did not work in last row of a cell. Fixed.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@371684 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/render/rtf/RTFHandler.java22
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java7
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java143
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java6
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java32
5 files changed, 143 insertions, 67 deletions
diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java
index 9f800ead6..a6611f5bd 100644
--- a/src/java/org/apache/fop/render/rtf/RTFHandler.java
+++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java
@@ -66,6 +66,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfBeforeContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfListContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTextrunContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableColumnsInfo;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAfter;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfBefore;
@@ -684,6 +685,8 @@ public class RTFHandler extends FOEventHandler {
final RtfTableRow row = (RtfTableRow)builderContext.getContainer(RtfTableRow.class,
true, null);
+ int numberRowsSpanned = tc.getNumberRowsSpanned();
+ int numberColumnsSpanned = tc.getNumberColumnsSpanned();
//while the current column is in row-spanning, act as if
//a vertical merged cell would have been specified.
@@ -701,8 +704,25 @@ public class RTFHandler extends FOEventHandler {
RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc);
RtfTableCell cell = row.newTableCell((int)width, atts);
+// process number-columns-spanned attribute
+ if (numberColumnsSpanned > 0) {
+ // Get the number of columns spanned
+ RtfTable table = row.getTable();
+
+ // We widthdraw one cell because the first cell is already created
+ // (it's the current cell) !
+ int i = numberColumnsSpanned - 1;
+ while (i > 0) {
+ tctx.selectNextColumn();
+
+ row.newTableCellMergedHorizontally(
+ 0, null);
+
+ i--;
+ }
+ }
+
//process number-rows-spanned attribute
- int numberRowsSpanned = tc.getNumberRowsSpanned();
if (numberRowsSpanned > 1) {
// Start vertical merge
cell.setVMerge(RtfTableCell.MERGE_START);
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
index c614d01f4..fb6934668 100644
--- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
@@ -32,5 +32,12 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
*/
public interface IRtfTextrunContainer {
+
+ /**
+ * Returns the current RtfTextrun object.
+ * Opens a new one if necessary.
+ * @return The RtfTextrun object
+ * @throws IOException Thrown when an IO-problem occurs
+ */
RtfTextrun getTextrun() throws IOException;
}
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 11930b0a0..f55940a2f 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
@@ -85,47 +85,6 @@ public class RtfTableCell
id = idNum;
parentRow = parent;
this.cellWidth = cellWidth;
-
- /** Added by Boris Poudérous on 07/22/2002 in order to process
- * number-columns-spanned attribute */
- // If the cell is spanned horizontally
- if (attrs.getValue("number-columns-spanned") != null) {
- // Start horizontal merge
- this.setHMerge(MERGE_START);
-
- // Get the number of columns spanned
- int nbMergedCells = ((Integer)attrs.getValue("number-columns-spanned")).intValue();
-
- if (parent.parent instanceof RtfTable) {
- // Get the context of the current table in order to get the width of each column
- ITableColumnsInfo tableColumnsInfo
- = ((RtfTable)parent.parent).getITableColumnsInfo();
- tableColumnsInfo.selectFirstColumn();
-
- // Reach the column index in table context corresponding to the current column cell
- // id is the index of the current cell (it begins at 1)
- // getColumnIndex() is the index of the current column in table context (it begins at 0)
- // => so we must widthdraw 1 when comparing these two variables.
- while ((this.id - 1) != tableColumnsInfo.getColumnIndex()) {
- tableColumnsInfo.selectNextColumn();
- }
-
- // We widthdraw one cell because the first cell is already created
- // (it's the current cell) !
- int i = nbMergedCells - 1;
- while (i > 0) {
- tableColumnsInfo.selectNextColumn();
- // Added by Normand Masse
- // Pass in the current cell's attributes so the 'merged' cell has the
- // same display attributes.
- parent.newTableCellMergedHorizontally((int)tableColumnsInfo.getColumnWidth(),
- attrs);
-
- i--;
- }
- }
- }
- /** - end - */
}
/**
@@ -225,9 +184,23 @@ public class RtfTableCell
* @param widthOffset sum of the widths of preceeding cells in same row
* @return widthOffset + width of this cell
*/
- int writeCellDef(int widthOffset) throws IOException {
+ int writeCellDef(int offset) throws IOException {
+ /*
+ * Don't write \clmgf or \clmrg. Instead add the widths
+ * of all spanned columns and create a single wider cell,
+ * because \clmgf and \clmrg won't work in last row of a
+ * table (Word2000 seems to do the same).
+ * Cause of this, dont't write horizontally merged cells.
+ * They just exist as placeholders in TableContext class,
+ * and are never written to RTF file.
+ */
+ // horizontal cell merge codes
+ if (hMerge == MERGE_WITH_PREVIOUS) {
+ return offset;
+ }
+
newLine();
- this.widthOffset = widthOffset;
+ this.widthOffset = offset;
// vertical cell merge codes
if (vMerge == MERGE_START) {
@@ -236,13 +209,6 @@ public class RtfTableCell
writeControlWord("clvmrg");
}
- // horizontal cell merge codes
- if (hMerge == MERGE_START) {
- writeControlWord("clmgf");
- } else if (hMerge == MERGE_WITH_PREVIOUS) {
- writeControlWord("clmrg");
- }
-
/**
* Added by Boris POUDEROUS on 2002/06/26
*/
@@ -254,8 +220,39 @@ public class RtfTableCell
writeAttributes (attrib, ITableAttributes.CELL_BORDER);
writeAttributes (attrib, IBorderAttributes.BORDERS);
- // cell width
- final int xPos = widthOffset + this.cellWidth;
+ // determine cell width
+ int iCurrentWidth = this.cellWidth;
+ 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
+ ITableColumnsInfo tableColumnsInfo
+ = tab.getITableColumnsInfo();
+
+ tableColumnsInfo.selectFirstColumn();
+
+ // Reach the column index in table context corresponding to the current column cell
+ // id is the index of the current cell (it begins at 1)
+ // getColumnIndex() is the index of the current column in table context (it begins at 0)
+ // => so we must widthdraw 1 when comparing these two variables.
+ while ((this.id - 1) != tableColumnsInfo.getColumnIndex()) {
+ tableColumnsInfo.selectNextColumn();
+ }
+
+ // We widthdraw one cell because the first cell is already created
+ // (it's the current cell) !
+ int i = nbMergedCells - 1;
+ while (i > 0) {
+ tableColumnsInfo.selectNextColumn();
+ iCurrentWidth += (int)tableColumnsInfo.getColumnWidth();
+
+ i--;
+ }
+ }
+ final int xPos = offset + iCurrentWidth;
//these lines added by Chris Scott, Westinghouse
//some attributes need to be writting before opening block
@@ -275,12 +272,44 @@ public class RtfTableCell
return xPos;
}
+
+ /**
+ * Overriden to avoid writing any it's a merged cell.
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ // Never write horizontally merged cells.
+ if (hMerge == MERGE_WITH_PREVIOUS) {
+ return;
+ }
+
+ super.writeRtfContent();
+ }
+
+ /**
+ * Called before writeRtfContent; overriden to avoid writing
+ * any it's a merged cell.
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ // Never write horizontally merged cells.
+ if (hMerge == MERGE_WITH_PREVIOUS) {
+ return;
+ }
+
+ super.writeRtfPrefix();
+ }
/**
* The "cell" control word marks the end of a cell
* @throws IOException for I/O problems
*/
protected void writeRtfSuffix() throws IOException {
+ // Never write horizontally merged cells.
+ if (hMerge == MERGE_WITH_PREVIOUS) {
+ return;
+ }
+
if (getRow().getTable().isNestedTable()) {
//nested table
writeControlWordNS("nestcell");
@@ -455,6 +484,12 @@ public class RtfTableCell
return result;
}
+ /**
+ * Returns the current RtfTextrun object.
+ * Opens a new one if necessary.
+ * @return The RtfTextrun object
+ * @throws IOException Thrown when an IO-problem occurs
+ */
public RtfTextrun getTextrun() throws IOException {
RtfAttributes attrs = new RtfAttributes();
@@ -471,6 +506,10 @@ public class RtfTableCell
return textrun;
}
+ /**
+ * Get the parent row.
+ * @return The parent row.
+ */
public RtfTableRow getRow() {
RtfElement e = this;
while (e.parent != null) {
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
index 2c6402061..f19d2aa17 100644
--- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
@@ -110,8 +110,10 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes {
highestCell++;
// Added by Normand Masse
// Inherit attributes from base cell for merge
- RtfAttributes wAttributes = (RtfAttributes)attrs.clone();
- wAttributes.unset("number-columns-spanned");
+ RtfAttributes wAttributes = null;
+ if (attrs != null) {
+ wAttributes = (RtfAttributes)attrs.clone();
+ }
cell = new RtfTableCell(this, writer, cellWidth, wAttributes, highestCell);
cell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
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 c97d02209..0d458f27e 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
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-/* $Id: TableContext.java 227252 2005-08-03 19:30:55Z jeremias $ */
+/* $Id$ */
package org.apache.fop.render.rtf.rtflib.tools;
@@ -167,16 +167,24 @@ public class TableContext implements ITableColumnsInfo {
}
}
- /** Added by Boris Poudérous on 07/22/2002 */
- public int getColumnIndex() {
- return colIndex;
- }
- /** - end - */
-
- /** Added by Boris Poudérous on 07/22/2002 */
- public int getNumberOfColumns() {
- return colWidths.size();
- }
- /** - end - */
+ /**
+ * Set current column index.
+ * @param index New column index
+ */
+ public void setColumnIndex(int index) {
+ colIndex = index;
+ }
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getColumnIndex() {
+ return colIndex;
+ }
+ /** - end - */
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getNumberOfColumns() {
+ return colWidths.size();
+ }
+ /** - end - */
}