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/23 23:07:32 UTC

svn commit: r371684 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf: RTFHandler.java rtflib/rtfdoc/IRtfTextrunContainer.java rtflib/rtfdoc/RtfTableCell.java rtflib/rtfdoc/RtfTableRow.java rtflib/tools/TableContext.java

Author: pherweg
Date: Mon Jan 23 14:07:24 2006
New Revision: 371684

URL: http://svn.apache.org/viewcvs?rev=371684&view=rev
Log:
number-columns-spanned did not work in last row of a cell. Fixed.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.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
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=371684&r1=371683&r2=371684&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java Mon Jan 23 14:07:24 2006
@@ -66,6 +66,7 @@
 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 @@
             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 @@
             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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java?rev=371684&r1=371683&r2=371684&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java Mon Jan 23 14:07:24 2006
@@ -32,5 +32,12 @@
  */
 
 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;
 }

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=371684&r1=371683&r2=371684&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 Mon Jan 23 14:07:24 2006
@@ -85,47 +85,6 @@
         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 @@
      *  @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 @@
             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 @@
         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 @@
         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 @@
         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 @@
         return textrun;
     }
     
+    /**
+     * Get the parent row.
+     * @return The parent row.
+     */
     public RtfTableRow getRow() {
         RtfElement e = this;
         while (e.parent != 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=371684&r1=371683&r2=371684&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 Mon Jan 23 14:07:24 2006
@@ -110,8 +110,10 @@
         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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java?rev=371684&r1=371683&r2=371684&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java Mon Jan 23 14:07:24 2006
@@ -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 @@
         }
     }
 
-     /** 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 - */
 }
 



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