Просмотр исходного кода

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
tags/fop-0_92-beta
Peter Herweg 18 лет назад
Родитель
Сommit
4e8413db45

+ 21
- 1
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);

+ 7
- 0
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;
}

+ 91
- 52
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) {

+ 4
- 2
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);

+ 20
- 12
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 - */
}


Загрузка…
Отмена
Сохранить