keiron      02/02/25 01:31:03

  Modified:    src/org/apache/fop/image AbstractFopImage.java BmpImage.java
                        EPSImage.java FopImage.java GifImage.java
                        ImageFactory.java JAIImage.java JimiImage.java
                        JpegImage.java SVGImage.java
               src/org/apache/fop/image/analyser BMPReader.java
                        EPSReader.java GIFReader.java ImageReader.java
                        ImageReaderFactory.java JPEGReader.java
                        PNGReader.java SVGReader.java TIFFReader.java
  Removed:     src/org/apache/fop/image/analyser AbstractImageReader.java
  Log:
  improved thread safety of readers
  
  Revision  Changes    Path
  1.7       +7 -7      xml-fop/src/org/apache/fop/image/AbstractFopImage.java
  
  Index: AbstractFopImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/AbstractFopImage.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractFopImage.java     21 Feb 2002 09:54:27 -0000      1.6
  +++ AbstractFopImage.java     25 Feb 2002 09:31:03 -0000      1.7
  @@ -1,5 +1,5 @@
   /*
  - * $Id: AbstractFopImage.java,v 1.6 2002/02/21 09:54:27 keiron Exp $
  + * $Id: AbstractFopImage.java,v 1.7 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -45,7 +45,7 @@
       /**
        * ImageReader object (to obtain image header informations).
        */
  -    protected ImageReader m_imageReader = null;
  +    protected FopImage.ImageInfo imageInfo = null;
   
       /**
        * Image color space (org.apache.fop.datatypes.ColorSpace).
  @@ -95,16 +95,16 @@
        * imgReader ImageReader object
        * @return a new FopImage object
        */
  -    public AbstractFopImage(URL href, ImageReader imgReader) {
  +    public AbstractFopImage(URL href, FopImage.ImageInfo info) {
           this.m_href = href;
  -        this.m_imageReader = imgReader;
  -        this.m_width = this.m_imageReader.getWidth();
  -        this.m_height = this.m_imageReader.getHeight();
  +        this.imageInfo = info;
  +        this.m_width = this.imageInfo.width;
  +        this.m_height = this.imageInfo.height;
           loaded = loaded & DIMENSIONS;
       }
   
       public String getMimeType() {
  -        return m_imageReader.getMimeType();
  +        return imageInfo.mimeType;
       }
   
       /**
  
  
  
  1.5       +2 -2      xml-fop/src/org/apache/fop/image/BmpImage.java
  
  Index: BmpImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/BmpImage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BmpImage.java     21 Feb 2002 09:54:27 -0000      1.4
  +++ BmpImage.java     25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: BmpImage.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: BmpImage.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -26,7 +26,7 @@
   import org.apache.fop.fo.FOUserAgent;
   
   public class BmpImage extends AbstractFopImage {
  -    public BmpImage(URL href, ImageReader imgReader) {
  +    public BmpImage(URL href, FopImage.ImageInfo imgReader) {
           super(href, imgReader);
       }
   
  
  
  
  1.5       +33 -13    xml-fop/src/org/apache/fop/image/EPSImage.java
  
  Index: EPSImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/EPSImage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EPSImage.java     21 Feb 2002 09:54:27 -0000      1.4
  +++ EPSImage.java     25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: EPSImage.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: EPSImage.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -32,8 +32,7 @@
       private String docName;
       private int[] bbox;
   
  -    private byte[] epsImage = null;
  -    private EPSReader epsReader = null;
  +    private EPSData epsData = null;
   
       /**
        * Initialize docName and bounding box
  @@ -62,23 +61,44 @@
           return bbox;
       }
   
  -    public EPSImage(URL href, ImageReader imgReader) {
  -        super(href, imgReader);
  +    public EPSImage(URL href, FopImage.ImageInfo imgInfo) {
  +        super(href, imgInfo);
           init(href);
  -        if (imgReader instanceof EPSReader) {
  -            EPSReader eimgReader = (EPSReader) imgReader;
  -            epsReader = eimgReader;
  -            epsImage = eimgReader.getEpsFile();
  -            m_bitmaps = epsImage;
  -            bbox = eimgReader.getBBox();
  +        if (imgInfo.data instanceof EPSData) {
  +            epsData = (EPSData) imgInfo.data;
  +            bbox = new int[4];
  +            bbox[0] = (int) epsData.bbox[0];
  +            bbox[1] = (int) epsData.bbox[1];
  +            bbox[2] = (int) epsData.bbox[2];
  +            bbox[3] = (int) epsData.bbox[3];
  +
           }
       }
   
       public byte[] getEPSImage() {
  -        if (epsImage == null) {
  +        if (epsData.epsFile == null) {
               //log.error("ERROR LOADING EXTERNAL EPS");
           }
  -        return epsImage;
  +        return epsData.epsFile;
  +    }
  +
  +    public static class EPSData {
  +        public long[] bbox;
  +        public boolean isAscii; // True if plain ascii eps file
  +
  +        // offsets if not ascii
  +        public long psStart = 0;
  +        public long psLength = 0;
  +        public long wmfStart = 0;
  +        public long wmfLength = 0;
  +        public long tiffStart = 0;
  +        public long tiffLength = 0;
  +
  +        /** raw eps file */
  +        public byte[] rawEps;
  +        /** eps part */
  +        public byte[] epsFile;
  +        public byte[] preview = null;
       }
   
   }
  
  
  
  1.10      +12 -1     xml-fop/src/org/apache/fop/image/FopImage.java
  
  Index: FopImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/FopImage.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FopImage.java     21 Feb 2002 09:54:27 -0000      1.9
  +++ FopImage.java     25 Feb 2002 09:31:03 -0000      1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: FopImage.java,v 1.9 2002/02/21 09:54:27 keiron Exp $
  + * $Id: FopImage.java,v 1.10 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -10,6 +10,8 @@
   
   package org.apache.fop.image;
   
  +import java.io.InputStream;
  +
   import org.apache.fop.datatypes.ColorSpace;
   import org.apache.fop.pdf.PDFColor;
   import org.apache.fop.pdf.PDFFilter;
  @@ -61,5 +63,14 @@
       public int getRessourceBytesSize();
       // return null if no corresponding PDFFilter
       public PDFFilter getPDFFilter();
  +
  +    public static class ImageInfo {
  +        public InputStream stream;
  +        public int width;
  +        public int height;
  +        public Object data;
  +        public String mimeType;
  +    }
  +
   }
   
  
  
  
  1.3       +2 -2      xml-fop/src/org/apache/fop/image/GifImage.java
  
  Index: GifImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/GifImage.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GifImage.java     21 Feb 2002 09:54:27 -0000      1.2
  +++ GifImage.java     25 Feb 2002 09:31:03 -0000      1.3
  @@ -1,5 +1,5 @@
   /*
  - * $Id: GifImage.java,v 1.2 2002/02/21 09:54:27 keiron Exp $
  + * $Id: GifImage.java,v 1.3 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -27,7 +27,7 @@
    * @see FopImage
    */
   public class GifImage extends AbstractFopImage {
  -    public GifImage(URL href, ImageReader imgReader) {
  +    public GifImage(URL href, FopImage.ImageInfo imgReader) {
           super(href, imgReader);
       }
   
  
  
  
  1.3       +13 -13    xml-fop/src/org/apache/fop/image/ImageFactory.java
  
  Index: ImageFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/ImageFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ImageFactory.java 22 Feb 2002 09:18:47 -0000      1.2
  +++ ImageFactory.java 25 Feb 2002 09:31:03 -0000      1.3
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ImageFactory.java,v 1.2 2002/02/22 09:18:47 keiron Exp $
  + * $Id: ImageFactory.java,v 1.3 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -119,7 +119,7 @@
               }
               imgIS = absoluteURL.openStream();
           } catch (MalformedURLException e_context) {
  -            log.error("Error with image URL: " + e_context.getMessage());
  +            log.error("Error with image URL: " + e_context.getMessage(), e_context);
               return null;
           }
           catch (Exception e) {
  @@ -134,22 +134,22 @@
               } catch (MalformedURLException e_context) {
                   // pb context url
                   log.error( "Invalid Image URL - error on relative URL : " +
  -                           e_context.getMessage());
  +                           e_context.getMessage(), e_context);
                   return null;
               }
           }
   
           // If not, check image type
  -        ImageReader imgReader = null;
  +        FopImage.ImageInfo imgInfo = null;
           try {
               if (imgIS == null) {
                   imgIS = absoluteURL.openStream();
               }
  -            imgReader = ImageReaderFactory.make(
  +            imgInfo = ImageReaderFactory.make(
                             absoluteURL.toExternalForm(), imgIS, ua);
           } catch (Exception e) {
               log.error("Error while recovering Image Informations (" +
  -                      absoluteURL.toString() + ") : " + e.getMessage());
  +                      absoluteURL.toString() + ") : " + e.getMessage(), e);
               return null;
           }
           finally { if (imgIS != null) {
  @@ -157,13 +157,13 @@
                             imgIS.close();
                     } catch (IOException e) {}
                     }
  -            } if (imgReader == null) {
  +            } if (imgInfo == null) {
               log.error("No ImageReader for this type of image (" +
                         absoluteURL.toString() + ")");
               return null;
           }
           // Associate mime-type to FopImage class
  -        String imgMimeType = imgReader.getMimeType();
  +        String imgMimeType = imgInfo.mimeType;
           String imgClassName = null;
           if ("image/gif".equals(imgMimeType)) {
               imgClassName = "org.apache.fop.image.GifImage";
  @@ -201,14 +201,14 @@
           try {
               imageClass = Class.forName(imgClassName);
               Class[] imageConstructorParameters = new Class[2];
  -            imageConstructorParameters[0] = Class.forName("java.net.URL");
  -            imageConstructorParameters[1] = 
Class.forName("org.apache.fop.image.analyser.ImageReader");
  +            imageConstructorParameters[0] = java.net.URL.class;
  +            imageConstructorParameters[1] = 
org.apache.fop.image.FopImage.ImageInfo.class;
               Constructor imageConstructor =
                 imageClass.getDeclaredConstructor(
                   imageConstructorParameters);
               Object[] initArgs = new Object[2];
               initArgs[0] = absoluteURL;
  -            initArgs[1] = imgReader;
  +            initArgs[1] = imgInfo;
               imageInstance = imageConstructor.newInstance(initArgs);
           } catch (java.lang.reflect.InvocationTargetException ex) {
               Throwable t = ex.getTargetException();
  @@ -219,13 +219,13 @@
                   msg = ex.getMessage();
               }
               log.error("Error creating FopImage object (" +
  -                      absoluteURL.toString() + ") : " + msg);
  +                      absoluteURL.toString() + ") : " + msg, (t == null) ? ex:t);
               return null;
           }
           catch (Exception ex) {
               log.error("Error creating FopImage object (" +
                         "Error creating FopImage object (" +
  -                      absoluteURL.toString() + ") : " + ex.getMessage());
  +                      absoluteURL.toString() + ") : " + ex.getMessage(), ex);
               return null;
           }
           if (!(imageInstance instanceof org.apache.fop.image.FopImage)) {
  
  
  
  1.4       +2 -2      xml-fop/src/org/apache/fop/image/JAIImage.java
  
  Index: JAIImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/JAIImage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JAIImage.java     21 Feb 2002 09:54:27 -0000      1.3
  +++ JAIImage.java     25 Feb 2002 09:31:03 -0000      1.4
  @@ -1,5 +1,5 @@
   /*
  - * $Id: JAIImage.java,v 1.3 2002/02/21 09:54:27 keiron Exp $
  + * $Id: JAIImage.java,v 1.4 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -38,7 +38,7 @@
           super(href);
       }
   
  -    public JAIImage(URL href, ImageReader imgReader) {
  +    public JAIImage(URL href, FopImage.ImageInfo imgReader) {
           super(href, imgReader);
       }
   
  
  
  
  1.10      +2 -2      xml-fop/src/org/apache/fop/image/JimiImage.java
  
  Index: JimiImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/JimiImage.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JimiImage.java    21 Feb 2002 09:54:27 -0000      1.9
  +++ JimiImage.java    25 Feb 2002 09:31:03 -0000      1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: JimiImage.java,v 1.9 2002/02/21 09:54:27 keiron Exp $
  + * $Id: JimiImage.java,v 1.10 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -29,7 +29,7 @@
    * @see FopImage
    */
   public class JimiImage extends AbstractFopImage {
  -    public JimiImage(URL href, ImageReader imgReader) {
  +    public JimiImage(URL href, FopImage.ImageInfo imgReader) {
           super(href, imgReader);
           try {
               Class c = Class.forName("com.sun.jimi.core.Jimi");
  
  
  
  1.4       +2 -2      xml-fop/src/org/apache/fop/image/JpegImage.java
  
  Index: JpegImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/JpegImage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JpegImage.java    21 Feb 2002 09:54:27 -0000      1.3
  +++ JpegImage.java    25 Feb 2002 09:31:03 -0000      1.4
  @@ -1,5 +1,5 @@
   /*
  - * $Id: JpegImage.java,v 1.3 2002/02/21 09:54:27 keiron Exp $
  + * $Id: JpegImage.java,v 1.4 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -32,7 +32,7 @@
       boolean found_icc_profile = false;
       boolean found_dimensions = false;
   
  -    public JpegImage(URL href, ImageReader imgReader) {
  +    public JpegImage(URL href, FopImage.ImageInfo imgReader) {
           super(href, imgReader);
       }
   
  
  
  
  1.11      +5 -5      xml-fop/src/org/apache/fop/image/SVGImage.java
  
  Index: SVGImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/SVGImage.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SVGImage.java     22 Feb 2002 09:09:35 -0000      1.10
  +++ SVGImage.java     25 Feb 2002 09:31:03 -0000      1.11
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGImage.java,v 1.10 2002/02/22 09:09:35 keiron Exp $
  + * $Id: SVGImage.java,v 1.11 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -26,10 +26,10 @@
   public class SVGImage extends AbstractFopImage {
       SVGDocument doc;
   
  -    public SVGImage(URL href, ImageReader imgReader) {
  -        super(href, imgReader);
  -        if(imgReader instanceof SVGReader) {
  -            doc = (SVGDocument)((SVGReader)imgReader).getDocument();
  +    public SVGImage(URL href, FopImage.ImageInfo imgInfo) {
  +        super(href, imgInfo);
  +        if(imgInfo.data instanceof SVGDocument) {
  +            doc = (SVGDocument)imgInfo.data;
           }
       }
   
  
  
  
  1.5       +23 -20    xml-fop/src/org/apache/fop/image/analyser/BMPReader.java
  
  Index: BMPReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/BMPReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BMPReader.java    21 Feb 2002 09:54:27 -0000      1.4
  +++ BMPReader.java    25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: BMPReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: BMPReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -18,29 +19,29 @@
    * @author Pankaj Narula
    * @version 1.0
    */
  -public class BMPReader extends AbstractImageReader {
  +public class BMPReader implements ImageReader {
       static protected final int BMP_SIG_LENGTH = 26;
   
  -    protected byte[] header;
  -
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        this.setDefaultHeader();
  +        byte[] header = getDefaultHeader(fis);
           boolean supported = ((header[0] == (byte) 0x42) &&
                                (header[1] == (byte) 0x4d));
           if (supported) {
  -            setDimension();
  -            return true;
  -        } else
  -            return false;
  +            return getDimension(header);
  +        } else {
  +            return null;
  +        }
       }
   
       public String getMimeType() {
           return "image/bmp";
       }
   
  -    protected void setDimension() {
  +    protected FopImage.ImageInfo getDimension(byte[] header) {
  +        FopImage.ImageInfo info = new FopImage.ImageInfo();
  +        info.mimeType = getMimeType();
  +
           // little endian notation
           int byte1 = header[18] & 0xff;
           int byte2 = header[19] & 0xff;
  @@ -48,28 +49,30 @@
           int byte4 = header[21] & 0xff;
           long l = (long)((byte4 << 24) | (byte3 << 16) |
                           (byte2 << 8) | byte1);
  -        this.width = (int)(l & 0xffffffff);
  +        info.width = (int)(l & 0xffffffff);
   
           byte1 = header[22] & 0xff;
           byte2 = header[23] & 0xff;
           byte3 = header[24] & 0xff;
           byte4 = header[25] & 0xff;
           l = (long)((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
  -        this.height = (int)(l & 0xffffffff);
  +        info.height = (int)(l & 0xffffffff);
  +        return info;
       }
   
  -    protected void setDefaultHeader() throws IOException {
  -        this.header = new byte[BMP_SIG_LENGTH];
  +    protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws 
IOException {
  +        byte[] header = new byte[BMP_SIG_LENGTH];
           try {
  -            this.imageStream.mark(BMP_SIG_LENGTH + 1);
  -            this.imageStream.read(header);
  -            this.imageStream.reset();
  +            imageStream.mark(BMP_SIG_LENGTH + 1);
  +            imageStream.read(header);
  +            imageStream.reset();
           } catch (IOException ex) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ex;
           }
  +        return header;
       }
   
   }
  
  
  
  1.4       +55 -80    xml-fop/src/org/apache/fop/image/analyser/EPSReader.java
  
  Index: EPSReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/EPSReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EPSReader.java    21 Feb 2002 09:54:27 -0000      1.3
  +++ EPSReader.java    25 Feb 2002 09:31:03 -0000      1.4
  @@ -1,5 +1,5 @@
   /*
  - * $Id: EPSReader.java,v 1.3 2002/02/21 09:54:27 keiron Exp $
  + * $Id: EPSReader.java,v 1.4 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -17,28 +17,14 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
   
  +import org.apache.fop.image.FopImage;
  +import org.apache.fop.image.EPSImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
    * ImageReader object for EPS document image type.
    */
  -public class EPSReader extends AbstractImageReader {
  -    private long[] bbox;
  -    private boolean isAscii; // True if plain ascii eps file
  -
  -    // offsets if not ascii
  -    long psStart = 0;
  -    long psLength = 0;
  -    long wmfStart = 0;
  -    long wmfLength = 0;
  -    long tiffStart = 0;
  -    long tiffLength = 0;
  -
  -    /** raw eps file */
  -    private byte[] rawEps;
  -    /** eps part */
  -    private byte[] epsFile;
  -    private byte[] preview = null;
  +public class EPSReader implements ImageReader {
   
       private long getLong(byte[] buf, int idx) {
           int b1 = buf[idx] & 0xff;
  @@ -49,55 +35,60 @@
           return (long)((b4 << 24) | (b3 << 16) | (b2 << 8) | b1);
       }
   
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
           boolean isEPS = false;
  -        this.imageStream = fis;
           fis.mark(32);
           byte[] header = new byte[30];
           fis.read(header, 0, 30);
           fis.reset();
   
  +        EPSImage.EPSData data = new EPSImage.EPSData();
  +
           // Check if binary header
           if (getLong(header, 0) == 0xC6D3D0C5) {
  -            isAscii = false;
  +            data.isAscii = false;
               isEPS = true;
   
  -            psStart = getLong(header, 4);
  -            psLength = getLong(header, 8);
  -            wmfStart = getLong(header, 12);
  -            wmfLength = getLong(header, 16);
  -            tiffStart = getLong(header, 20);
  -            tiffLength = getLong(header, 24);
  +            data.psStart = getLong(header, 4);
  +            data.psLength = getLong(header, 8);
  +            data.wmfStart = getLong(header, 12);
  +            data.wmfLength = getLong(header, 16);
  +            data.tiffStart = getLong(header, 20);
  +            data.tiffLength = getLong(header, 24);
   
           } else {
               // Check if plain ascii
               byte[] epsh = "%!PS".getBytes();
               if (epsh[0] == header[0] && epsh[1] == header[1] &&
                       epsh[2] == header[2] && epsh[3] == header[3]) {
  -                isAscii = true;
  +                data.isAscii = true;
                   isEPS = true;
               }
           }
   
           if (isEPS) {
  -            readEPSImage(fis);
  -            bbox = readBBox();
  -
  -            if (bbox != null) {
  -                width = (int)(bbox[2] - bbox[0]);
  -                height = (int)(bbox[3] - bbox[1]);
  +            FopImage.ImageInfo info = new FopImage.ImageInfo();
  +            info.mimeType = getMimeType();
  +            info.data = data;
  +            readEPSImage(fis, data);
  +            data.bbox = readBBox(data);
  +
  +            if (data.bbox != null) {
  +                info.width = (int)(data.bbox[2] - data.bbox[0]);
  +                info.height = (int)(data.bbox[3] - data.bbox[1]);
  +                return info;
               } else {
                   // Ain't eps if no BoundingBox
                   isEPS = false;
               }
           }
   
  -        return isEPS;
  +        return null;
       }
   
       /** read the eps file and extract eps part */
  -    private void readEPSImage(BufferedInputStream fis) throws IOException {
  +    private void readEPSImage(BufferedInputStream fis, EPSImage.EPSData data) 
throws IOException {
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           byte[] file;
           byte[] readBuf = new byte[20480];
  @@ -117,49 +108,44 @@
   
           file = baos.toByteArray();
   
  -        if (isAscii) {
  -            rawEps = null;
  -            epsFile = new byte[file.length];
  -            System.arraycopy(file, 0, epsFile, 0, epsFile.length);
  +        if (data.isAscii) {
  +            data.rawEps = null;
  +            data.epsFile = new byte[file.length];
  +            System.arraycopy(file, 0, data.epsFile, 0, data.epsFile.length);
           } else {
  -            rawEps = new byte[file.length];
  -            epsFile = new byte[(int) psLength];
  -            System.arraycopy(file, 0, rawEps, 0, rawEps.length);
  -            System.arraycopy(rawEps, (int) psStart, epsFile, 0,
  -                             (int) psLength);
  +            data.rawEps = new byte[file.length];
  +            data.epsFile = new byte[(int) data.psLength];
  +            System.arraycopy(file, 0, data.rawEps, 0, data.rawEps.length);
  +            System.arraycopy(data.rawEps, (int) data.psStart, data.epsFile, 0,
  +                             (int) data.psLength);
           }
       }
   
  -    public byte[] getEpsFile() {
  -        return epsFile;
  -    }
  -
       /* Get embedded preview or null */
  -    public byte[] getPreview() {
  -        InputStream is = null;
  -        if (preview == null) {
  -            if (tiffLength > 0) {
  -                preview = new byte[(int) tiffLength];
  -                System.arraycopy(rawEps, (int) tiffStart, preview, 0,
  -                                 (int) tiffLength);
  +    public byte[] getPreview(EPSImage.EPSData data) {
  +        if (data.preview == null) {
  +            if (data.tiffLength > 0) {
  +                data.preview = new byte[(int) data.tiffLength];
  +                System.arraycopy(data.rawEps, (int) data.tiffStart, data.preview, 0,
  +                                 (int) data.tiffLength);
               }
           }
  -        return preview;
  +        return data.preview;
       }
   
       /** Extract bounding box from eps part
        */
  -    private long[] readBBox() {
  +    private long[] readBBox(EPSImage.EPSData data) {
           long[] mbbox = null;
           int idx = 0;
           byte[] bbxName = "%%BoundingBox: ".getBytes();
           boolean found = false;
   
  -        while (!found && (epsFile.length > (idx + bbxName.length))) {
  +        while (!found && (data.epsFile.length > (idx + bbxName.length))) {
               boolean sfound = true;
               int i = idx;
               for (i = idx; sfound && (i - idx) < bbxName.length; i++) {
  -                if (bbxName[i - idx] != epsFile[i])
  +                if (bbxName[i - idx] != data.epsFile[i])
                       sfound = false;
               }
               if (sfound) {
  @@ -175,26 +161,26 @@
   
   
           mbbox = new long[4];
  -        idx += readLongString(mbbox, 0, idx);
  -        idx += readLongString(mbbox, 1, idx);
  -        idx += readLongString(mbbox, 2, idx);
  -        idx += readLongString(mbbox, 3, idx);
  +        idx += readLongString(data, mbbox, 0, idx);
  +        idx += readLongString(data, mbbox, 1, idx);
  +        idx += readLongString(data, mbbox, 2, idx);
  +        idx += readLongString(data, mbbox, 3, idx);
   
           return mbbox;
       }
   
  -    private int readLongString(long[] mbbox, int i, int idx) {
  -        while (idx < epsFile.length && (epsFile[idx] == 32))
  +    private int readLongString(EPSImage.EPSData data, long[] mbbox, int i, int idx) 
{
  +        while (idx < data.epsFile.length && (data.epsFile[idx] == 32))
               idx++;
   
           int nidx = idx;
   
  -        while (nidx < epsFile.length &&
  -                (epsFile[nidx] >= 48 && epsFile[nidx] <= 57))
  +        while (nidx < data.epsFile.length &&
  +                (data.epsFile[nidx] >= 48 && data.epsFile[nidx] <= 57))
               nidx++;
   
           byte[] num = new byte[nidx - idx];
  -        System.arraycopy(epsFile, idx, num, 0, nidx - idx);
  +        System.arraycopy(data.epsFile, idx, num, 0, nidx - idx);
           String ns = new String(num);
           mbbox[i] = Long.parseLong(ns);
   
  @@ -205,16 +191,5 @@
           return "image/eps";
       }
   
  -    /**
  -     * Return the BoundingBox
  -     */
  -    public int[] getBBox() {
  -        int[] bbox = new int[4];
  -        bbox[0] = (int) this.bbox[0];
  -        bbox[1] = (int) this.bbox[1];
  -        bbox[2] = (int) this.bbox[2];
  -        bbox[3] = (int) this.bbox[3];
  -        return bbox;
  -    }
   }
   
  
  
  
  1.5       +21 -18    xml-fop/src/org/apache/fop/image/analyser/GIFReader.java
  
  Index: GIFReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/GIFReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GIFReader.java    21 Feb 2002 09:54:27 -0000      1.4
  +++ GIFReader.java    25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: GIFReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: GIFReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -18,52 +19,54 @@
    * @author Pankaj Narula
    * @version 1.0
    */
  -public class GIFReader extends AbstractImageReader {
  +public class GIFReader implements ImageReader {
       static protected final int GIF_SIG_LENGTH = 10;
  -    protected byte[] header;
   
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        this.setDefaultHeader();
  +        byte[] header = getDefaultHeader(fis);
           boolean supported = ((header[0] == 'G') && (header[1] == 'I') &&
                                (header[2] == 'F') && (header[3] == '8') &&
                                (header[4] == '7' || header[4] == '9') &&
                                (header[5] == 'a'));
           if (supported) {
  -            setDimension();
  -            return true;
  +            FopImage.ImageInfo info = getDimension(header);
  +            info.mimeType = getMimeType();
  +            return info;
           } else
  -            return false;
  +            return null;
       }
   
       public String getMimeType() {
           return "image/gif";
       }
   
  -    protected void setDimension() {
  +    protected FopImage.ImageInfo getDimension(byte[] header) {
  +        FopImage.ImageInfo info = new FopImage.ImageInfo();
           // little endian notation
           int byte1 = header[6] & 0xff;
           int byte2 = header[7] & 0xff;
  -        this.width = ((byte2 << 8) | byte1) & 0xffff;
  +        info.width = ((byte2 << 8) | byte1) & 0xffff;
   
           byte1 = header[8] & 0xff;
           byte2 = header[9] & 0xff;
  -        this.height = ((byte2 << 8) | byte1) & 0xffff;
  +        info.height = ((byte2 << 8) | byte1) & 0xffff;
  +        return info;
       }
   
  -    protected void setDefaultHeader() throws IOException {
  -        this.header = new byte[GIF_SIG_LENGTH];
  +    protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws 
IOException {
  +        byte[] header = new byte[GIF_SIG_LENGTH];
           try {
  -            this.imageStream.mark(GIF_SIG_LENGTH + 1);
  -            this.imageStream.read(header);
  -            this.imageStream.reset();
  +            imageStream.mark(GIF_SIG_LENGTH + 1);
  +            imageStream.read(header);
  +            imageStream.reset();
           } catch (IOException ex) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ex;
           }
  +        return header;
       }
   
   }
  
  
  
  1.5       +3 -25     xml-fop/src/org/apache/fop/image/analyser/ImageReader.java
  
  Index: ImageReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/ImageReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ImageReader.java  21 Feb 2002 09:54:27 -0000      1.4
  +++ ImageReader.java  25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ImageReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: ImageReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -26,31 +27,8 @@
        * @return true if image type is the handled one
        * @exception IOException io error
        */
  -    public boolean verifySignature(String uri, BufferedInputStream bis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
                                      FOUserAgent ua) throws IOException;
   
  -    /**
  -     * Return the used InputStream.
  -     * @return BufferedInputStream used to verify image type
  -     */
  -    public BufferedInputStream getInputStream();
  -
  -    /**
  -     * Return correspondig mime type.
  -     * @return image mime type
  -     */
  -    public String getMimeType();
  -
  -    /**
  -     * Return the image height.
  -     * @return image height
  -     */
  -    public int getHeight();
  -
  -    /**
  -     * Return the image width.
  -     * @return image width
  -     */
  -    public int getWidth();
   }
   
  
  
  
  1.9       +6 -4      
xml-fop/src/org/apache/fop/image/analyser/ImageReaderFactory.java
  
  Index: ImageReaderFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/org/apache/fop/image/analyser/ImageReaderFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ImageReaderFactory.java   21 Feb 2002 09:54:27 -0000      1.8
  +++ ImageReaderFactory.java   25 Feb 2002 09:31:03 -0000      1.9
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ImageReaderFactory.java,v 1.8 2002/02/21 09:54:27 keiron Exp $
  + * $Id: ImageReaderFactory.java,v 1.9 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -13,6 +13,7 @@
   import java.io.IOException;
   import java.util.ArrayList;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -40,7 +41,7 @@
        * @return ImageReader object
        * image type is not supported
        */
  -    static public ImageReader make(String uri, InputStream in,
  +    static public FopImage.ImageInfo make(String uri, InputStream in,
                                      FOUserAgent ua) {
   
           ImageReader reader;
  @@ -48,8 +49,9 @@
           try {
               for (int count = 0; count < formats.size(); count++) {
                   reader = (ImageReader) formats.get(count);
  -                if (reader.verifySignature(uri, bis, ua)) {
  -                    return reader;
  +                FopImage.ImageInfo info = reader.verifySignature(uri, bis, ua);
  +                if(info != null) {
  +                    return info;
                   }
               }
           } catch (IOException ex) {
  
  
  
  1.5       +29 -26    xml-fop/src/org/apache/fop/image/analyser/JPEGReader.java
  
  Index: JPEGReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/JPEGReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JPEGReader.java   21 Feb 2002 09:54:27 -0000      1.4
  +++ JPEGReader.java   25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: JPEGReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: JPEGReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -18,7 +19,7 @@
    * @author Pankaj Narula
    * @version 1.0
    */
  -public class JPEGReader extends AbstractImageReader {
  +public class JPEGReader implements ImageReader {
   
       /**
        * Only SOFn and APPn markers are defined as SOFn is needed for the height and
  @@ -39,40 +40,41 @@
       static protected final int SOI = 0xd8; // start of Image
       static protected final int JPG_SIG_LENGTH = 2;
   
  -    protected byte[] header;
  -
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        this.setDefaultHeader();
  +        byte[] header = getDefaultHeader(fis);
           boolean supported = ((header[0] == (byte) 0xff) &&
                                (header[1] == (byte) 0xd8));
           if (supported) {
  -            setDimension();
  -            return true;
  -        } else
  -            return false;
  +            FopImage.ImageInfo info = getDimension(fis);
  +            info.mimeType = getMimeType();
  +            return info;
  +        } else {
  +            return null;
  +        }
       }
   
       public String getMimeType() {
           return "image/jpeg";
       }
   
  -    protected void setDefaultHeader() throws IOException {
  -        this.header = new byte[JPG_SIG_LENGTH];
  +    protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws 
IOException {
  +        byte[] header = new byte[JPG_SIG_LENGTH];
           try {
  -            this.imageStream.mark(JPG_SIG_LENGTH + 1);
  -            this.imageStream.read(header);
  -            this.imageStream.reset();
  +            imageStream.mark(JPG_SIG_LENGTH + 1);
  +            imageStream.read(header);
  +            imageStream.reset();
           } catch (IOException ex) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ex;
           }
  +        return header;
       }
   
  -    protected void setDimension() throws IOException {
  +    protected FopImage.ImageInfo getDimension(BufferedInputStream imageStream) 
throws IOException {
  +        FopImage.ImageInfo info = new FopImage.ImageInfo();
           try {
               int marker = NULL;
               long length, skipped;
  @@ -94,32 +96,33 @@
                       case SOF2:
                       case SOF3: // SOF3 and SOFA are only supported by PDF 1.3
                       case SOFA:
  -                        this.skip(3);
  -                        this.height = this.read2bytes();
  -                        this.width = this.read2bytes();
  +                        this.skip(imageStream, 3);
  +                        info.height = this.read2bytes(imageStream);
  +                        info.width = this.read2bytes(imageStream);
                           break outer;
                       default:
  -                        length = this.read2bytes();
  -                        skipped = this.skip(length - 2);
  +                        length = this.read2bytes(imageStream);
  +                        skipped = this.skip(imageStream, length - 2);
                           if (skipped != length - 2)
                               throw new IOException("Skipping Error");
                   }
               }
           } catch (IOException ioe) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ioe;
           }
  +        return info;
       }
   
  -    protected int read2bytes() throws IOException {
  +    protected int read2bytes(BufferedInputStream imageStream) throws IOException {
           int byte1 = imageStream.read();
           int byte2 = imageStream.read();
           return (int)((byte1 << 8) | byte2);
       }
   
  -    protected long skip(long n) throws IOException {
  +    protected long skip(BufferedInputStream imageStream, long n) throws IOException 
{
           long discarded = 0;
           while (discarded != n) {
               imageStream.read();
  
  
  
  1.5       +24 -20    xml-fop/src/org/apache/fop/image/analyser/PNGReader.java
  
  Index: PNGReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/PNGReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PNGReader.java    21 Feb 2002 09:54:27 -0000      1.4
  +++ PNGReader.java    25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: PNGReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: PNGReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -18,31 +19,33 @@
    * @author Pankaj Narula
    * @version 1.0
    */
  -public class PNGReader extends AbstractImageReader {
  +public class PNGReader implements ImageReader {
       static protected final int PNG_SIG_LENGTH = 24;
  -    protected byte[] header;
   
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        this.setDefaultHeader();
  +        byte[] header = getDefaultHeader(fis);
           boolean supported = ((header[0] == (byte) 0x89) &&
                                (header[1] == (byte) 0x50) && (header[2] == (byte) 
0x4e) &&
                                (header[3] == (byte) 0x47) && (header[4] == (byte) 
0x0d) &&
                                (header[5] == (byte) 0x0a) &&
                                (header[6] == (byte) 0x1a) && (header[7] == (byte) 
0x0a));
           if (supported) {
  -            setDimension();
  -            return true;
  -        } else
  -            return false;
  +            FopImage.ImageInfo info = getDimension(header);
  +            info.mimeType = getMimeType();
  +            return info;
  +        } else {
  +            return null;
  +        }
       }
   
       public String getMimeType() {
           return "image/png";
       }
   
  -    protected void setDimension() {
  +    protected FopImage.ImageInfo getDimension(byte[] header) {
  +        FopImage.ImageInfo info = new FopImage.ImageInfo();
  +
           // png is always big endian
           int byte1 = header[16] & 0xff;
           int byte2 = header[17] & 0xff;
  @@ -50,29 +53,30 @@
           int byte4 = header[19] & 0xff;
           long l = (long)((byte1 << 24) | (byte2 << 16) |
                           (byte3 << 8) | byte4);
  -        this.width = (int)(l);
  +        info.width = (int)(l);
   
           byte1 = header[20] & 0xff;
           byte2 = header[21] & 0xff;
           byte3 = header[22] & 0xff;
           byte4 = header[23] & 0xff;
           l = (long)((byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4);
  -        this.height = (int)(l);
  -
  +        info.height = (int)(l);
  +        return info;
       }
   
  -    protected void setDefaultHeader() throws IOException {
  -        this.header = new byte[PNG_SIG_LENGTH];
  +    protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws 
IOException {
  +        byte[] header = new byte[PNG_SIG_LENGTH];
           try {
  -            this.imageStream.mark(PNG_SIG_LENGTH + 1);
  -            this.imageStream.read(header);
  -            this.imageStream.reset();
  +            imageStream.mark(PNG_SIG_LENGTH + 1);
  +            imageStream.read(header);
  +            imageStream.reset();
           } catch (IOException ex) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ex;
           }
  +        return header;
       }
   
   }
  
  
  
  1.20      +29 -30    xml-fop/src/org/apache/fop/image/analyser/SVGReader.java
  
  Index: SVGReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SVGReader.java    22 Feb 2002 09:18:47 -0000      1.19
  +++ SVGReader.java    25 Feb 2002 09:31:03 -0000      1.20
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGReader.java,v 1.19 2002/02/22 09:18:47 keiron Exp $
  + * $Id: SVGReader.java,v 1.20 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -46,52 +46,46 @@
   import java.awt.geom.Dimension2D;
   import java.awt.Dimension;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   import org.apache.fop.svg.SVGUserAgent;
   
   /**
    * ImageReader object for SVG document image type.
    */
  -public class SVGReader extends AbstractImageReader {
  +public class SVGReader implements ImageReader {
       public static final String SVG_MIME_TYPE = "image/svg+xml";
  -    FOUserAgent userAgent;
  -    Document doc;
       boolean batik = true;
   
       public SVGReader() {
       }
   
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        userAgent = ua;
  -        return loadImage(uri);
  +        return loadImage(uri, fis, ua);
       }
   
       public String getMimeType() {
           return SVG_MIME_TYPE;
       }
   
  -    public Document getDocument() {
  -        return doc;
  -    }
  -
       /**
        * This means the external svg document will be loaded twice.
        * Possibly need a slightly different design for the image stuff.
        */
  -    protected boolean loadImage(String uri) {
  +    protected FopImage.ImageInfo loadImage(String uri, BufferedInputStream fis,
  +                                   FOUserAgent ua) {
           if(batik) {
               try {
                   Loader loader = new Loader();
  -                return loader.getImage(uri);
  +                return loader.getImage(uri, fis, ua);
               } catch (NoClassDefFoundError e) {
                   batik = false;
  -                //userAgent.getLogger().error("Batik not in class path", e);
  -                return false;
  +                //ua.getLogger().error("Batik not in class path", e);
  +                return null;
               }
           }
  -        return false;
  +        return null;
       }
   
       /**
  @@ -100,21 +94,26 @@
        * the SVGReader class.
        */
       class Loader {
  -        private boolean getImage(String uri) {
  +        private FopImage.ImageInfo getImage(String uri, BufferedInputStream fis,
  +                                   FOUserAgent ua) {
               // parse document and get the size attributes of the svg element
   
               try {
  -                int length = imageStream.available();
  -                imageStream.mark(length);
  +                FopImage.ImageInfo info = new FopImage.ImageInfo();
  +                info.mimeType = getMimeType();
  +
  +                int length = fis.available();
  +                fis.mark(length);
                   SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
                                                     SVGImage.getParserName());
  -                doc = factory.createDocument(uri, imageStream);
  +                SVGDocument doc = factory.createDocument(uri, fis);
  +                info.data = doc;
   
                   Element e = ((SVGDocument) doc).getRootElement();
                   String s;
                   SVGUserAgent userAg =
                     new SVGUserAgent(new AffineTransform());
  -                userAg.setLogger(userAgent.getLogger());
  +                userAg.setLogger(ua.getLogger());
                   BridgeContext ctx = new BridgeContext(userAg);
                   UnitProcessor.Context uctx =
                     UnitProcessor.createContext(ctx, e);
  @@ -125,7 +124,7 @@
                   if (s.length() == 0) {
                       s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
                   }
  -                width = (int) UnitProcessor.svgHorizontalLengthToUserSpace (
  +                info.width = (int) UnitProcessor.svgHorizontalLengthToUserSpace (
                             s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
   
                   // 'height' attribute - default is 100%
  @@ -134,27 +133,27 @@
                   if (s.length() == 0) {
                       s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE;
                   }
  -                height = (int) UnitProcessor.svgVerticalLengthToUserSpace (
  +                info.height = (int) UnitProcessor.svgVerticalLengthToUserSpace (
                              s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
   
  -                return true;
  +                return info;
               } catch (NoClassDefFoundError ncdfe) {
                   batik = false;
  -                //userAgent.getLogger().error("Batik not in class path", ncdfe);
  -                return false;
  +                //ua.getLogger().error("Batik not in class path", ncdfe);
  +                return null;
               }
               catch (Exception e) {
                   // If the svg is invalid then it throws an IOException
                   // so there is no way of knowing if it is an svg document
   
  -                // userAgent.getLogger().error("Could not load external SVG: " +
  +                // ua.getLogger().error("Could not load external SVG: " +
                   //                       e.getMessage(), e);
                   // assuming any exception means this document is not svg
                   // or could not be loaded for some reason
                   try {
  -                    imageStream.reset();
  +                    fis.reset();
                   } catch (IOException ioe) { }
  -                return false;
  +                return null;
               }
           }
       }
  
  
  
  1.5       +20 -17    xml-fop/src/org/apache/fop/image/analyser/TIFFReader.java
  
  Index: TIFFReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/TIFFReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TIFFReader.java   21 Feb 2002 09:54:27 -0000      1.4
  +++ TIFFReader.java   25 Feb 2002 09:31:03 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: TIFFReader.java,v 1.4 2002/02/21 09:54:27 keiron Exp $
  + * $Id: TIFFReader.java,v 1.5 2002/02/25 09:31:03 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -11,6 +11,7 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  +import org.apache.fop.image.FopImage;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -18,14 +19,12 @@
    * @author Pankaj Narula, Michael Lee
    * @version 1.0
    */
  -public class TIFFReader extends AbstractImageReader {
  +public class TIFFReader implements ImageReader {
       static protected final int TIFF_SIG_LENGTH = 8;
  -    protected byte[] header;
   
  -    public boolean verifySignature(String uri, BufferedInputStream fis,
  +    public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  -        this.imageStream = fis;
  -        this.setDefaultHeader();
  +        byte[] header = getDefaultHeader(fis);
           boolean supported = false;
   
           if (header[0] == (byte) 0x49 && header[1] == (byte) 0x49)// first 2 bytes = 
II (little endian encoding)
  @@ -43,17 +42,19 @@
           }
   
           if (supported) {
  -            setDimension();
  -            return true;
  -        } else
  -            return false;
  +            FopImage.ImageInfo info = getDimension(header);
  +            info.mimeType = getMimeType();
  +            return info;
  +        } else {
  +            return null;
  +        }
       }
   
       public String getMimeType() {
           return "image/tiff";
       }
   
  -    protected void setDimension() {
  +    protected FopImage.ImageInfo getDimension(byte[] header) {
           // currently not setting the width and height
           // these are set again by the Jimi image reader.
           // I suppose I'll do it one day to be complete.  Or
  @@ -76,20 +77,22 @@
            * byte4 );
            * this.height = ( int ) ( l );
            */
  +         return null;
       }
   
  -    protected void setDefaultHeader() throws IOException {
  -        this.header = new byte[TIFF_SIG_LENGTH];
  +    protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws 
IOException {
  +        byte[] header = new byte[TIFF_SIG_LENGTH];
           try {
  -            this.imageStream.mark(TIFF_SIG_LENGTH + 1);
  -            this.imageStream.read(header);
  -            this.imageStream.reset();
  +            imageStream.mark(TIFF_SIG_LENGTH + 1);
  +            imageStream.read(header);
  +            imageStream.reset();
           } catch (IOException ex) {
               try {
  -                this.imageStream.reset();
  +                imageStream.reset();
               } catch (IOException exbis) {}
               throw ex;
           }
  +        return header;
       }
   
   }
  
  
  

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

Reply via email to