vmote       2003/07/02 12:20:45

  Modified:    src/java/org/apache/fop/rtf/rtflib/rtfdoc
                        RtfExternalGraphic.java
  Log:
  Extract computeImageSize and writeSizeInfo methods (to reduce size of 
writeRtfContentWithException for checkstyle). Compiles but untested.
  
  Revision  Changes    Path
  1.8       +42 -31    
xml-fop/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
  
  Index: RtfExternalGraphic.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RtfExternalGraphic.java   2 Jul 2003 16:59:54 -0000       1.7
  +++ RtfExternalGraphic.java   2 Jul 2003 19:20:45 -0000       1.8
  @@ -161,6 +161,11 @@
        */
        protected int graphicCompressionRate = 80;
   
  +     /** The image data */
  +     private byte[] data = null;
  +
  +     /** The image type */
  +     private int type;
   
       //////////////////////////////////////////////////
       // @@ Construction
  @@ -236,7 +241,7 @@
   //        getRtfFile ().getLog ().logInfo ("Writing image '" + url + "'.");
   
   
  -        byte[] data = null;
  +        data = null;
           try {
               // image reading patch provided by Michael Krause <[EMAIL PROTECTED]>
               final BufferedInputStream bin = new 
BufferedInputStream(url.openStream());
  @@ -262,7 +267,7 @@
   
           // Determine image file format
           String file = url.getFile ();
  -        int type = determineImageType(data, file.substring(file.lastIndexOf(".") + 
1));
  +        type = determineImageType(data, file.substring(file.lastIndexOf(".") + 1));
   
           if (type >= ImageConstants.I_TO_CONVERT_BASIS) {
               // convert
  @@ -311,6 +316,38 @@
   
           writeControlWord(rtfImageCode);
   
  +        computeImageSize();
  +        writeSizeInfo();
  +
  +        for (int i = 0; i < data.length; i++) {
  +            int iData = data [i];
  +
  +            // Make positive byte
  +            if (iData < 0) {
  +                iData += 256;
  +            }
  +
  +            if (iData < 16) {
  +                // Set leading zero and append
  +                buf.append('0');
  +            }
  +
  +            buf.append(Integer.toHexString(iData));
  +        }
  +
  +        int len = buf.length();
  +        char[] chars = new char[len];
  +
  +        buf.getChars(0, len, chars, 0);
  +        writer.write(chars);
  +
  +        // Writes the end of RTF image
  +
  +        writeGroupMark(false);
  +        writeGroupMark(false);
  +    }
  +
  +    private void computeImageSize () {
           if (type == ImageConstants.I_PNG) {
               width = ImageUtil.getIntFromByteArray(data, 16, 4, true);
               height = ImageUtil.getIntFromByteArray(data, 20, 4, true);
  @@ -342,7 +379,9 @@
               width = ImageUtil.getIntFromByteArray(data, 151, 4, false);
               height = ImageUtil.getIntFromByteArray(data, 155, 4, false);
           }
  +    }
   
  +    private void writeSizeInfo () throws IOException {
           // Set image size
           if (width != -1) {
               writeControlWord("picw" + width);
  @@ -382,35 +421,7 @@
                   writeControlWord("picscaley" + widthDesired * 100 / width);
               }
           }
  -
  -        for (int i = 0; i < data.length; i++) {
  -            int iData = data [i];
  -
  -            // Make positive byte
  -            if (iData < 0) {
  -                iData += 256;
  -            }
  -
  -            if (iData < 16) {
  -                // Set leading zero and append
  -                buf.append('0');
  -            }
  -
  -            buf.append(Integer.toHexString(iData));
  -        }
  -
  -        int len = buf.length();
  -        char[] chars = new char[len];
  -
  -        buf.getChars(0, len, chars, 0);
  -        writer.write(chars);
  -
  -        // Writes the end of RTF image
  -
  -        writeGroupMark(false);
  -        writeGroupMark(false);
       }
  -
   
       //////////////////////////////////////////////////
       // @@ Member access
  
  
  

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

Reply via email to