Quellcode durchsuchen

Bugzilla #41488:

Fix for NPE with PNG images for RTF output.
Support for GIF images in RTF output (RTF handler, only. Does not affect the RTF library.).

Reverts revision 503326 and fixes the problem in a different way. But the fix is only a work-around and will need to be revisited when redesigning the image package. At any rate, the resolution problem introduced with the previous patch can been avoided with the new approach.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@504511 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_94
Jeremias Maerki vor 17 Jahren
Ursprung
Commit
42c14d6c02

+ 6
- 5
src/java-1.4/org/apache/fop/image/ImageIOImage.java Datei anzeigen

@@ -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() */

+ 3
- 0
src/java/org/apache/fop/image/AbstractFopImage.java Datei anzeigen

@@ -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) {

+ 48
- 2
src/java/org/apache/fop/render/rtf/RTFHandler.java Datei anzeigen

@@ -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: "

+ 6
- 3
status.xml Datei anzeigen

@@ -28,12 +28,15 @@

<changes>
<release version="FOP Trunk">
<action context="Code" dev="AD" type="fix">
Fix for properly parsing font-family names containing spaces.
<action context="Code" dev="JM" type="add">
Support for GIF images in RTF output (RTF handler, only. Does not affect the RTF library.)
</action>
<action context="Code" dev="JM" type="fix" fixes-bug="41488" due-to="Dominic Brügger">
<action context="Code" dev="JM" type="fix">
Fix for NPE with PNG images for RTF output.
</action>
<action context="Code" dev="AD" type="fix">
Fix for properly parsing font-family names containing spaces.
</action>
<action context="Code" dev="JM" type="add">
Support for soft masks (transparency) with ImageIO image adapter.
</action>

Laden…
Abbrechen
Speichern