diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/java-1.4/org/apache/fop/image/ImageIOImage.java | 11 | ||||
-rw-r--r-- | src/java/org/apache/fop/image/AbstractFopImage.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/rtf/RTFHandler.java | 50 |
3 files changed, 57 insertions, 7 deletions
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 1af4f0b9a..7ec6b9004 100644 --- a/src/java-1.4/org/apache/fop/image/ImageIOImage.java +++ b/src/java-1.4/org/apache/fop/image/ImageIOImage.java @@ -64,10 +64,7 @@ public class ImageIOImage extends AbstractFopImage { * @see org.apache.fop.image.AbstractFopImage#loadDimensions() */ protected boolean loadDimensions() { - if ((this.width > 0) && (this.height > 0)) { - return true; - } - else if (this.bitmaps == null) { + if (this.bitmaps == null) { return loadBitmap(); } return true; @@ -211,7 +208,11 @@ public class ImageIOImage extends AbstractFopImage { /** @see org.apache.fop.image.AbstractFopImage#loadOriginalData() */ protected boolean loadOriginalData() { - return loadDefaultOriginalData(); + if (inputStream == null && getBitmaps() != null) { + return false; + } else { + return loadDefaultOriginalData(); + } } /** @see org.apache.fop.image.FopImage#hasSoftMask() */ diff --git a/src/java/org/apache/fop/image/AbstractFopImage.java b/src/java/org/apache/fop/image/AbstractFopImage.java index 8c150df41..4d49034a7 100644 --- a/src/java/org/apache/fop/image/AbstractFopImage.java +++ b/src/java/org/apache/fop/image/AbstractFopImage.java @@ -219,6 +219,9 @@ public abstract class AbstractFopImage implements FopImage { * @return true if the loading was successful */ protected boolean loadDefaultOriginalData() { + if (inputStream == null) { + throw new IllegalStateException("inputStream is already null or was never set"); + } try { this.raw = IOUtils.toByteArray(inputStream); } catch (java.io.IOException ex) { diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index d17e3285c..ac0363cb2 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -20,13 +20,24 @@ package org.apache.fop.render.rtf; // Java +import java.awt.color.ColorSpace; import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; +import java.awt.image.DataBufferByte; +import java.awt.image.PixelInterleavedSampleModel; +import java.awt.image.Raster; +import java.awt.image.SampleModel; +import java.awt.image.WritableRaster; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Iterator; import org.apache.batik.dom.svg.SVGDOMImplementation; +import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOPException; @@ -97,6 +108,8 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem.RtfListItemLabel; import org.apache.fop.render.rtf.rtflib.tools.BuilderContext; import org.apache.fop.render.rtf.rtflib.tools.TableContext; +import org.apache.xmlgraphics.image.writer.ImageWriter; +import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -1128,7 +1141,12 @@ public class RTFHandler extends FOEventHandler { log.error("Image could not be found: " + url); return; } - fopimage.load(FopImage.ORIGINAL_DATA); + if ("image/gif".equals(fopimage.getMimeType())) { + //GIF is not directly supported by RTF, so it must be converted to PNG + fopimage.load(FopImage.BITMAP); + } else { + fopimage.load(FopImage.ORIGINAL_DATA); + } putGraphic(eg, fopimage); } catch (Exception e) { @@ -1184,6 +1202,26 @@ public class RTFHandler extends FOEventHandler { } } + private BufferedImage createBufferedImageFromBitmaps(FopImage image) { + // TODO Hardcoded color and sample models, FIX ME! + ColorModel cm = new ComponentColorModel( + ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[] {8, 8, 8}, + false, false, + ColorModel.OPAQUE, DataBuffer.TYPE_BYTE); + SampleModel sampleModel = new PixelInterleavedSampleModel( + DataBuffer.TYPE_BYTE, image.getWidth(), image.getHeight(), 3, image.getWidth() * 3, + new int[] {0, 1, 2}); + DataBuffer dbuf = new DataBufferByte(image.getBitmaps(), + image.getWidth() * image.getHeight() * 3); + + WritableRaster raster = Raster.createWritableRaster(sampleModel, + dbuf, null); + + // Combine the color model and raster into a buffered image + return new BufferedImage(cm, raster, false, null); + } + /** * Puts a graphic/image into the generated RTF file. * @param abstractGraphic the graphic (external-graphic or instream-foreign-object) @@ -1195,8 +1233,16 @@ public class RTFHandler extends FOEventHandler { byte[] rawData; if ("image/svg+xml".equals(fopImage.getMimeType())) { rawData = SVGConverter.convertToJPEG((XMLImage) fopImage); - } else { + } else if (fopImage.getRessourceBytes() != null) { rawData = fopImage.getRessourceBytes(); + } else { + //TODO Revisit after the image library redesign!!! + //Convert the decoded bitmaps to a BufferedImage + BufferedImage bufImage = createBufferedImageFromBitmaps(fopImage); + ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor("image/png"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + writer.writeImage(bufImage, baout); + rawData = baout.toByteArray(); } if (rawData == null) { log.warn(FONode.decorateWithContextInfo("Image could not be embedded: " |