public class RtfTable extends RtfContainer {
private RtfTableRow row;
private int highestRow = 0;
+ private Boolean isNestedTable = null;
/** Added by Boris Poudérous on 07/22/2002 in order to process
* number-columns-spanned attribute */
* @throws IOException for I/O problems
*/
protected void writeRtfPrefix() throws IOException {
- writeGroupMark(true);
+ if (isNestedTable()) {
+ writeControlWordNS("pard");
+ }
+
+ writeGroupMark(true);
}
-
+
/**
* Overridden to write RTF suffix code, what comes after our children
* @throws IOException for I/O problems
*/
protected void writeRtfSuffix() throws IOException {
writeGroupMark(false);
+
+ if(isNestedTable()) {
+ getRow().writeRowAndCellsDefintions();
+ }
}
/**
return super.getRtfAttributes();
}
- /** - end - */
+
+ public boolean isNestedTable() {
+ if (isNestedTable == null) {
+ RtfElement e=this;
+ while(e.parent != null) {
+ if (e.parent instanceof RtfTableCell) {
+ isNestedTable=new Boolean(true);
+ return true;
+ }
+
+ e = e.parent;
+ }
+
+ isNestedTable=new Boolean(false);
+ } else {
+ return isNestedTable.booleanValue();
+ }
+
+ return false;
+ }
+
+ public RtfTableRow getRow() {
+ RtfElement e=this;
+ while(e.parent != null) {
+ if (e.parent instanceof RtfTableRow) {
+ return (RtfTableRow) e.parent;
+ }
+
+ e = e.parent;
+ }
+
+ return null;
+ }
}
if (attrs == null) {
attrs = new RtfAttributes();
}
+
attrs.set("intbl");
paragraph = new RtfParagraph(this, writer, attrs);
* @throws IOException for I/O problems
*/
protected void writeRtfSuffix() throws IOException {
- // word97 hangs if cell does not contain at least one "par" control word
- // TODO this is what causes the extra spaces in nested table of test
- // 004-spacing-in-tables.fo,
- // but if is not here we generate invalid RTF for word97
-
- if (setCenter) {
- writeControlWord("qc");
- } else if (setRight) {
- writeControlWord("qr");
- } else {
- writeControlWord("ql");
- }
-
-
-
- if (!containsText()) {
- writeControlWord("intbl");
-
- //R.Marra this create useless paragraph
- //Seem working into Word97 with the "intbl" only
-// writeControlWord("par");
- }
-
- writeControlWord("cell");
+ if (getRow().getTable().isNestedTable()) {
+ //nested table
+ writeControlWordNS("nestcell");
+ writeGroupMark(true);
+ writeControlWord("nonesttables");
+ writeControlWord("par");
+ writeGroupMark(false);
+ } else {
+ // word97 hangs if cell does not contain at least one "par" control word
+ // TODO this is what causes the extra spaces in nested table of test
+ // 004-spacing-in-tables.fo,
+ // but if is not here we generate invalid RTF for word97
+
+ if (setCenter) {
+ writeControlWord("qc");
+ } else if (setRight) {
+ writeControlWord("qr");
+ } else {
+ writeControlWord("ql");
+ }
+
+
+
+ if (!containsText()) {
+ writeControlWord("intbl");
+
+ //R.Marra this create useless paragraph
+ //Seem working into Word97 with the "intbl" only
+ // writeControlWord("par");
+ }
+
+ writeControlWord("cell");
+ }
}
* disabled for V0.3 - nested table support is not done yet
* @throws IOException for I/O problems
*/
+ /*
protected void writeRtfContent()
throws IOException {
int extraRowIndex = 0;
e.writeRtf();
}
}
- }
+ }*/
/**
* A table cell always contains "useful" content, as it is here to take some
public RtfTextrun getTextrun()
throws IOException {
RtfAttributes attrs = new RtfAttributes();
- attrs.set("intbl");
+
+ if(!getRow().getTable().isNestedTable()) {
+ attrs.set("intbl");
+ }
RtfTextrun textrun = RtfTextrun.getTextrun(this, writer, attrs);
return textrun;
}
+
+ public RtfTableRow getRow() {
+ RtfElement e=this;
+ while(e.parent != null) {
+ if (e.parent instanceof RtfTableRow) {
+ return (RtfTableRow) e.parent;
+ }
+
+ e = e.parent;
+ }
+
+ return null;
+ }
}
public class RtfTableRow extends RtfContainer implements ITableAttributes {
private RtfTableCell cell;
- private RtfExtraRowSet extraRowSet;
+// private RtfExtraRowSet extraRowSet;
private int id;
private int highestCell = 0;
*/
protected void writeRtfContent() throws IOException {
- // create new extra row set to allow our cells to put nested tables
- // in rows that will be rendered after this one
- extraRowSet = new RtfExtraRowSet(writer);
-
- // render the row and cells definitions
+ if (getTable().isNestedTable()) {
+ //nested table
+ writeControlWord("intbl");
+ writeControlWord("itap2");
+ } else {
+ //normal (not nested) table
+ writeRowAndCellsDefintions();
+ }
+ // now children can write themselves, we have the correct RTF prefix code
+ super.writeRtfContent();
+ }
+
+ public void writeRowAndCellsDefintions() throws IOException {
+// render the row and cells definitions
writeControlWord("trowd");
-
+
+ if (!getTable().isNestedTable()) {
+ writeControlWord("itap0");
+ }
+
//check for keep-together
if (attrib != null && attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
writeControlWord(ROW_KEEP_TOGETHER);
attrib.getValue(ITableAttributes.ROW_HEIGHT));
}
- /**
- * Added by Boris POUDEROUS on 07/02/2002
- * in order to get the indexes of the cells preceding a cell that
- * contains a nested table.
- * Thus, the cells of the extra row will be merged with the cells above.
- */
- boolean nestedTableFound = false;
- int index = 0; // Used to store the index of the cell that contains a nested table
- int numberOfCellsBeforeNestedTable = 0;
-
- java.util.Vector indexesFound = new java.util.Vector();
- for (Iterator it = getChildren().iterator(); it.hasNext();) {
- final RtfElement e = (RtfElement)it.next();
-
- if (e instanceof RtfTableCell) {
- if (!nestedTableFound) {
- ++numberOfCellsBeforeNestedTable;
- }
- for (Iterator it2 = ((RtfTableCell)e).getChildren().iterator(); it2.hasNext();) {
- final RtfElement subElement = (RtfElement)it2.next();
- if (subElement instanceof RtfTable) {
- nestedTableFound = true;
- indexesFound.addElement(new Integer(index));
- } else if (subElement instanceof RtfParagraph) {
- for (Iterator it3
- = ((RtfParagraph)subElement).getChildren().iterator();
- it3.hasNext();) {
- final RtfElement subSubElement = (RtfElement)it3.next();
- if (subSubElement instanceof RtfTable) {
- nestedTableFound = true;
- indexesFound.addElement(new Integer(index));
- }
- }
- }
- }
- }
-
- index++;
- }
- /** - end - */
-
// write X positions of our cells
int xPos = 0;
xPos = ((Integer)leftIndent).intValue();
}
- index = 0; // Line added by Boris POUDEROUS on 07/02/2002
+ int index = 0;
for (Iterator it = getChildren().iterator(); it.hasNext();) {
final RtfElement e = (RtfElement)it.next();
if (e instanceof RtfTableCell) {
- /**
- * Added by Boris POUDEROUS on 2002/07/02
- */
- // If one of the row's child cells contains a nested table :
- if (!indexesFound.isEmpty()) {
- for (int i = 0; i < indexesFound.size(); i++) {
- // If the current cell index is equals to the index of the cell that
- // contains a nested table => NO MERGE
- if (index == ((Integer)indexesFound.get(i)).intValue()) {
- break;
-
- // If the current cell index is lower than the index of the cell that
- // contains a nested table => START VERTICAL MERGE
- } else if (index < ((Integer)indexesFound.get(i)).intValue()) {
- ((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
- break;
-
- // If the current cell index is greater than the index of the cell that
- // contains a nested table => START VERTICAL MERGE
- } else if (index > ((Integer)indexesFound.get(i)).intValue()) {
- ((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
- break;
- }
- }
- }
- /** - end - */
-
// Added by Normand Masse
// Adjust the cell's display attributes so the table's/row's borders
// are drawn properly.
}
index++; // Added by Boris POUDEROUS on 2002/07/02
}
-
- newLine();
- // now children can write themselves, we have the correct RTF prefix code
- super.writeRtfContent();
+ newLine();
}
private void adjustBorderProperties(RtfTable parentTable) {
* @throws IOException for I/O problems
*/
protected void writeRtfSuffix() throws IOException {
- writeControlWord("row");
+ if (getTable().isNestedTable()) {
+ //nested table
+ writeGroupMark(true);
+ writeStarControlWord("nesttableprops");
+ writeRowAndCellsDefintions();
+ writeControlWordNS("nestrow");
+ writeGroupMark(false);
+
+
+ writeGroupMark(true);
+ writeControlWord("nonesttables");
+ writeControlWord("par");
+ writeGroupMark(false);
+ } else {
+ writeControlWord("row");
+ }
- // write extra rows if any
- extraRowSet.writeRtf();
writeGroupMark(false);
}
- RtfExtraRowSet getExtraRowSet() {
- return extraRowSet;
- }
+// RtfExtraRowSet getExtraRowSet() {
+// return extraRowSet;
+// }
private void writePaddingAttributes()
throws IOException {
public boolean isHighestCell(int id) {
return (highestCell == id) ? true : false;
}
+
+ public RtfTable getTable() {
+ RtfElement e=this;
+ while(e.parent != null) {
+ if (e.parent instanceof RtfTable) {
+ return (RtfTable) e.parent;
+ }
+
+ e = e.parent;
+ }
+
+ return null;
+ }
}