]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
RTF: Add support for number-rows-spanned, height (at table-row) and margin-left
authorJeremias Maerki <jeremias@apache.org>
Sat, 8 Nov 2003 19:31:41 +0000 (19:31 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sat, 8 Nov 2003 19:31:41 +0000 (19:31 +0000)
(at table and block).
Submitted By: Peter Herweg <pherweg@web.de>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196999 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/TableAttributesConverter.java
src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java

index ef2df1947cd6c81586a110db788bd435ebcf4c1b..3ef09ab216722683e501cd9368c27c85a68308a2 100644 (file)
@@ -372,9 +372,11 @@ public class RTFHandler extends FOInputHandler {
     public void startTable(Table tbl) {
         // create an RtfTable in the current table container
         TableContext tableContext = new TableContext(builderContext);
-        RtfAttributes atts = new RtfAttributes();
 
         try {
+            RtfAttributes atts = 
+                    TableAttributesConverter.convertTableAttributes(tbl.properties);
+            
             final IRtfTableContainer tc =
                    (IRtfTableContainer)builderContext.getContainer(IRtfTableContainer.class,
                    true, null);
@@ -499,7 +501,7 @@ public class RTFHandler extends FOInputHandler {
     public void startBody(TableBody tb) {
         try {
             RtfAttributes atts = TableAttributesConverter.convertRowAttributes (tb.properties,
-                   null, null);
+                   null);
 
             RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this);
             tbl.setHeaderAttribs(atts);
@@ -534,7 +536,7 @@ public class RTFHandler extends FOInputHandler {
             RtfAttributes tblAttribs = tbl.getRtfAttributes();
             RtfAttributes tblRowAttribs = new RtfAttributes();
             RtfAttributes atts = TableAttributesConverter.convertRowAttributes(tr.properties,
-                    null, tbl.getHeaderAttribs());
+                    tbl.getHeaderAttribs());
 
             builderContext.pushContainer(tbl.newTableRow(atts));
 
@@ -577,13 +579,12 @@ public class RTFHandler extends FOInputHandler {
             float width = tctx.getColumnWidth();
 
             // create an RtfTableCell in the current RtfTableRow
-            RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties,
-                    null);
+            RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties);
             RtfTableCell cell = row.newTableCell((int)width, atts);
 
             //process number-rows-spanned attribute
             Property p = null;
-            if ((p = tc.properties.get("number-rows-spanned")) != null && false) {
+            if ((p = tc.properties.get("number-rows-spanned")) != null) {
                 // Start vertical merge
                 cell.setVMerge(RtfTableCell.MERGE_START);
 
index 3a08ee0c0a817146d6654d3e9c46c96ebf4fa6c1..650851e4bbecd91642b87656db53f08c1b795aa4 100644 (file)
@@ -104,7 +104,34 @@ public class TableAttributesConverter {
     //////////////////////////////////////////////////
     // @@ Static converter methods
     //////////////////////////////////////////////////
+    /**
+     * Converts table-only attributes to rtf attributes.
+     * 
+     * @param attrs Given attributes
+     * @param defaultAttributes Default rtf attributes
+     *
+     * @return All valid rtf attributes together
+     *
+     * @throws ConverterException On convertion error
+     */
+    static RtfAttributes convertTableAttributes(PropertyList properties)
+    throws FOPException {
+        RtfAttributes attrib = new RtfAttributes();
 
+        LengthProperty lengthProp=null;
+        // margin-left
+        lengthProp=(LengthProperty)properties.get("margin-left");
+        if (lengthProp != null) {
+            Float f = new Float(lengthProp.getLength().getValue() / 1000f);
+            final String sValue = f.toString() + "pt";
+
+            attrib.set(
+                    ITableAttributes.ATTR_ROW_LEFT_INDENT,
+                    (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+        }
+
+        return attrib;
+    }
 
     /**
      * Converts cell attributes to rtf attributes.
@@ -115,7 +142,7 @@ public class TableAttributesConverter {
      *
      * @throws ConverterException On convertion error
      */
-    static RtfAttributes convertCellAttributes(PropertyList props, PropertyList defProps)
+    static RtfAttributes convertCellAttributes(PropertyList props)
     throws FOPException {
 
         Property p;
@@ -124,11 +151,7 @@ public class TableAttributesConverter {
 
         RtfAttributes attrib = null;
 
-        if (defProps != null) {
-            attrib = convertCellAttributes(defProps, null);
-        } else {
             attrib = new RtfAttributes();
-        }
 
         boolean isBorderPresent = false;
 
@@ -269,7 +292,7 @@ public class TableAttributesConverter {
      * @throws ConverterException On convertion error
      */
     static RtfAttributes convertRowAttributes(PropertyList props,
-            PropertyList defProps, RtfAttributes rtfatts)
+            RtfAttributes rtfatts)
     throws FOPException {
 
         Property p;
@@ -278,14 +301,10 @@ public class TableAttributesConverter {
 
         RtfAttributes attrib = null;
 
-        if (defProps != null) {
-            attrib = convertRowAttributes(defProps, null, rtfatts);
-        } else {
             if (rtfatts == null) {
                 attrib = new RtfAttributes();
             } else {
                 attrib = rtfatts;
-            }
         }
 
         String attrValue;
index be4d79cf41c15dc9fd5ff7fd7ebf3aef04ea7477..d8b8e0faba6e47288884bcb2a037e92691deb036 100644 (file)
@@ -266,7 +266,7 @@ class TextAttributesConverter {
                 String sValue = f.toString() + "pt";
             
                 rtfAttr.set(
-                        RtfText.LEFT_INDENT_BODY,
+                        RtfText.RIGHT_INDENT_BODY,
                         (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
             } else {
                 rtfAttr.set(RtfText.RIGHT_INDENT_BODY, 0);
index e85afc51116ac830b0b3d7c1d779af84dcc9cc0b..f46109b93569da13b11f9e388115f12a031afa55 100644 (file)
@@ -74,6 +74,7 @@ public interface ITableAttributes {
 
     /** half the space between the cells of a table row in twips */
     public static final String ATTR_RTF_15_TRGAPH = "trgaph";
+    public static final String ATTR_ROW_LEFT_INDENT = "trleft";
 
 // RTF 1.6 Row and table attributes
     /** table row padding, top */
@@ -103,7 +104,7 @@ public interface ITableAttributes {
         ATTR_ROW_PADDING_BOTTOM, ATTR_ROW_U_PADDING_BOTTOM,
         ATTR_ROW_PADDING_LEFT, ATTR_ROW_U_PADDING_LEFT,
         ATTR_ROW_PADDING_RIGHT, ATTR_ROW_U_PADDING_RIGHT,
-        ATTR_RTF_15_TRGAPH
+        ATTR_RTF_15_TRGAPH, ATTR_ROW_LEFT_INDENT
     };
 
 // Cell attributes
index f84b5c970057d0d26982cb609c7142e3b7c13ce8..de11831edf29afd67a70a8eda1f0570531c9e234 100644 (file)
@@ -481,6 +481,12 @@ implements IRtfParagraphContainer, IRtfListContainer, IRtfTableContainer,
         RtfAttributes attrs = new RtfAttributes();
         attrs.set("intbl");
         
-        return RtfTextrun.getTextrun(this, writer, attrs);
+        RtfTextrun textrun=RtfTextrun.getTextrun(this, writer, attrs);
+
+        //Suppress the very last \par, because the closing \cell applies the
+        //paragraph attributes. 
+        textrun.setSuppressLastPar(true);  
+        
+        return textrun;
     }
 }
index 5be8d50f0cfde51f1f189dd91a35bbed3910891c..d2031927d0e8cca5e7b1141a5238e9aa199b8c10 100644 (file)
@@ -184,6 +184,12 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes {
         writeAttributes(attrib, ITableAttributes.CELL_BORDER);
         writeAttributes(attrib, BorderAttributesConverter.BORDERS);
 
+        if(attrib.isSet(ITableAttributes.ROW_HEIGHT)) {
+            writeOneAttribute(
+                    ITableAttributes.ROW_HEIGHT,
+                    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
@@ -227,6 +233,12 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes {
 
         // write X positions of our cells
         int xPos = 0;
+        
+        final Object leftIndent = attrib.getValue(ITableAttributes.ATTR_ROW_LEFT_INDENT);
+        if (leftIndent != null) {
+            xPos = ((Integer)leftIndent).intValue();
+        }
+        
         index = 0;            // Line added by Boris POUDEROUS on 07/02/2002
         for (Iterator it = getChildren().iterator(); it.hasNext();) {
             final RtfElement e = (RtfElement)it.next();
index 7a12202c294478e87460ccac29c71be0582f018c..aae0190d802ede676a386ab5a95dcb16d2ee84e6 100644 (file)
@@ -70,6 +70,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
  */
 
 public class RtfTextrun extends RtfContainer {
+    private boolean bSuppressLastPar=false;
     
     /**  Class which represents the opening of a RTF group mark.*/
     private class RtfOpenGroupMark extends RtfElement
@@ -203,6 +204,15 @@ public class RtfTextrun extends RtfContainer {
         return textrun;
     }
    
+    /**
+     * specify, if the last paragraph control word (\par) should be suppressed.
+     * @param bSuppress true, if the last \par should be suppressed
+     * @throws IOException for I/O problems
+     */    
+    public void setSuppressLastPar(boolean bSuppress) {
+        bSuppressLastPar=bSuppress;
+    }
+   
     /**
      * write RTF code of all our children
      * @throws IOException for I/O problems
@@ -269,7 +279,9 @@ public class RtfTextrun extends RtfContainer {
             boolean bHide=false;
             bHide=bRtfParagraphBreak;
             bHide=bHide &&
-                    (bPrevPar || bFirst || (bLast && lastParagraphBreak!=null && e==lastParagraphBreak) );
+                    (bPrevPar || bFirst || 
+                        (bSuppressLastPar && bLast && lastParagraphBreak!=null && e==lastParagraphBreak)
+                    );
                 
             if( !bHide) {
                 e.writeRtf();