From: Jeremias Maerki Date: Mon, 22 Aug 2005 14:48:42 +0000 (+0000) Subject: Remember the original URI in the FopImage instance. X-Git-Tag: fop-0_90-alpha1~361 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e1b540f10ba6efa045dcc3be164a71bbc19d7391;p=xmlgraphics-fop.git Remember the original URI in the FopImage instance. Output the original URI in the comment when writing an image to PostScript. Useful for people who post-process their PostScript files. Fixed the position of the image comment so it can be used to factor out duplicate images when combining multiple PostScript files. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@234500 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/image/AbstractFopImage.java b/src/java/org/apache/fop/image/AbstractFopImage.java index e97a0ec68..2a9136f80 100644 --- a/src/java/org/apache/fop/image/AbstractFopImage.java +++ b/src/java/org/apache/fop/image/AbstractFopImage.java @@ -24,7 +24,6 @@ import java.awt.color.ICC_Profile; import java.io.InputStream; import java.awt.Color; -// FOP import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -133,11 +132,15 @@ public abstract class AbstractFopImage implements FopImage { return imageInfo.mimeType; } + /** @see org.apache.fop.image.FopImage#getOriginalURI() */ + public String getOriginalURI() { + return this.imageInfo.originalURI; + } + /** * Load image data and initialize its properties. * * @param type the type of loading to do - * @param ua the user agent for handling logging etc. * @return true if the loading was successful */ public synchronized boolean load(int type) { @@ -173,7 +176,6 @@ public abstract class AbstractFopImage implements FopImage { * All implementations should override this to get and * return the dimensions. * - * @param ua the user agent * @return true if the loading was successful */ protected boolean loadDimensions() { @@ -185,7 +187,6 @@ public abstract class AbstractFopImage implements FopImage { * If the renderer requires a bitmap image then the * implementations should override this to load the bitmap. * - * @param ua the user agent * @return true if the loading was successful */ protected boolean loadBitmap() { @@ -197,7 +198,6 @@ public abstract class AbstractFopImage implements FopImage { * In some cases the original data can be used by the renderer. * This should load the data and any other associated information. * - * @param ua the user agent * @return true if the loading was successful */ protected boolean loadOriginalData() { diff --git a/src/java/org/apache/fop/image/FopImage.java b/src/java/org/apache/fop/image/FopImage.java index 153947cc9..510a66f05 100644 --- a/src/java/org/apache/fop/image/FopImage.java +++ b/src/java/org/apache/fop/image/FopImage.java @@ -32,17 +32,17 @@ public interface FopImage { /** * Flag for loading dimensions. */ - public static final int DIMENSIONS = 1; + int DIMENSIONS = 1; /** * Flag for loading original data. */ - public static final int ORIGINAL_DATA = 2; + int ORIGINAL_DATA = 2; /** * Flag for loading bitmap data. */ - public static final int BITMAP = 4; + int BITMAP = 4; /** * Get the mime type of this image. @@ -53,6 +53,9 @@ public interface FopImage { */ String getMimeType(); + /** @return the original URI used to access this image. */ + String getOriginalURI(); + /** * Load particular inforamtion for this image * This must be called before attempting to get @@ -170,6 +173,8 @@ public interface FopImage { public static class ImageInfo { /** InputStream to load the image from */ public InputStream inputStream; + /** Original URI the image was accessed with */ + public String originalURI; /** image width (in pixels) */ public int width; /** image height (in pixels) */ diff --git a/src/java/org/apache/fop/image/analyser/BMPReader.java b/src/java/org/apache/fop/image/analyser/BMPReader.java index 077d4f229..12be15dab 100644 --- a/src/java/org/apache/fop/image/analyser/BMPReader.java +++ b/src/java/org/apache/fop/image/analyser/BMPReader.java @@ -30,7 +30,7 @@ import org.apache.fop.apps.FOUserAgent; * ImageReader object for BMP image type. * * @author Pankaj Narula - * @version $Id: BMPReader.java,v 1.8 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class BMPReader implements ImageReader { @@ -54,6 +54,8 @@ public class BMPReader implements ImageReader { && (header[1] == (byte) 0x4d)); if (supported) { FopImage.ImageInfo info = getDimension(header); + info.originalURI = uri; + info.mimeType = getMimeType(); info.inputStream = bis; return info; } else { @@ -72,7 +74,6 @@ public class BMPReader implements ImageReader { private FopImage.ImageInfo getDimension(byte[] header) { FopImage.ImageInfo info = new FopImage.ImageInfo(); - info.mimeType = getMimeType(); // little endian notation int byte1 = header[WIDTH_OFFSET] & 0xff; diff --git a/src/java/org/apache/fop/image/analyser/EPSReader.java b/src/java/org/apache/fop/image/analyser/EPSReader.java index 1d34d702b..8217b6dbd 100644 --- a/src/java/org/apache/fop/image/analyser/EPSReader.java +++ b/src/java/org/apache/fop/image/analyser/EPSReader.java @@ -32,7 +32,7 @@ import org.apache.fop.apps.FOUserAgent; /** * ImageReader object for EPS document image type. * - * @version $Id: EPSReader.java,v 1.9 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class EPSReader implements ImageReader { @@ -80,6 +80,7 @@ public class EPSReader implements ImageReader { if (isEPS) { FopImage.ImageInfo info = new FopImage.ImageInfo(); + info.originalURI = uri; info.mimeType = getMimeType(); info.data = data; readEPSImage(bis, data); diff --git a/src/java/org/apache/fop/image/analyser/GIFReader.java b/src/java/org/apache/fop/image/analyser/GIFReader.java index 8a23ddcc3..ed32d9462 100644 --- a/src/java/org/apache/fop/image/analyser/GIFReader.java +++ b/src/java/org/apache/fop/image/analyser/GIFReader.java @@ -30,7 +30,7 @@ import org.apache.fop.apps.FOUserAgent; * ImageReader object for GIF image type. * * @author Pankaj Narula - * @version $Id: GIFReader.java,v 1.8 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class GIFReader implements ImageReader { @@ -48,6 +48,7 @@ public class GIFReader implements ImageReader { && (header[5] == 'a')); if (supported) { FopImage.ImageInfo info = getDimension(header); + info.originalURI = uri; info.mimeType = getMimeType(); info.inputStream = bis; return info; diff --git a/src/java/org/apache/fop/image/analyser/JPEGReader.java b/src/java/org/apache/fop/image/analyser/JPEGReader.java index 71f6f7da1..b4fde1e11 100644 --- a/src/java/org/apache/fop/image/analyser/JPEGReader.java +++ b/src/java/org/apache/fop/image/analyser/JPEGReader.java @@ -30,7 +30,7 @@ import org.apache.fop.apps.FOUserAgent; * ImageReader object for JPEG image type. * * @author Pankaj Narula - * @version $Id: JPEGReader.java,v 1.8 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class JPEGReader implements ImageReader { @@ -61,6 +61,7 @@ public class JPEGReader implements ImageReader { && (header[1] == (byte) 0xd8)); if (supported) { FopImage.ImageInfo info = getDimension(fis); + info.originalURI = uri; info.mimeType = getMimeType(); info.inputStream = fis; return info; diff --git a/src/java/org/apache/fop/image/analyser/PNGReader.java b/src/java/org/apache/fop/image/analyser/PNGReader.java index c833187a2..08dd9fa19 100644 --- a/src/java/org/apache/fop/image/analyser/PNGReader.java +++ b/src/java/org/apache/fop/image/analyser/PNGReader.java @@ -30,7 +30,7 @@ import org.apache.fop.apps.FOUserAgent; * ImageReader object for PNG image type. * * @author Pankaj Narula - * @version $Id: PNGReader.java,v 1.8 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class PNGReader implements ImageReader { @@ -51,6 +51,7 @@ public class PNGReader implements ImageReader { if (supported) { FopImage.ImageInfo info = getDimension(header); + info.originalURI = uri; info.mimeType = getMimeType(); info.inputStream = bis; return info; diff --git a/src/java/org/apache/fop/image/analyser/SVGReader.java b/src/java/org/apache/fop/image/analyser/SVGReader.java index f5328d04e..d7f433f3c 100644 --- a/src/java/org/apache/fop/image/analyser/SVGReader.java +++ b/src/java/org/apache/fop/image/analyser/SVGReader.java @@ -166,6 +166,7 @@ public class SVGReader implements ImageReader { FopImage.ImageInfo info = new FopImage.ImageInfo(); + info.originalURI = uri; info.mimeType = getMimeType(); info.str = SVGDOMImplementation.SVG_NAMESPACE_URI; diff --git a/src/java/org/apache/fop/image/analyser/TIFFReader.java b/src/java/org/apache/fop/image/analyser/TIFFReader.java index 3d8a82309..fa79c2e79 100644 --- a/src/java/org/apache/fop/image/analyser/TIFFReader.java +++ b/src/java/org/apache/fop/image/analyser/TIFFReader.java @@ -30,7 +30,7 @@ import org.apache.fop.apps.FOUserAgent; * ImageReader object for TIFF image type. * * @author Pankaj Narula, Michael Lee - * @version $Id: TIFFReader.java,v 1.9 2003/03/06 21:25:45 jeremias Exp $ + * @version $Id$ */ public class TIFFReader implements ImageReader { @@ -62,6 +62,7 @@ public class TIFFReader implements ImageReader { if (supported) { FopImage.ImageInfo info = getDimension(header); + info.originalURI = uri; info.mimeType = getMimeType(); info.inputStream = bis; return info; diff --git a/src/java/org/apache/fop/image/analyser/XMLReader.java b/src/java/org/apache/fop/image/analyser/XMLReader.java index 55ebc5dfd..b8d9203ac 100644 --- a/src/java/org/apache/fop/image/analyser/XMLReader.java +++ b/src/java/org/apache/fop/image/analyser/XMLReader.java @@ -62,6 +62,7 @@ public class XMLReader implements ImageReader { FOUserAgent ua) throws IOException { FopImage.ImageInfo info = loadImage(uri, fis, ua); + info.originalURI = uri; if (info != null) { IOUtils.closeQuietly(fis); } diff --git a/src/java/org/apache/fop/render/ps/PSGraphics2D.java b/src/java/org/apache/fop/render/ps/PSGraphics2D.java index be0c50aa6..1d4202454 100644 --- a/src/java/org/apache/fop/render/ps/PSGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSGraphics2D.java @@ -307,7 +307,6 @@ public class PSGraphics2D extends AbstractGraphics2D { private int width; private int bitsPerPixel; private ColorSpace colorSpace; - private int bitmapSiye; private byte[] bitmaps; private byte[] mask; private Color transparentColor; @@ -326,6 +325,10 @@ public class PSGraphics2D extends AbstractGraphics2D { return "application/octet-stream"; } + public String getOriginalURI() { + return "temp-image:" + this.toString(); + } + /** * @see org.apache.fop.image.FopImage#load(int, org.apache.commons.logging.Log) */ diff --git a/src/java/org/apache/fop/render/ps/PSImageUtils.java b/src/java/org/apache/fop/render/ps/PSImageUtils.java index ebc67a4df..b4c3d5f43 100644 --- a/src/java/org/apache/fop/render/ps/PSImageUtils.java +++ b/src/java/org/apache/fop/render/ps/PSImageUtils.java @@ -22,18 +22,15 @@ import java.awt.color.ColorSpace; import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.output.CountingOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.image.EPSImage; import org.apache.fop.image.FopImage; import org.apache.fop.image.JpegImage; -import org.apache.fop.image.XMLImage; import org.apache.fop.util.ASCII85OutputStream; import org.apache.fop.util.Finalizable; import org.apache.fop.util.FlateEncodeOutputStream; import org.apache.fop.util.RunLengthEncodeOutputStream; -import org.w3c.dom.Document; /** * Utility code for rendering images in PostScript. @@ -72,7 +69,10 @@ public class PSImageUtils { byte[] imgmap = img.getBitmaps(); gen.saveGraphicsState(); - gen.commentln("%FOPBeginBitmap: " + img.getMimeType()); + gen.writeln(x + " " + y + " translate"); + gen.writeln(w + " " + h + " scale"); + + gen.commentln("%FOPBeginBitmap: " + img.getMimeType() + " " + img.getOriginalURI()); if (img.getColorSpace().getType() == ColorSpace.TYPE_CMYK) { gen.writeln("/DeviceCMYK setcolorspace"); } else if (img.getColorSpace().getType() == ColorSpace.CS_GRAY) { @@ -81,9 +81,6 @@ public class PSImageUtils { gen.writeln("/DeviceRGB setcolorspace"); } - gen.writeln(x + " " + y + " translate"); - gen.writeln(w + " " + h + " scale"); - gen.writeln("{{"); // Template: (RawData is used for the EOF signal only) // gen.write("/RawData currentfile filter def");