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;
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.
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);
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 - */
}
/**
* @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) {
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
*/
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
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");
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();
return textrun;
}
+ /**
+ * Get the parent row.
+ * @return The parent row.
+ */
public RtfTableRow getRow() {
RtfElement e = this;
while (e.parent != null) {