aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-12-13 20:41:28 +0000
committerJeremias Maerki <jeremias@apache.org>2005-12-13 20:41:28 +0000
commit6f265f63de6154d9225d92e0f496dfc362b2006c (patch)
treedb6625910179ba9e7cdc7d78a87b8d0ffeba7d07 /src/java/org
parentb45765ff3c9cc5deed81c299a203b221af0dbb6d (diff)
downloadxmlgraphics-fop-6f265f63de6154d9225d92e0f496dfc362b2006c.tar.gz
xmlgraphics-fop-6f265f63de6154d9225d92e0f496dfc362b2006c.zip
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
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/image/AbstractFopImage.java20
-rw-r--r--src/java/org/apache/fop/image/EmfImage.java12
-rw-r--r--src/java/org/apache/fop/image/GifImage.java5
-rw-r--r--src/java/org/apache/fop/image/JAIImage.java5
-rw-r--r--src/java/org/apache/fop/image/JimiImage.java5
-rw-r--r--src/java/org/apache/fop/image/PNGImage.java27
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java9
7 files changed, 69 insertions, 14 deletions
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;
@@ -205,6 +206,25 @@ public abstract class AbstractFopImage implements FopImage {
}
/**
+ * 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)
*/
public int getWidth() {
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 <fo:external-graphic> "
+ "does not support "
+ file.substring(file.lastIndexOf(".") + 1)