jeremias    2003/11/08 11:31:41

  Modified:    src/java/org/apache/fop/render/rtf/rtflib/rtfdoc
                        RtfTextrun.java ITableAttributes.java
                        RtfTableRow.java RtfTableCell.java
               src/java/org/apache/fop/render/rtf
                        TextAttributesConverter.java RTFHandler.java
                        TableAttributesConverter.java
  Log:
  RTF: Add support for number-rows-spanned, height (at table-row) and margin-left 
  (at table and block).
  Submitted By: Peter Herweg <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.3       +13 -1     
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
  
  Index: RtfTextrun.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RtfTextrun.java   8 Nov 2003 14:01:23 -0000       1.2
  +++ RtfTextrun.java   8 Nov 2003 19:31:40 -0000       1.3
  @@ -70,6 +70,7 @@
    */
   
   public class RtfTextrun extends RtfContainer {
  +    private boolean bSuppressLastPar=false;
       
       /**  Class which represents the opening of a RTF group mark.*/
       private class RtfOpenGroupMark extends RtfElement
  @@ -204,6 +205,15 @@
       }
      
       /**
  +     * 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 @@
               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(); 
  
  
  
  1.2       +3 -2      
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java
  
  Index: ITableAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ITableAttributes.java     4 Nov 2003 23:59:11 -0000       1.1
  +++ ITableAttributes.java     8 Nov 2003 19:31:40 -0000       1.2
  @@ -74,6 +74,7 @@
   
       /** 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 @@
           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
  
  
  
  1.2       +13 -1     
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
  
  Index: RtfTableRow.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RtfTableRow.java  4 Nov 2003 23:59:11 -0000       1.1
  +++ RtfTableRow.java  8 Nov 2003 19:31:40 -0000       1.2
  @@ -184,6 +184,12 @@
           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 @@
   
           // 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();
  
  
  
  1.2       +8 -2      
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
  
  Index: RtfTableCell.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RtfTableCell.java 4 Nov 2003 23:59:11 -0000       1.1
  +++ RtfTableCell.java 8 Nov 2003 19:31:40 -0000       1.2
  @@ -481,6 +481,12 @@
           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;
       }
   }
  
  
  
  1.2       +1 -1      
xml-fop/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
  
  Index: TextAttributesConverter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TextAttributesConverter.java      4 Nov 2003 23:59:11 -0000       1.1
  +++ TextAttributesConverter.java      8 Nov 2003 19:31:41 -0000       1.2
  @@ -266,7 +266,7 @@
                   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);
  
  
  
  1.3       +8 -7      xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java
  
  Index: RTFHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RTFHandler.java   8 Nov 2003 14:01:24 -0000       1.2
  +++ RTFHandler.java   8 Nov 2003 19:31:41 -0000       1.3
  @@ -372,9 +372,11 @@
       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 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 @@
               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 @@
               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);
   
  
  
  
  1.2       +30 -11    
xml-fop/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java
  
  Index: TableAttributesConverter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TableAttributesConverter.java     4 Nov 2003 23:59:11 -0000       1.1
  +++ TableAttributesConverter.java     8 Nov 2003 19:31:41 -0000       1.2
  @@ -104,7 +104,34 @@
       //////////////////////////////////////////////////
       // @@ 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 @@
        *
        * @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 @@
   
           RtfAttributes attrib = null;
   
  -        if (defProps != null) {
  -            attrib = convertCellAttributes(defProps, null);
  -        } else {
               attrib = new RtfAttributes();
  -        }
   
           boolean isBorderPresent = false;
   
  @@ -269,7 +292,7 @@
        * @throws ConverterException On convertion error
        */
       static RtfAttributes convertRowAttributes(PropertyList props,
  -            PropertyList defProps, RtfAttributes rtfatts)
  +            RtfAttributes rtfatts)
       throws FOPException {
   
           Property p;
  @@ -278,14 +301,10 @@
   
           RtfAttributes attrib = null;
   
  -        if (defProps != null) {
  -            attrib = convertRowAttributes(defProps, null, rtfatts);
  -        } else {
               if (rtfatts == null) {
                   attrib = new RtfAttributes();
               } else {
                   attrib = rtfatts;
  -            }
           }
   
           String attrValue;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to