]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
* Reverted back the interface changes I made to ImageHandler.
authorAdrian Cumiskey <acumiskey@apache.org>
Tue, 25 Nov 2008 18:34:05 +0000 (18:34 +0000)
committerAdrian Cumiskey <acumiskey@apache.org>
Tue, 25 Nov 2008 18:34:05 +0000 (18:34 +0000)
* Created AbstractAFPImageHandlerRawStream base class to handle raw image streams for AFP.
* Fixed a bug in handling native embedded TIFF images.

I think its finally ready to roll now guys, sorry for the last minute glitches.

My apologies for not finding time to respond to the fop-dev mailing list this afternoon but have been trying to put my efforts into applying the final touches to the branch.  If my good lady allows I'll respond to your comments later this evening :).

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

24 files changed:
src/java/org/apache/fop/afp/AFPDataObjectFactory.java
src/java/org/apache/fop/afp/AFPDataObjectInfo.java
src/java/org/apache/fop/afp/AFPImageObjectInfo.java
src/java/org/apache/fop/afp/ioca/ImageContent.java
src/java/org/apache/fop/afp/ioca/ImageSegment.java
src/java/org/apache/fop/afp/modca/AbstractDataObject.java
src/java/org/apache/fop/afp/modca/ImageObject.java
src/java/org/apache/fop/afp/modca/ObjectContainer.java
src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java
src/java/org/apache/fop/render/ImageHandler.java
src/java/org/apache/fop/render/afp/AFPImageHandler.java
src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java
src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
src/java/org/apache/fop/render/afp/AFPImageHandlerXML.java
src/java/org/apache/fop/render/afp/AFPRenderer.java
src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java
src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java [new file with mode: 0644]
src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java
src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java
src/java/org/apache/fop/render/pdf/PDFImageHandlerXML.java

index aba181358a47c02b2d9c8717c5ccb93cb02c4379..80cb40713242062e6ca5e11948cfb824e120046c 100644 (file)
@@ -77,7 +77,7 @@ public class AFPDataObjectFactory {
                 ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT,
                 objectType, dataInContainer, containerHasOEG, dataInOCD);
 
-        objectContainer.setInputStream(dataObjectInfo.getInputStream());
+        objectContainer.setData(dataObjectInfo.getData());
         return objectContainer;
     }
 
@@ -117,6 +117,7 @@ public class AFPDataObjectFactory {
         } else {
             imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
         }
+
         imageObj.setData(imageObjectInfo.getData());
 
         return imageObj;
index c618a53fc12dd6817e999ae0db55a2c50418efa0..f6ff0046a9402b8acad141fd0545d100817671f1 100644 (file)
@@ -19,8 +19,6 @@
 
 package org.apache.fop.afp;
 
-import java.io.InputStream;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.afp.modca.Registry;
@@ -43,12 +41,18 @@ public class AFPDataObjectInfo {
     /** the data object height */
     private int dataHeight;
 
-    /** the object data in an inputstream */
-    private InputStream inputStream;
-
     /** the object registry mimetype */
     private String mimeType;
 
+    /** the object data in a byte array */
+    private byte[] data;
+
+    /** the object data height resolution */
+    private int dataHeightRes;
+
+    /** the object data width resolution */
+    private int dataWidthRes;
+
     /**
      * Default constructor
      */
@@ -121,16 +125,6 @@ public class AFPDataObjectInfo {
         return this.objectAreaInfo;
     }
 
-    /** {@inheritDoc} */
-    public String toString() {
-        return "AFPDataObjectInfo{"
-            + "mimeType=" + mimeType
-            + ", dataWidth=" + dataWidth
-            + ", dataHeight=" + dataHeight
-            + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "")
-            + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : "");
-    }
-
     /**
      * Returns the uri of this data object
      *
@@ -186,21 +180,68 @@ public class AFPDataObjectInfo {
     }
 
     /**
-     * Sets the object data inputstream
+     * Returns the data height resolution
+     *
+     * @return the data height resolution
+     */
+    public int getDataHeightRes() {
+        return this.dataHeightRes;
+    }
+
+    /**
+     * Sets the data width resolution
+     *
+     * @param dataWidthRes the data width resolution
+     */
+    public void setDataHeightRes(int dataHeightRes) {
+        this.dataHeightRes = dataHeightRes;
+    }
+
+    /**
+     * Returns the data width resolution
+     *
+     * @return the data width resolution
+     */
+    public int getDataWidthRes() {
+        return this.dataWidthRes;
+    }
+
+    /**
+     * Sets the data width resolution
+     *
+     * @param dataWidthRes the data width resolution
+     */
+    public void setDataWidthRes(int dataWidthRes) {
+        this.dataWidthRes = dataWidthRes;
+    }
+
+    /**
+     * Sets the object data
      *
-     * @param inputStream the object data inputstream
+     * @param data the object data
      */
-    public void setInputStream(InputStream inputStream) {
-        this.inputStream = inputStream;
+    public void setData(byte[] data) {
+        this.data = data;
     }
 
     /**
-     * Returns the object data inputstream
+     * Returns the object data
      *
-     * @return the object data inputstream
+     * @return the object data
      */
-    public InputStream getInputStream() {
-        return this.inputStream;
+    public byte[] getData() {
+        return this.data;
     }
 
+    /** {@inheritDoc} */
+    public String toString() {
+        return "AFPDataObjectInfo{"
+            + "mimeType=" + mimeType
+            + ", dataWidth=" + dataWidth
+            + ", dataHeight=" + dataHeight
+            + ", dataWidthRes=" + dataWidthRes
+            + ", dataHeightRes=" + dataHeightRes
+            + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "")
+            + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : "");
+    }
 }
index 561ad438b75ede476fcac29896edf35280eb4972..f3677534f494a8921ae542882b60fb872569024b 100644 (file)
@@ -24,6 +24,7 @@ package org.apache.fop.afp;
  * A list of parameters associated with an image
  */
 public class AFPImageObjectInfo extends AFPDataObjectInfo {
+
     /** number of bits per pixel used */
     private int bitsPerPixel;
 
@@ -33,9 +34,6 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo {
     /** compression type if any */
     private int compression = -1;
 
-    /** the object data in a byte array */
-    private byte[] data;
-
     /**
      * Default constructor
      */
@@ -106,24 +104,6 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo {
         this.compression = compression;
     }
 
-    /**
-     * Sets the object data
-     *
-     * @param data the object data
-     */
-    public void setData(byte[] data) {
-        this.data = data;
-    }
-
-    /**
-     * Returns the object data
-     *
-     * @return the object data
-     */
-    public byte[] getData() {
-        return this.data;
-    }
-
     /** {@inheritDoc} */
     public String toString() {
         return "AFPImageObjectInfo{" + super.toString()
@@ -132,5 +112,4 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo {
             + ", bitsPerPixel=" + bitsPerPixel
             + "}";
     }
-
 }
\ No newline at end of file
index 028d08475ebfcfd22355510fe59bdd3c0d1ef62a..40e51578b3d944495d51d231bb0c4fedbe1c2a10 100644 (file)
@@ -123,7 +123,7 @@ public class ImageContent extends AbstractStructuredObject {
     }
 
     /**
-     * Set the data image store information.
+     * Set the image data (can be byte array or inputstream)
      *
      * @param imageData the image data
      */
@@ -148,15 +148,16 @@ public class ImageContent extends AbstractStructuredObject {
 
         os.write(getExternalAlgorithmParameter());
 
-        // Image Data
-        if (data != null) {
-            final byte[] dataHeader = new byte[] {
+        final byte[] dataHeader = new byte[] {
                 (byte)0xFE, // ID
                 (byte)0x92, // ID
                 0x00, // length
                 0x00  // length
             };
-            final int lengthOffset = 2;
+        final int lengthOffset = 2;
+
+        // Image Data
+        if (data != null) {
             writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os);
         }
     }
index eab8b931a7157fd5db06107fc51c7fc8149375c2..9fb5447197786550a184e1f3781c6d524ed2b6e6 100644 (file)
@@ -118,8 +118,8 @@ public class ImageSegment extends AbstractNamedAFPObject {
      *
      * @param data the image data
      */
-    public void setData(byte[] data) {
-        getImageContent().setImageData(data);
+    public void setData(byte[] imageData) {
+        getImageContent().setImageData(imageData);
     }
 
     /** {@inheritDoc} */
index ec1b45be68650276ed92c376b0d5d4ee14e03f8e..4a13b4a55118dea300a218ad45ca4b8927c78dbc 100644 (file)
@@ -112,6 +112,7 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject implemen
 
     /** {@inheritDoc} */
     protected void writeContent(OutputStream os) throws IOException {
+        writeTriplets(os);
         if (objectEnvironmentGroup != null) {
             objectEnvironmentGroup.writeToStream(os);
         }
index 8ab56691f0006773763f5ba08ac2f27d90ebeb06..24ac0cb22b47b391219b7737c3458dabc47cb01a 100644 (file)
@@ -25,7 +25,6 @@ import java.io.OutputStream;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPImageObjectInfo;
-import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.Factory;
 import org.apache.fop.afp.ioca.ImageSegment;
 
@@ -65,15 +64,17 @@ public class ImageObject extends AbstractDataObject {
         int dataWidth = imageObjectInfo.getDataWidth();
         int dataHeight = imageObjectInfo.getDataHeight();
 
-        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
-        int widthRes = objectAreaInfo.getWidthRes();
-        int heightRes = objectAreaInfo.getHeightRes();
+//        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
+//        int widthRes = objectAreaInfo.getWidthRes();
+//        int heightRes = objectAreaInfo.getHeightRes();
 
+        int dataWidthRes = imageObjectInfo.getDataWidthRes();
+        int dataHeightRes = imageObjectInfo.getDataWidthRes();
         ImageDataDescriptor imageDataDescriptor
-            = factory.createImageDataDescriptor(dataWidth, dataHeight, widthRes, heightRes);
+            = factory.createImageDataDescriptor(dataWidth, dataHeight, dataWidthRes, dataHeightRes);
         getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor);
 
-        getImageSegment().setImageSize(dataWidth, dataHeight, widthRes, heightRes);
+        getImageSegment().setImageSize(dataWidth, dataHeight, dataWidthRes, dataHeightRes);
     }
 
     /**
@@ -117,8 +118,8 @@ public class ImageObject extends AbstractDataObject {
      *
      * @param data the image data
      */
-    public void setData(byte[] data) {
-        getImageSegment().setData(data);
+    public void setData(byte[] imageData) {
+        getImageSegment().setData(imageData);
     }
 
     /** {@inheritDoc} */
index 791f4da1b7189d39dad3b1fe084a90b00720e3ac..39b935d01169edb54e717b2bb44575c0c0b55147 100644 (file)
 package org.apache.fop.afp.modca;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.AFPResourceInfo;
@@ -40,7 +38,7 @@ public class ObjectContainer extends AbstractDataObject {
     /** the object container data maximum length */
     private static final int MAX_DATA_LEN = 32759;
 
-    private InputStream inputStream;
+    private byte[] data;
 
     /**
      * Main constructor
@@ -75,8 +73,9 @@ public class ObjectContainer extends AbstractDataObject {
         copySF(dataHeader, SF_CLASS, Type.DATA, Category.OBJECT_CONTAINER);
         final int lengthOffset = 1;
 
-        copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os);
-        IOUtils.closeQuietly(inputStream);
+        if (data != null) {
+            writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os);
+        }
     }
 
     /** {@inheritDoc} */
@@ -118,7 +117,7 @@ public class ObjectContainer extends AbstractDataObject {
      *
      * @param inputStream the inputstream for the object container data
      */
-    public void setInputStream(InputStream inputStream) {
-        this.inputStream = inputStream;
+    public void setData(byte[] data) {
+        this.data = data;
     }
 }
index e305e0a551e29c7b7caf11d9f379bd15b8a8cda2..e8001f2fa0f1e42faa05d1bd7598222e4c4ebd04 100644 (file)
@@ -100,10 +100,7 @@ public abstract class AbstractImageHandlerRegistry {
      * @param handler the ImageHandler instance
      */
     public synchronized void addHandler(ImageHandler handler) {
-        Class[] imageClasses = handler.getSupportedImageClasses();
-        for (int i = 0; i < imageClasses.length; i++) {
-            this.handlers.put(imageClasses[i], handler);
-        }
+        this.handlers.put(handler.getSupportedImageClass(), handler);
 
         //Sorted insert
         ListIterator iter = this.handlerList.listIterator();
index 05d1e2e79b43666f2da25f28e3aa845436088477..6a44c01a9a33e44f87ed2d80122c03fd71870189 100644 (file)
 
 package org.apache.fop.render;
 
-import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 
 public interface ImageHandler {
 
     /**
      * Returns the priority for this image handler. A lower value means higher priority. This
-     * information is used to build the ordered/prioritized list of supported ImageFlavors for
-     * the PDF renderer. The built-in handlers use priorities between 100 and 999.
+     * information is used to build the ordered/prioritized list of supported ImageFlavors.
+     * The built-in handlers use priorities between 100 and 999.
      * @return a positive integer (>0) indicating the priority
      */
     int getPriority();
@@ -39,8 +38,8 @@ public interface ImageHandler {
     ImageFlavor[] getSupportedImageFlavors();
 
     /**
-     * Returns the {@link Image} subclasses supported by this instance.
-     * @return the Image types
+     * Returns the {@link Class} subclass supported by this instance.
+     * @return the image Class type
      */
-    Class[] getSupportedImageClasses();
+    Class getSupportedImageClass();
 }
index 8e925d460c29b40c523ebb245dc21d41eb88b0a4..3ec3ea0b11153942a6afd72ba2a513179a546fd6 100644 (file)
@@ -31,6 +31,9 @@ import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPUnitConverter;
 import org.apache.fop.render.ImageHandler;
 
+/**
+ * A base abstract AFP image handler
+ */
 public abstract class AFPImageHandler implements ImageHandler {
     private static final int X = 0;
     private static final int Y = 1;
index fa3f00cdb969781e2dcfcdb479b8c5479385d357..0780e8a59cbf5a474b048e7f486b05a5012fc316 100644 (file)
@@ -41,10 +41,6 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler {
         ImageFlavor.GRAPHICS2D
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageGraphics2D.class
-    };
-
     /** {@inheritDoc} */
     public AFPDataObjectInfo generateDataObjectInfo(
             AFPRendererImageInfo rendererImageInfo) throws IOException {
@@ -98,8 +94,8 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageGraphics2D.class;
     }
 
     /** {@inheritDoc} */
index aa91bb6608e414733c306d0fbcfd10bc5010a01b..3ac1d569641a53ca24aa9dc78411cd85e0076f9b 100644 (file)
@@ -23,24 +23,18 @@ import java.io.IOException;
 
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPImageObjectInfo;
-import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
 
 /**
- * PDFImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
+ * AFPImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
  */
-public class AFPImageHandlerRawCCITTFax extends AFPImageHandler {
+public class AFPImageHandlerRawCCITTFax extends AbstractAFPImageHandlerRawStream {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RAW_CCITTFAX,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageRawCCITTFax.class,
-    };
-
     /** {@inheritDoc} */
     public AFPDataObjectInfo generateDataObjectInfo(
             AFPRendererImageInfo rendererImageInfo) throws IOException {
@@ -48,18 +42,10 @@ public class AFPImageHandlerRawCCITTFax extends AFPImageHandler {
             = (AFPImageObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
 
         ImageRawCCITTFax ccitt = (ImageRawCCITTFax) rendererImageInfo.getImage();
-        imageObjectInfo.setCompression(ccitt.getCompression());
-
-        AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
-        ImageSize imageSize = ccitt.getSize();
-        int widthRes = (int) (imageSize.getDpiHorizontal() * 10);
-        objectAreaInfo.setWidthRes(widthRes);
-
-        int heightRes = (int) (imageSize.getDpiVertical() * 10);
-        objectAreaInfo.setHeightRes(heightRes);
-
-        imageObjectInfo.setInputStream(ccitt.createInputStream());
+        int compression = ccitt.getCompression();
+        imageObjectInfo.setCompression(compression);
 
+        imageObjectInfo.setBitsPerPixel(1);
         return imageObjectInfo;
     }
 
@@ -74,8 +60,8 @@ public class AFPImageHandlerRawCCITTFax extends AFPImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRawCCITTFax.class;
     }
 
     /** {@inheritDoc} */
index 47344b200b8d27cd273cfb79085ee3032e1a9934..ded9ec9d53ca9c1535afec4d78822759d3d8e66a 100644 (file)
 
 package org.apache.fop.render.afp;
 
-import java.io.IOException;
-import java.io.InputStream;
-
 import org.apache.fop.afp.AFPDataObjectInfo;
-import org.apache.fop.afp.AFPObjectAreaInfo;
-import org.apache.fop.afp.AFPPaintingState;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
 
 /**
  * AFPImageHandler implementation which handles raw stream images.
  */
-public class AFPImageHandlerRawStream extends AFPImageHandler {
+public class AFPImageHandlerRawStream extends AbstractAFPImageHandlerRawStream {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RAW_JPEG,
-        ImageFlavor.RAW_CCITTFAX,
         ImageFlavor.RAW_EPS,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageRawJPEG.class,
-        ImageRawCCITTFax.class,
-        ImageRawEPS.class
-    };
-
-    /** {@inheritDoc} */
-    public AFPDataObjectInfo generateDataObjectInfo(
-            AFPRendererImageInfo rendererImageInfo) throws IOException {
-        AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo);
-        ImageInfo imageInfo = rendererImageInfo.getImageInfo();
-        String mimeType = imageInfo.getMimeType();
-        if (mimeType != null) {
-            dataObjectInfo.setMimeType(mimeType);
-        }
-        ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
-
-        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
-
-        AFPRendererContext rendererContext
-        = (AFPRendererContext)rendererImageInfo.getRendererContext();
-        AFPInfo afpInfo = rendererContext.getInfo();
-        AFPPaintingState paintingState = afpInfo.getPaintingState();
-        int resolution = paintingState.getResolution();
-        objectAreaInfo.setWidthRes(resolution);
-        objectAreaInfo.setHeightRes(resolution);
-
-        InputStream inputStream = rawStream.createInputStream();
-        dataObjectInfo.setInputStream(inputStream);
-
-        int dataHeight = rawStream.getSize().getHeightPx();
-        dataObjectInfo.setDataHeight(dataHeight);
-
-        int dataWidth = rawStream.getSize().getWidthPx();
-        dataObjectInfo.setDataWidth(dataWidth);
-        return dataObjectInfo;
-    }
-
     /** {@inheritDoc} */
     public int getPriority() {
-        return 100;
+        return 200;
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRawStream.class;
     }
 
     /** {@inheritDoc} */
index ef6a6bb651ce02aa539e1e74b00e1d33bfaa0172..28c942a0843b3d222ff721722158e6120ba39970 100644 (file)
@@ -28,7 +28,6 @@ import org.apache.fop.afp.AFPImageObjectInfo;
 import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.impl.ImageBuffered;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
 import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 import org.apache.xmlgraphics.util.MimeConstants;
@@ -43,27 +42,21 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler {
         ImageFlavor.RENDERED_IMAGE
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageBuffered.class,
-        ImageRendered.class
-    };
-
     /** {@inheritDoc} */
     public AFPDataObjectInfo generateDataObjectInfo(
             AFPRendererImageInfo rendererImageInfo) throws IOException {
         AFPImageObjectInfo imageObjectInfo
             = (AFPImageObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
 
-        imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
-
-        AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
         AFPRendererContext rendererContext
             = (AFPRendererContext)rendererImageInfo.getRendererContext();
         AFPInfo afpInfo = rendererContext.getInfo();
         AFPPaintingState paintingState = afpInfo.getPaintingState();
         int resolution = paintingState.getResolution();
-        objectAreaInfo.setWidthRes(resolution);
-        objectAreaInfo.setHeightRes(resolution);
+
+        imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
+        imageObjectInfo.setDataHeightRes(resolution);
+        imageObjectInfo.setDataWidthRes(resolution);
 
         ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img;
         RenderedImage renderedImage = imageRendered.getRenderedImage();
@@ -92,6 +85,11 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler {
         }
         imageObjectInfo.setData(imageData);
 
+        // set object area info
+        AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
+        objectAreaInfo.setWidthRes(resolution);
+        objectAreaInfo.setHeightRes(resolution);
+
         return imageObjectInfo;
     }
 
@@ -106,8 +104,8 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRendered.class;
     }
 
     /** {@inheritDoc} */
index b7345811a2555c3b595911fd90629af692c36164..7ea1a7a109275ad62b81b7700784c3a03ac38f3b 100644 (file)
@@ -39,10 +39,6 @@ public class AFPImageHandlerXML extends AFPImageHandler {
         ImageFlavor.XML_DOM,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageXMLDOM.class,
-    };
-
     /** {@inheritDoc} */
     public AFPDataObjectInfo generateDataObjectInfo(AFPRendererImageInfo rendererImageInfo)
             throws IOException {
@@ -64,8 +60,8 @@ public class AFPImageHandlerXML extends AFPImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageXMLDOM.class;
     }
 
     /** {@inheritDoc} */
index 903099610140aa952fb6eec530991165029a5ad1..b73b036c33be08ba1a2f608f983f591f58430403 100644 (file)
@@ -71,7 +71,6 @@ import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.afp.extensions.AFPElementMapping;
 import org.apache.fop.render.afp.extensions.AFPPageSetup;
-import org.apache.fop.util.AbstractPaintingState;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -742,15 +741,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
         return paintingState.getResolution();
     }
 
-    /**
-     * Returns the current AFP state
-     *
-     * @return the current AFP state
-     */
-    public AbstractPaintingState getState() {
-        return this.paintingState;
-    }
-
     /**
      * Sets the default resource group file path
      * @param filePath the default resource group file path
index 0aa3eb6abe457b8bdc4976c18435eccf5370683e..2687d9071a0b4f4d6a279945046d57e050cac2df 100644 (file)
@@ -146,4 +146,17 @@ public class AFPRendererImageInfo {
         return this.pos;
     }
 
+    /** {@inheritDoc} */
+    public String toString() {
+        return "AFPRendererImageInfo{\n"
+            + "\turi=" + uri + ",\n"
+            + "\tinfo=" + info + ",\n"
+            + "\tpos=" + pos + ",\n"
+            + "\torigin=" + origin + ",\n"
+            + "\timg=" + img + ",\n"
+            + "\tforeignAttributes=" + foreignAttributes + ",\n"
+            + "\trendererContext=" + rendererContext + "\n"
+        + "}";
+
+    }
 }
diff --git a/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java b/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java
new file mode 100644 (file)
index 0000000..ae8ac99
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.fop.afp.AFPObjectAreaInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+
+/**
+ * A base abstract AFP raw stream image handler
+ */
+public abstract class AbstractAFPImageHandlerRawStream extends AFPImageHandler {
+
+    /** {@inheritDoc} */
+    public AFPDataObjectInfo generateDataObjectInfo(
+            AFPRendererImageInfo rendererImageInfo) throws IOException {
+        AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo);
+
+        ImageInfo imageInfo = rendererImageInfo.getImageInfo();
+        String mimeType = imageInfo.getMimeType();
+        if (mimeType != null) {
+            dataObjectInfo.setMimeType(mimeType);
+        }
+        ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
+        InputStream inputStream = rawStream.createInputStream();
+        try {
+            dataObjectInfo.setData(IOUtils.toByteArray(inputStream));
+        } finally {
+            IOUtils.closeQuietly(inputStream);
+        }
+
+        int dataHeight = rawStream.getSize().getHeightPx();
+        dataObjectInfo.setDataHeight(dataHeight);
+
+        int dataWidth = rawStream.getSize().getWidthPx();
+        dataObjectInfo.setDataWidth(dataWidth);
+
+        ImageSize imageSize = rawStream.getSize();
+        dataObjectInfo.setDataHeightRes((int) (imageSize.getDpiHorizontal() * 10));
+        dataObjectInfo.setDataWidthRes((int) (imageSize.getDpiVertical() * 10));
+
+        // set object area info
+        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
+        AFPRendererContext rendererContext
+            = (AFPRendererContext)rendererImageInfo.getRendererContext();
+        AFPInfo afpInfo = rendererContext.getInfo();
+        AFPPaintingState paintingState = afpInfo.getPaintingState();
+        int resolution = paintingState.getResolution();
+        objectAreaInfo.setWidthRes(resolution);
+        objectAreaInfo.setHeightRes(resolution);
+
+        return dataObjectInfo;
+    }
+
+}
index 9f44e58b5331e303ac2277e87c85543d3dc4ab37..3e4a9b3541c766bde1dd51043cc6f8355f86b855 100644 (file)
@@ -38,10 +38,6 @@ public class PDFImageHandlerGraphics2D implements PDFImageHandler {
         ImageFlavor.GRAPHICS2D,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageGraphics2D.class,
-    };
-
     /** {@inheritDoc} */
     public PDFXObject generateImage(RendererContext context, Image image,
             Point origin, Rectangle pos)
@@ -59,8 +55,8 @@ public class PDFImageHandlerGraphics2D implements PDFImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageGraphics2D.class;
     }
 
     /** {@inheritDoc} */
index 158e93c86116f04786ae9f3073682428e0213adf..1ba498ff0a9770c404f1f4a8c31c666246f70821 100644 (file)
@@ -41,10 +41,6 @@ public class PDFImageHandlerRawCCITTFax implements PDFImageHandler {
         ImageFlavor.RAW_CCITTFAX,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageRawCCITTFax.class,
-    };
-
     /** {@inheritDoc} */
     public PDFXObject generateImage(RendererContext context, Image image,
             Point origin, Rectangle pos)
@@ -74,8 +70,8 @@ public class PDFImageHandlerRawCCITTFax implements PDFImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRawCCITTFax.class;
     }
 
     /** {@inheritDoc} */
index 1432547da4111bb97cb0f4e3ba22a72a3dabaae2..41a2d7565ee8db118e8c94a9aaf70150ac2f0431 100644 (file)
@@ -41,10 +41,6 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler {
         ImageFlavor.RAW_JPEG,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageRawJPEG.class,
-    };
-
     /** {@inheritDoc} */
     public PDFXObject generateImage(RendererContext context, Image image,
             Point origin, Rectangle pos)
@@ -74,8 +70,8 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRawJPEG.class;
     }
 
     /** {@inheritDoc} */
index edbe9005dfd244e22217bb63d19ac19090cfac2a..268ff8862a943045fb9d6555d8954cb9e2ee8a12 100644 (file)
@@ -42,11 +42,6 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler {
         ImageFlavor.RENDERED_IMAGE
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageRendered.class,
-    };
-
-
     /** {@inheritDoc} */
     public PDFXObject generateImage(RendererContext context, Image image,
             Point origin, Rectangle pos)
@@ -76,8 +71,8 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageRendered.class;
     }
 
     /** {@inheritDoc} */
index 069fef172f1fcca20023cb078fda036ad125812a..26ba8337161916e8b3a5fdd90ee04354ecda5b93 100644 (file)
@@ -40,10 +40,6 @@ public class PDFImageHandlerXML implements PDFImageHandler {
         ImageFlavor.XML_DOM,
     };
 
-    private static final Class[] CLASSES = new Class[] {
-        ImageXMLDOM.class,
-    };
-
     /** {@inheritDoc} */
     public PDFXObject generateImage(RendererContext context, Image image,
             Point origin, Rectangle pos)
@@ -64,8 +60,8 @@ public class PDFImageHandlerXML implements PDFImageHandler {
     }
 
     /** {@inheritDoc} */
-    public Class[] getSupportedImageClasses() {
-        return CLASSES;
+    public Class getSupportedImageClass() {
+        return ImageXMLDOM.class;
     }
 
     /** {@inheritDoc} */