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 je...@apache.org on 2004/12/08 19:52:32 UTC

cvs commit: xml-fop/src/java/org/apache/fop/render/rtf TableAttributesConverter.java FOPRtfAttributes.java

jeremias    2004/12/08 10:52:32

  Modified:    src/java/org/apache/fop/render/rtf/rtflib/rtfdoc
                        RtfColorTable.java RtfTextrun.java
                        RtfFontManager.java RtfTableRow.java
                        RtfTableCell.java RtfHeader.java RtfGenerator.java
                        RtfElement.java
               src/java/org/apache/fop/render/rtf
                        TableAttributesConverter.java FOPRtfAttributes.java
  Log:
  Make RTF output human-friendly by inserting line feeds.
  Adding support for table cell padding.
  
  Revision  Changes    Path
  1.5       +4 -1      xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java
  
  Index: RtfColorTable.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RtfColorTable.java	27 Feb 2004 17:54:01 -0000	1.4
  +++ RtfColorTable.java	8 Dec 2004 18:52:31 -0000	1.5
  @@ -184,6 +184,7 @@
               return;
           }
   
  +        header.newLine();
           header.writeGroupMark (true);
           //Don't use writeControlWord, because it appends a blank,
           //which may confuse Wordpad.
  @@ -196,11 +197,13 @@
           for (int i = 0; i < len; i++) {
               int identifier = ((Integer) colorTable.get (i)).intValue ();
   
  +            header.newLine();
               header.write ("\\red" + determineColorLevel (identifier, RED));
               header.write ("\\green" + determineColorLevel (identifier, GREEN));
               header.write ("\\blue" + determineColorLevel (identifier, BLUE) + ";");
           }
   
  +        header.newLine();
           header.writeGroupMark (false);
       }
   
  
  
  
  1.11      +3 -2      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RtfTextrun.java	27 Feb 2004 17:54:01 -0000	1.10
  +++ RtfTextrun.java	8 Dec 2004 18:52:31 -0000	1.11
  @@ -235,7 +235,7 @@
           if (rtfListItem != null) {
               rtfListItem.getRtfListStyle().writeParagraphPrefix(this);
           }
  -        
  +
           //write all children
           boolean bPrevPar = false;
           boolean bFirst = true;
  @@ -260,6 +260,7 @@
                           && e == lastParagraphBreak));
                   
               if (!bHide) {
  +                newLine();
                   e.writeRtf(); 
                   
                   if (rtfListItem != null && e instanceof RtfParagraphBreak) {
  
  
  
  1.3       +4 -1      xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontManager.java
  
  Index: RtfFontManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RtfFontManager.java	27 Feb 2004 17:54:01 -0000	1.2
  +++ RtfFontManager.java	8 Dec 2004 18:52:31 -0000	1.3
  @@ -144,6 +144,7 @@
               return;
           }
   
  +        header.newLine();
           header.writeGroupMark (true);
           header.writeControlWord ("fonttbl;");
   
  @@ -151,11 +152,13 @@
   
           for (int i = 0; i < len; i++) {
               header.writeGroupMark (true);
  +            header.newLine();
               header.write ("\\f" + i);
               header.write (" " + (String) fontTable.elementAt (i));
               header.writeGroupMark (false);
           }
   
  +        header.newLine();
           header.writeGroupMark (false);
       }
   
  
  
  
  1.8       +4 -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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RtfTableRow.java	1 Nov 2004 12:39:14 -0000	1.7
  +++ RtfTableRow.java	8 Dec 2004 18:52:31 -0000	1.8
  @@ -122,6 +122,7 @@
        * @throws IOException for I/O problems
        */
       protected void writeRtfPrefix() throws IOException {
  +        newLine();
           writeGroupMark(true);
       }
   
  @@ -276,6 +277,8 @@
             index++; // Added by Boris POUDEROUS on 2002/07/02
           }
   
  +        newLine();
  +        
           // now children can write themselves, we have the correct RTF prefix code
           super.writeRtfContent();
       }
  
  
  
  1.6       +3 -1      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RtfTableCell.java	27 Feb 2004 17:54:01 -0000	1.5
  +++ RtfTableCell.java	8 Dec 2004 18:52:31 -0000	1.6
  @@ -226,6 +226,7 @@
        *  @return widthOffset + width of this cell
        */
       int writeCellDef(int widthOffset) throws IOException {
  +        newLine();
           this.widthOffset = widthOffset;
   
           // vertical cell merge codes
  @@ -268,6 +269,7 @@
   
           writeControlWord("cellx" + xPos);
   
  +        //TODO Why is this here, right after an alignment command is written (see above)?
           writeControlWord("ql");
   
           return xPos;
  
  
  
  1.5       +6 -5      xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java
  
  Index: RtfHeader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RtfHeader.java	1 Oct 2004 09:03:24 -0000	1.4
  +++ RtfHeader.java	8 Dec 2004 18:52:31 -0000	1.5
  @@ -103,9 +103,10 @@
        *write properties for footnote handling
        */
       private void writeFootnoteProperties() throws IOException {
  -    writeControlWord("fet0");  //footnotes, not endnotes
  -    writeControlWord("ftnbj"); //place footnotes at the end of the
  -                               //page (should be the default, but
  -                               //Word 2000 thinks otherwise)
  +        newLine();
  +        writeControlWord("fet0");  //footnotes, not endnotes
  +        writeControlWord("ftnbj"); //place footnotes at the end of the
  +                                   //page (should be the default, but
  +                                   //Word 2000 thinks otherwise)
       }
   }
  
  
  
  1.2       +8 -7      xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfGenerator.java
  
  Index: RtfGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RtfGenerator.java	1 Oct 2004 09:03:24 -0000	1.1
  +++ RtfGenerator.java	8 Dec 2004 18:52:31 -0000	1.2
  @@ -37,12 +37,13 @@
        * @see org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement#writeRtfContent()
        */
       protected void writeRtfContent() throws IOException {
  -        parent.writeGroupMark(true);
  -        parent.writeStarControlWord("generator");
  -        parent.writer.write("Apache FOP ");
  -        parent.writer.write(Fop.getVersion());
  -        parent.writer.write(";");
  -        parent.writeGroupMark(false);
  +        newLine();
  +        writeGroupMark(true);
  +        writeStarControlWord("generator");
  +        writer.write("Apache FOP ");
  +        writer.write(Fop.getVersion());
  +        writer.write(";");
  +        writeGroupMark(false);
       }
   
       /**
  
  
  
  1.4       +10 -1     xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java
  
  Index: RtfElement.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RtfElement.java	1 Oct 2004 09:30:35 -0000	1.3
  +++ RtfElement.java	8 Dec 2004 18:52:31 -0000	1.4
  @@ -90,6 +90,15 @@
       }
   
       /**
  +     * Starts a new line in the RTF file being written. This is only to format
  +     * the RTF file itself (for easier debugging), not its content.
  +     * @throws IOException in case of an I/O problem
  +     */
  +    protected void newLine() throws IOException {
  +        writer.write("\n");
  +    }
  +    
  +    /**
        * Write an RTF control word to our Writer
        * @param word RTF control word to write
        * @throws IOException for I/O problems
  
  
  
  1.25      +41 -3     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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TableAttributesConverter.java	24 Nov 2004 21:07:30 -0000	1.24
  +++ TableAttributesConverter.java	8 Dec 2004 18:52:32 -0000	1.25
  @@ -116,9 +116,10 @@
           FOPRtfAttributes attrib = new FOPRtfAttributes();
   
           boolean isBorderPresent = false;
  +        CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground();
   
           // Cell background color
  -        ColorType color = fobj.getCommonBorderPaddingBackground().backgroundColor;
  +        ColorType color = border.backgroundColor;
           if ((color != null) 
                   && (color.getAlpha() != 0
                           || color.getRed() != 0
  @@ -127,7 +128,6 @@
               attrib.set(ITableAttributes.CELL_COLOR_BACKGROUND, color);
           }
   
  -        CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground();
           BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE,
                   attrib, ITableAttributes.CELL_BORDER_TOP);
           BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER,
  @@ -137,6 +137,44 @@
           BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END,
                   attrib,  ITableAttributes.CELL_BORDER_RIGHT);
   
  +        int padding;
  +        boolean reproduceMSWordBug = true;
  +        //TODO Make this configurable
  +        if (reproduceMSWordBug) {
  +            //MS Word has a bug where padding left and top are exchanged
  +            padding = border.getPaddingStart(false);
  +            if (padding != 0) {
  +                attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_TOP, padding);
  +                attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, 3 /*=twips*/);
  +            }
  +            padding = border.getPaddingBefore(false);
  +            if (padding != 0) {
  +                attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_LEFT, padding);
  +                attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_LEFT, 3 /*=twips*/);
  +            }
  +        } else {
  +            padding = border.getPaddingStart(false);
  +            if (padding != 0) {
  +                attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_LEFT, padding);
  +                attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_LEFT, 3 /*=twips*/);
  +            }
  +            padding = border.getPaddingBefore(false);
  +            if (padding != 0) {
  +                attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_TOP, padding);
  +                attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, 3 /*=twips*/);
  +            }
  +        }
  +        padding = border.getPaddingEnd(false);
  +        if (padding != 0) {
  +            attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_RIGHT, padding);
  +            attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_RIGHT, 3 /*=twips*/);
  +        }
  +        padding = border.getPaddingAfter(false);
  +        if (padding != 0) {
  +            attrib.setTwips(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, padding);
  +            attrib.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, 3 /*=twips*/);
  +        }
  +        
           int n = fobj.getNumberColumnsSpanned();
           // Column spanning :
           if (n > 1) {
  
  
  
  1.4       +12 -1     xml-fop/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java
  
  Index: FOPRtfAttributes.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FOPRtfAttributes.java	1 Nov 2004 15:04:50 -0000	1.3
  +++ FOPRtfAttributes.java	8 Dec 2004 18:52:32 -0000	1.4
  @@ -42,6 +42,17 @@
       }
   
       /**
  +     * Set an attribute using a value in millipoints (internal units in twips)
  +     * @param name name of attribute
  +     * @param value value of attribute (in millipoints)
  +     * @return this (which now contains the new entry)
  +     */
  +    public RtfAttributes setTwips(String name, int value) {
  +        set(name, value / (1000 / 20)); //Convert millipoints to twips
  +        return this;
  +    }
  +
  +    /**
        * Set an attribute that has a Length value (internal units in half-points)
        * @param name name of attribute
        * @param value value of attribute
  
  
  

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