diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-01-20 14:08:20 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-01-20 14:08:20 +0000 |
commit | 0cb69bccd8be607c9ce36eedd58c1f5f25a042d0 (patch) | |
tree | e8d2b949bfa1593d5d541b149d94ea1c943a2c67 /src/java/org/apache/fop | |
parent | 68674072dea8e8438870a493e5d2bd4c366a87bb (diff) | |
download | xmlgraphics-fop-0cb69bccd8be607c9ce36eedd58c1f5f25a042d0.tar.gz xmlgraphics-fop-0cb69bccd8be607c9ce36eedd58c1f5f25a042d0.zip |
Clipping the background image.
Added support for fetching bitmap resolution (only implemented for JFIF-compliant JPEG files for now, all other remain at 72dpi as before)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198294 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
5 files changed, 114 insertions, 14 deletions
diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 8f0fe7fda..c9f67a0fc 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -306,7 +306,7 @@ public class ExternalGraphic extends FObj { public int getIntrinsicWidth() { prepareIntrinsicSize(); if (fopimage != null) { - return fopimage.getWidth() * 1000; + return fopimage.getIntrinsicWidth(); } else { return 0; } @@ -318,7 +318,7 @@ public class ExternalGraphic extends FObj { public int getIntrinsicHeight() { prepareIntrinsicSize(); if (fopimage != null) { - return fopimage.getHeight() * 1000; + return fopimage.getIntrinsicHeight(); } else { return 0; } diff --git a/src/java/org/apache/fop/image/AbstractFopImage.java b/src/java/org/apache/fop/image/AbstractFopImage.java index 57a4098cd..e97a0ec68 100644 --- a/src/java/org/apache/fop/image/AbstractFopImage.java +++ b/src/java/org/apache/fop/image/AbstractFopImage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,12 @@ public abstract class AbstractFopImage implements FopImage { * Image height (in pixel). */ protected int height = 0; + + /** Horizontal bitmap resolution (in dpi) */ + protected double dpiHorizontal = 72.0f; + + /** Vertical bitmap resolution (in dpi) */ + protected double dpiVertical = 72.0f; /** * Image input stream. @@ -112,6 +118,8 @@ public abstract class AbstractFopImage implements FopImage { if (this.imageInfo.width != -1) { width = imageInfo.width; height = imageInfo.height; + dpiHorizontal = imageInfo.dpiHorizontal; + dpiVertical = imageInfo.dpiVertical; loaded = loaded | DIMENSIONS; } } @@ -197,21 +205,39 @@ public abstract class AbstractFopImage implements FopImage { } /** - * Return the image width. - * @return the image width + * @return the image width (in pixels) */ public int getWidth() { return this.width; } - + /** - * Return the image height. - * @return the image height + * @return the image height (in pixels) */ public int getHeight() { return this.height; } + /** @see org.apache.fop.image.FopImage#getIntrinsicWidth() */ + public int getIntrinsicWidth() { + return (int)(getWidth() * 72000 / getHorizontalResolution()); + } + + /** @see org.apache.fop.image.FopImage#getIntrinsicHeight() */ + public int getIntrinsicHeight() { + return (int)(getHeight() * 72000 / getVerticalResolution()); + } + + /** @see org.apache.fop.image.FopImage#getHorizontalResolution() */ + public double getHorizontalResolution() { + return this.dpiHorizontal; + } + + /** @see org.apache.fop.image.FopImage#getVerticalResolution() */ + public double getVerticalResolution() { + return this.dpiVertical; + } + /** * Return the image color space. * @return the image color space (java.awt.color.ColorSpace) diff --git a/src/java/org/apache/fop/image/FopImage.java b/src/java/org/apache/fop/image/FopImage.java index e15a9c784..ee81539d1 100644 --- a/src/java/org/apache/fop/image/FopImage.java +++ b/src/java/org/apache/fop/image/FopImage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,6 +74,26 @@ public interface FopImage { * @return the height in pixels */ int getHeight(); + + /** + * @return the intrinsic image width (in millipoints) + */ + int getIntrinsicWidth(); + + /** + * @return the intrinsic image width (in millipoints) + */ + int getIntrinsicHeight(); + + /** + * @return the horizontal bitmap resolution (in dpi) + */ + double getHorizontalResolution(); + + /** + * @return the vertical bitmap resolution (in dpi) + */ + double getVerticalResolution(); /** * Returns the color space of the image. @@ -151,6 +171,8 @@ public interface FopImage { public InputStream inputStream; public int width; public int height; + public double dpiHorizontal = 72.0f; + public double dpiVertical = 72.0f; public Object data; public String mimeType; public String str; diff --git a/src/java/org/apache/fop/image/analyser/JPEGReader.java b/src/java/org/apache/fop/image/analyser/JPEGReader.java index 3aafbb8bc..71f6f7da1 100644 --- a/src/java/org/apache/fop/image/analyser/JPEGReader.java +++ b/src/java/org/apache/fop/image/analyser/JPEGReader.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,8 +111,8 @@ outer: imageStream.mark(avail); pos = (int)this.skip(imageStream, pos); avail -= pos; - } - + } + //Marker first byte (FF) marker = imageStream.read(); pos++; avail--; } while (marker != MARK); @@ -125,6 +125,7 @@ outer: pos = (int)this.skip(imageStream, pos); avail -= pos; } + //Marker second byte marker = imageStream.read(); pos++; avail--; } while (marker == MARK); @@ -134,6 +135,52 @@ outer: break; case NULL: break; + case APP0: + if (avail < 14) { + imageStream.reset(); + avail = 2 * pos; + imageStream.mark(avail); + pos = (int)this.skip(imageStream, pos); + avail -= pos; + } + int reclen = this.read2bytes(imageStream); + pos += 2; avail -= 2; + this.skip(imageStream, 7); + pos += 7; avail -= 7; + int densityUnits = imageStream.read(); + pos++; avail--; + int xdensity = this.read2bytes(imageStream); + pos += 2; avail -= 2; + int ydensity = this.read2bytes(imageStream); + pos += 2; avail -= 2; + + if (densityUnits == 2) { + info.dpiHorizontal = xdensity * 28.3464567 / 72; //dpi + info.dpiVertical = ydensity * 28.3464567 / 72; //dpi + } else if (densityUnits == 1) { + info.dpiHorizontal = xdensity; + info.dpiVertical = ydensity; + } else { + //nop, nyi --> 72dpi + } + + int restlen = reclen - 12; + if (avail < restlen) { + imageStream.reset(); + avail = 2 * pos; + if (avail < pos + restlen + 10) { + avail = (int)(pos + restlen + 10); + } + imageStream.mark(avail); + pos = (int)this.skip(imageStream, pos); + avail -= pos; + } + skipped = this.skip(imageStream, restlen - 2); + pos += skipped; avail -= skipped; + if (skipped != restlen - 2) { + throw new IOException("Skipping Error"); + } + break; case SOF1: case SOF2: case SOF3: // SOF3 and SOFA are only supported by PDF 1.3 diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index eaae3bb2d..b9bead12c 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -582,6 +582,8 @@ public class PDFRenderer extends PrintRenderer { ImageFactory fact = ImageFactory.getInstance(); FopImage fopimage = fact.getImage(back.getURL(), userAgent); if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) { + saveGraphicsState(); + clip(startx, starty, width, height); if (back.getRepeat() == EN_REPEAT) { // create a pattern for the image } else { @@ -589,10 +591,13 @@ public class PDFRenderer extends PrintRenderer { Rectangle2D pos; pos = new Rectangle2D.Float((startx + back.getHoriz()) * 1000, (starty + back.getVertical()) * 1000, - fopimage.getWidth() * 1000, - fopimage.getHeight() * 1000); + fopimage.getIntrinsicWidth(), + fopimage.getIntrinsicHeight()); putImage(back.getURL(), pos); } + restoreGraphicsState(); + } else { + getLogger().warn("Can't find background image: " + back.getURL()); } } } |