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/25 20:11:21 UTC

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

Author: pherweg
Date: Wed Jan 25 11:11:15 2006
New Revision: 372292

URL: http://svn.apache.org/viewcvs?rev=372292&view=rev
Log:
added support for number-columns-spanned and number-rows-spanned in the same cell

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/ITableColumnsInfo.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/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=372292&r1=372291&r2=372292&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 Wed Jan 25 11:11:15 2006
@@ -537,11 +537,15 @@
         }
 
         try {
-            Integer iWidth = new Integer(tc.getColumnWidth().getValue() / 1000);
+            Integer iWidth = 
+                new Integer(tc.getColumnWidth().getValue() / 1000);
             String strWidth = iWidth.toString() + "pt";
-            Float width = new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth));
+            Float width = new Float(
+                    FoUnitsConverter.getInstance().convertToTwips(strWidth));
             builderContext.getTableContext().setNextColumnWidth(width);
-            builderContext.getTableContext().setNextColumnRowSpanning(new Integer(0), null);
+            builderContext.getTableContext().setNextColumnRowSpanning(
+                    new Integer(0), null);
+            builderContext.getTableContext().setNextFirstSpanningCol(false);
         } catch (Exception e) {
             log.error("startColumn: " + e.getMessage());
             throw new RuntimeException(e.getMessage());
@@ -722,6 +726,31 @@
         if (bDefer) {
             return;
         }
+        
+        try {
+            TableContext tctx = builderContext.getTableContext();
+            final RtfTableRow row = (RtfTableRow)builderContext.getContainer(RtfTableRow.class,
+                    true, null);
+
+            //while the current column is in row-spanning, act as if
+            //a vertical merged cell would have been specified.
+            while (tctx.getNumberOfColumns() > tctx.getColumnIndex()
+                  && tctx.getColumnRowSpanningNumber().intValue() > 0) {
+                RtfTableCell vCell = row.newTableCellMergedVertically(
+                        (int)tctx.getColumnWidth(),
+                        tctx.getColumnRowSpanningAttrs());
+                
+                if (!tctx.getFirstSpanningCol()) {
+                    vCell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
+                }
+                
+                tctx.selectNextColumn();
+            }
+        } catch (Exception e) {
+            log.error("endRow: " + e.getMessage());
+            throw new RuntimeException(e.getMessage());
+        }
+
 
         builderContext.popContainer();
         builderContext.getTableContext().decreaseRowSpannings();
@@ -748,8 +777,14 @@
             //a vertical merged cell would have been specified.
             while (tctx.getNumberOfColumns() > tctx.getColumnIndex()
                   && tctx.getColumnRowSpanningNumber().intValue() > 0) {
-                row.newTableCellMergedVertically((int)tctx.getColumnWidth(),
+                RtfTableCell vCell = row.newTableCellMergedVertically(
+                        (int)tctx.getColumnWidth(),
                         tctx.getColumnRowSpanningAttrs());
+                
+                if (!tctx.getFirstSpanningCol()) {
+                    vCell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
+                }
+                
                 tctx.selectNextColumn();
             }
 
@@ -759,37 +794,50 @@
             // create an RtfTableCell in the current RtfTableRow
             RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc);
             RtfTableCell cell = row.newTableCell((int)width, atts);
+            
+            //process number-rows-spanned attribute
+            if (numberRowsSpanned > 1) {
+                // Start vertical merge
+                cell.setVMerge(RtfTableCell.MERGE_START);
+
+                // set the number of rows spanned
+                tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), 
+                        cell.getRtfAttributes());
+            } else {
+                tctx.setCurrentColumnRowSpanning(
+                        new Integer(numberRowsSpanned), null);
+            }
 
-//          process number-columns-spanned attribute
+            //process number-columns-spanned attribute
             if (numberColumnsSpanned > 0) {
                 // Get the number of columns spanned
                 RtfTable table = row.getTable();
+                tctx.setCurrentFirstSpanningCol(true);
                 
                 // We widthdraw one cell because the first cell is already created
                 // (it's the current cell) !
-                int i = numberColumnsSpanned - 1;
-                while (i > 0) {
+                 for (int i = 0; i < numberColumnsSpanned - 1; ++i) {
                     tctx.selectNextColumn();
                     
-                    row.newTableCellMergedHorizontally(
+                    tctx.setCurrentFirstSpanningCol(false);
+                    RtfTableCell hCell = row.newTableCellMergedHorizontally(
                             0, null);
                     
-                    i--;
+                    if (numberRowsSpanned > 1) {
+                        // Start vertical merge
+                        hCell.setVMerge(RtfTableCell.MERGE_START);
+
+                        // set the number of rows spanned
+                        tctx.setCurrentColumnRowSpanning(
+                                new Integer(numberRowsSpanned), 
+                                cell.getRtfAttributes());
+                    } else {
+                        tctx.setCurrentColumnRowSpanning(
+                                new Integer(numberRowsSpanned), null);
+                    }
                 }
             }
             
-            //process number-rows-spanned attribute
-            if (numberRowsSpanned > 1) {
-                // Start vertical merge
-                cell.setVMerge(RtfTableCell.MERGE_START);
-
-                // set the number of rows spanned
-                tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned),
-                        cell.getRtfAttributes());
-            } else {
-                tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), null);
-            }
-
             builderContext.pushContainer(cell);
         } catch (Exception e) {
             log.error("startCell: " + e.getMessage());

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java?rev=372292&r1=372291&r2=372292&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java Wed Jan 25 11:11:15 2006
@@ -50,4 +50,10 @@
 
     /** @return number of columns */
     int getNumberOfColumns();
+    
+    /**
+     * 
+     * @return true, if it's the first of multiple spanning columns
+     */
+    public boolean getFirstSpanningCol();
 }

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=372292&r1=372291&r2=372292&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 Wed Jan 25 11:11:15 2006
@@ -225,7 +225,7 @@
         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

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=372292&r1=372291&r2=372292&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 Wed Jan 25 11:11:15 2006
@@ -45,7 +45,6 @@
     private int colIndex;
 
     /**
-     * Added by Peter Herweg on 2002-06-29
      * This ArrayList contains one element for each column in the table.
      * value == 0 means there is no row-spanning
      * value >  0 means there is row-spanning
@@ -54,13 +53,19 @@
     private final List colRowSpanningNumber = new java.util.ArrayList();
 
     /**
-     * Added by Peter Herweg on 2002-06-29
      * If there has a vertical merged cell to be created, its attributes are
      * inherited from the corresponding MERGE_START-cell.
      * For this purpose the attributes of a cell are stored in this array, as soon
      * as a number-rows-spanned attribute has been found.
      */
     private final List colRowSpanningAttrs = new java.util.ArrayList();
+    
+    /**
+     * This ArrayList contains one element for each column in the table.
+     * value == true means, it's the first of multiple spanned columns
+     * value == false meanst, it's NOT the first of multiple spanned columns
+     */
+    private final List colFirstSpanningCol = new java.util.ArrayList();
 
     private boolean bNextRowBelongsToHeader = false;
 
@@ -113,6 +118,15 @@
     public Integer getColumnRowSpanningNumber() {
         return (Integer)colRowSpanningNumber.get(colIndex);
     }
+    
+    /**
+     * 
+     * @return true, if it's the first of multiple spanning columns
+     */
+    public boolean getFirstSpanningCol() {
+        Boolean b = (Boolean) colFirstSpanningCol.get(colIndex);
+        return b.booleanValue();
+    }
 
     /**
      * 
@@ -141,6 +155,31 @@
         colRowSpanningNumber.add(iRowSpanning);
         colRowSpanningAttrs.add(colIndex, attrs);
     }
+    
+    /**
+     * 
+     * @param bFirstSpanningCol specifies, if it's the first of 
+     *                          multiple spanned columns
+     */
+    public void setCurrentFirstSpanningCol(
+            boolean bFirstSpanningCol) {
+
+        if (colIndex < colRowSpanningNumber.size()) {
+            colFirstSpanningCol.set(colIndex, new Boolean(bFirstSpanningCol));
+        } else {
+            colFirstSpanningCol.add(new Boolean(bFirstSpanningCol));
+        }
+    }
+
+    /**
+     * 
+     * @param bFirstSpanningCol specifies, if it's the first of 
+     *                          multiple spanned columns
+     */
+    public void setNextFirstSpanningCol(
+            boolean bFirstSpanningCol) {
+        colFirstSpanningCol.add(new Boolean(bFirstSpanningCol));
+    }
 
     /**
      * Added by Peter Herweg on 2002-06-29
@@ -160,6 +199,7 @@
 
             if (i.intValue() == 0) {
                 colRowSpanningAttrs.set(z, null);
+                colFirstSpanningCol.set(z, new Boolean(false));
             }
         }
     }
@@ -206,13 +246,17 @@
         colIndex = index;
     }
     
-    /** Added by Boris Poudérous on 07/22/2002 */
+    /**
+     * @return Index of current column 
+     */
     public int getColumnIndex() {
         return colIndex;
     }
     /** - end - */
 
-    /** Added by Boris Poudérous on 07/22/2002 */
+    /**
+     * @return Number of columns
+     */
     public int getNumberOfColumns() {
         return colWidths.size();
     }



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