]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added support for number-columns-spanned and number-rows-spanned in the same cell
authorPeter Herweg <pherweg@apache.org>
Wed, 25 Jan 2006 19:11:15 +0000 (19:11 +0000)
committerPeter Herweg <pherweg@apache.org>
Wed, 25 Jan 2006 19:11:15 +0000 (19:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@372292 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java

index 7e558bab3e9e59925160a7fd9b56bba8b31b1805..f7c23abe6d02d087ec47e6248854931731c27a81 100644 (file)
@@ -537,11 +537,15 @@ public class RTFHandler extends FOEventHandler {
         }
 
         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 @@ public class RTFHandler extends FOEventHandler {
         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 @@ public class RTFHandler extends FOEventHandler {
             //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 @@ public class RTFHandler extends FOEventHandler {
             // 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);
 
-//          process number-columns-spanned attribute
+                // 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
             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());
index 1f0f2c400a6ca60fa4e77a7b90b81e1a94565f70..6da766988e1dde578b775078b5377a47bc7ee435 100644 (file)
@@ -50,4 +50,10 @@ public interface ITableColumnsInfo {
 
     /** @return number of columns */
     int getNumberOfColumns();
+    
+    /**
+     * 
+     * @return true, if it's the first of multiple spanning columns
+     */
+    public boolean getFirstSpanningCol();
 }
\ No newline at end of file
index f55940a2f2a4082dfd2a677ed31c5e9c0d6f1ef8..1b4a26fc489ea63c5e27f0c4a57137d4a012c3e5 100644 (file)
@@ -225,7 +225,7 @@ public class RtfTableCell
         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
index fadb5236f34991781fe648ff156454891278f946..0f5f67635b48abe7312ad6e6ab5e49fd1fe60b95 100644 (file)
@@ -45,7 +45,6 @@ public class TableContext implements ITableColumnsInfo {
     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 @@ public class TableContext implements ITableColumnsInfo {
     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 class TableContext implements ITableColumnsInfo {
     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 @@ public class TableContext implements ITableColumnsInfo {
         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 @@ public class TableContext implements ITableColumnsInfo {
 
             if (i.intValue() == 0) {
                 colRowSpanningAttrs.set(z, null);
+                colFirstSpanningCol.set(z, new Boolean(false));
             }
         }
     }
@@ -206,13 +246,17 @@ public class TableContext implements ITableColumnsInfo {
         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();
     }