You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ph...@apache.org on 2006/01/15 18:38:03 UTC

svn commit: r369237 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc: RtfTable.java RtfTableCell.java RtfTableRow.java

Author: pherweg
Date: Sun Jan 15 09:37:58 2006
New Revision: 369237

URL: http://svn.apache.org/viewcvs?rev=369237&view=rev
Log:
RTF: support for nested tables

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java?rev=369237&r1=369236&r2=369237&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java Sun Jan 15 09:37:58 2006
@@ -36,6 +36,7 @@
 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 */
@@ -104,15 +105,23 @@
      * @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();
+        }
     }
 
     /**
@@ -159,5 +168,37 @@
 
         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;  
+    }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java?rev=369237&r1=369236&r2=369237&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java Sun Jan 15 09:37:58 2006
@@ -141,6 +141,7 @@
         if (attrs == null) {
             attrs = new RtfAttributes();
         }
+        
         attrs.set("intbl");
 
         paragraph = new RtfParagraph(this, writer, attrs);
@@ -280,30 +281,39 @@
      * @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");
+    	}
     }
 
 
@@ -374,6 +384,7 @@
      * 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;
@@ -405,7 +416,7 @@
                 e.writeRtf();
             }
         }
-    }
+    }*/
 
     /**
      * A table cell always contains "useful" content, as it is here to take some
@@ -449,7 +460,10 @@
     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);
 
@@ -458,5 +472,18 @@
         textrun.setSuppressLastPar(true);  
         
         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;  
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java?rev=369237&r1=369236&r2=369237&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java Sun Jan 15 09:37:58 2006
@@ -38,7 +38,7 @@
 
 public class RtfTableRow extends RtfContainer implements ITableAttributes {
     private RtfTableCell cell;
-    private RtfExtraRowSet extraRowSet;
+//    private RtfExtraRowSet extraRowSet;
     private int id;
     private int highestCell = 0;
 
@@ -132,13 +132,26 @@
      */
     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);
@@ -160,47 +173,6 @@
                     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;
         
@@ -209,37 +181,10 @@
             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.
@@ -276,11 +221,8 @@
             }
           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) {
@@ -309,16 +251,29 @@
      * @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 {
@@ -364,5 +319,18 @@
      */
     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;  
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org