From: Jeremias Maerki Date: Tue, 13 Dec 2005 20:41:28 +0000 (+0000) Subject: Restored PNG support for RTF output and fixed two bugs related to image handling... X-Git-Tag: fop-0_91-beta~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6f265f63de6154d9225d92e0f496dfc362b2006c;p=xmlgraphics-fop.git Restored PNG support for RTF output and fixed two bugs related to image handling (an NPE and an invalid "==" comparison on Strings). Added a default implementation for loading the raw image. Used by most FopImage implementations. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@356612 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java-1.4/org/apache/fop/image/ImageIOImage.java b/src/java-1.4/org/apache/fop/image/ImageIOImage.java index 111011918..3dddc05ad 100644 --- a/src/java-1.4/org/apache/fop/image/ImageIOImage.java +++ b/src/java-1.4/org/apache/fop/image/ImageIOImage.java @@ -153,5 +153,10 @@ public class ImageIOImage extends AbstractFopImage { return true; } + /** @see org.apache.fop.image.AbstractFopImage#loadOriginalData() */ + protected boolean loadOriginalData() { + return loadDefaultOriginalData(); + } + } diff --git a/src/java/org/apache/fop/image/AbstractFopImage.java b/src/java/org/apache/fop/image/AbstractFopImage.java index 461b474ea..e8189c95c 100644 --- a/src/java/org/apache/fop/image/AbstractFopImage.java +++ b/src/java/org/apache/fop/image/AbstractFopImage.java @@ -24,6 +24,7 @@ import java.awt.color.ICC_Profile; import java.io.InputStream; import java.awt.Color; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -204,6 +205,25 @@ public abstract class AbstractFopImage implements FopImage { return false; } + /** + * Load the original image data. This is generic code for use by any + * subclass that wants to use this from a loadOriginalData() implementation. + * + * @return true if the loading was successful + */ + protected boolean loadDefaultOriginalData() { + try { + this.raw = IOUtils.toByteArray(inputStream); + } catch (java.io.IOException ex) { + log.error("Error while loading image (EMF): " + ex.getMessage(), ex); + return false; + } finally { + IOUtils.closeQuietly(inputStream); + inputStream = null; + } + return true; + } + /** * @return the image width (in pixels) */ diff --git a/src/java/org/apache/fop/image/EmfImage.java b/src/java/org/apache/fop/image/EmfImage.java index 0954e97d7..23c393749 100644 --- a/src/java/org/apache/fop/image/EmfImage.java +++ b/src/java/org/apache/fop/image/EmfImage.java @@ -47,17 +47,7 @@ public class EmfImage extends AbstractFopImage { * @return true if loaded false for any error */ protected boolean loadOriginalData() { - try { - this.raw = IOUtils.toByteArray(inputStream); - } catch (java.io.IOException ex) { - log.error("Error while loading image (EMF): " + ex.getMessage(), ex); - return false; - } finally { - IOUtils.closeQuietly(inputStream); - inputStream = null; - } - - return true; + return loadDefaultOriginalData(); } } diff --git a/src/java/org/apache/fop/image/GifImage.java b/src/java/org/apache/fop/image/GifImage.java index 10a3d6328..c00689f23 100644 --- a/src/java/org/apache/fop/image/GifImage.java +++ b/src/java/org/apache/fop/image/GifImage.java @@ -165,6 +165,11 @@ public class GifImage extends AbstractFopImage { return true; } + /** @see org.apache.fop.image.AbstractFopImage#loadOriginalData() */ + protected boolean loadOriginalData() { + return loadDefaultOriginalData(); + } + /** * A dummy url connection for a gif image in an input stream. */ diff --git a/src/java/org/apache/fop/image/JAIImage.java b/src/java/org/apache/fop/image/JAIImage.java index 5e71f9902..a7eac59f8 100644 --- a/src/java/org/apache/fop/image/JAIImage.java +++ b/src/java/org/apache/fop/image/JAIImage.java @@ -177,5 +177,10 @@ public class JAIImage extends AbstractFopImage { } } + /** @see org.apache.fop.image.AbstractFopImage#loadOriginalData() */ + protected boolean loadOriginalData() { + return loadDefaultOriginalData(); + } + } diff --git a/src/java/org/apache/fop/image/JimiImage.java b/src/java/org/apache/fop/image/JimiImage.java index 35db0bbc1..2d11440e1 100644 --- a/src/java/org/apache/fop/image/JimiImage.java +++ b/src/java/org/apache/fop/image/JimiImage.java @@ -176,5 +176,10 @@ public class JimiImage extends AbstractFopImage { } } + /** @see org.apache.fop.image.AbstractFopImage#loadOriginalData() */ + protected boolean loadOriginalData() { + return loadDefaultOriginalData(); + } + } diff --git a/src/java/org/apache/fop/image/PNGImage.java b/src/java/org/apache/fop/image/PNGImage.java index 6235b9720..6cf50d47c 100644 --- a/src/java/org/apache/fop/image/PNGImage.java +++ b/src/java/org/apache/fop/image/PNGImage.java @@ -18,12 +18,17 @@ package org.apache.fop.image; +import java.awt.color.ColorSpace; +import java.awt.color.ICC_Profile; +import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.batik.ext.awt.image.codec.PNGRed; import org.apache.batik.ext.awt.image.codec.PNGDecodeParam; import org.apache.batik.ext.awt.image.codec.SeekableStream; import org.apache.batik.ext.awt.image.rendered.CachableRed; +import org.apache.commons.io.IOUtils; +import org.apache.fop.util.CMYKColorSpace; /** * FopImage object using PNG @@ -60,4 +65,26 @@ public class PNGImage extends BatikImage { return red; } + /** + * Load the original PNG data. + * This loads the original PNG data as is into memory. + * + * @return true if loaded false for any error + */ + protected boolean loadOriginalData() { + try { + seekableInput.seek(0); + this.raw = IOUtils.toByteArray(seekableInput); + + } catch (java.io.IOException ex) { + log.error("Error while loading raw image: " + ex.getMessage(), ex); + return false; + } finally { + IOUtils.closeQuietly(inputStream); + inputStream = null; + } + + return true; + } + } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java index ad1ee1885..db97d1943 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java @@ -382,10 +382,13 @@ public class RtfExternalGraphic extends RtfElement { // Determine image file format String file = url.getFile (); imageformat = FormatBase.determineFormat(imagedata); - imageformat = imageformat.convert(imageformat, imagedata); + if (imageformat != null) { + imageformat = imageformat.convert(imageformat, imagedata); + } - if (imageformat.getType() == ImageConstants.I_NOT_SUPPORTED - | imageformat.getRtfTag() == "") { + if (imageformat == null + || imageformat.getType() == ImageConstants.I_NOT_SUPPORTED + || "".equals(imageformat.getRtfTag())) { throw new ExternalGraphicException("The tag " + "does not support " + file.substring(file.lastIndexOf(".") + 1)