diff options
author | Jeremias Maerki <jeremias@apache.org> | 2004-08-16 19:33:19 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2004-08-16 19:33:19 +0000 |
commit | 98a82065accd4dfb081daa8429f03f0fed993dff (patch) | |
tree | c0bfd0ef9dcd880fc1a025f2394bddca264d454e /src/java/org/apache/fop/svg | |
parent | 153e0e1d8dd22414d63ba97aefbceb47ec454874 (diff) | |
download | xmlgraphics-fop-98a82065accd4dfb081daa8429f03f0fed993dff.tar.gz xmlgraphics-fop-98a82065accd4dfb081daa8429f03f0fed993dff.zip |
Fix JPEG with many long APPS markers.
Also defers the creation of the original node until it absolutely has to thus avoiding decoding the JPEG file and creating the raster unless needed.
Submitted by: Thomas DeWeese <Thomas.DeWeese.at.Kodak.com>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197881 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/svg')
-rw-r--r-- | src/java/org/apache/fop/svg/PDFImageElementBridge.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/java/org/apache/fop/svg/PDFImageElementBridge.java b/src/java/org/apache/fop/svg/PDFImageElementBridge.java index 567e0c46d..a77855ed0 100644 --- a/src/java/org/apache/fop/svg/PDFImageElementBridge.java +++ b/src/java/org/apache/fop/svg/PDFImageElementBridge.java @@ -27,6 +27,8 @@ import org.apache.fop.image.analyser.ImageReaderFactory; import java.awt.Shape; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; +import java.io.BufferedInputStream; +import java.io.InputStream; import org.w3c.dom.Element; @@ -59,17 +61,25 @@ public class PDFImageElementBridge extends SVGImageElementBridge { */ protected GraphicsNode createImageGraphicsNode (BridgeContext ctx, Element e, ParsedURL purl) { - GraphicsNode origGN = super.createImageGraphicsNode - (ctx, e, purl); try { + InputStream is = purl.openStream(); + if (!is.markSupported()) { + is = new BufferedInputStream(is, 1024); + } + + is.mark(3); + byte [] data = new byte[3]; + is.read(data); + is.reset(); + if ((data[0] == (byte)0xFF) && (data[1] == (byte)0xD8) && + (data[2] == (byte)0xFF)) { FopImage.ImageInfo ii = ImageReaderFactory.make - (purl.toString(), purl.openStream(), null); - if (ii.mimeType.toLowerCase() == "image/jpeg") { + (purl.toString(), is, null); JpegImage jpeg = new JpegImage(ii); SimpleLog logger = new SimpleLog("FOP/SVG"); logger.setLevel(SimpleLog.LOG_LEVEL_INFO); jpeg.load(FopImage.ORIGINAL_DATA); - PDFJpegNode node = new PDFJpegNode(jpeg, origGN); + PDFJpegNode node = new PDFJpegNode(jpeg, ctx, e, purl); Rectangle2D imgBounds = getImageBounds(ctx, e); Rectangle2D bounds = node.getPrimitiveBounds(); @@ -87,26 +97,37 @@ public class PDFImageElementBridge extends SVGImageElementBridge { } catch (Exception ex) { } - return origGN; + return superCreateGraphicsNode(ctx, e, purl); + } + + protected GraphicsNode superCreateGraphicsNode + (BridgeContext ctx, Element e, ParsedURL purl) { + return super.createImageGraphicsNode(ctx, e, purl); } + /** * A PDF jpeg node. * This holds a jpeg image so that it can be drawn into * the PDFGraphics2D. */ - public static class PDFJpegNode extends AbstractGraphicsNode { + public class PDFJpegNode extends AbstractGraphicsNode { private JpegImage jpeg; - private GraphicsNode origGraphicsNode ; + private BridgeContext ctx; + private Element e; + private ParsedURL purl; + private GraphicsNode origGraphicsNode=null; /** * Create a new pdf jpeg node for drawing jpeg images * into pdf graphics. * @param j the jpeg image */ - public PDFJpegNode(JpegImage j, - GraphicsNode origGraphicsNode) { - jpeg = j; - this.origGraphicsNode = origGraphicsNode; + public PDFJpegNode(JpegImage j, BridgeContext ctx, + Element e, ParsedURL purl) { + this.jpeg = j; + this.ctx = ctx; + this.e = e; + this.purl = purl; } /** @@ -137,7 +158,14 @@ public class PDFImageElementBridge extends SVGImageElementBridge { } } else { // Not going directly into PDF so use - // original implemtation so filters etc work. + // original implementation so filters etc work. + if (origGraphicsNode == null) { + // Haven't constructed baseclass Graphics Node, + // so do so now. + origGraphicsNode = + PDFImageElementBridge.this.superCreateGraphicsNode + (ctx, e, purl); + } origGraphicsNode.primitivePaint(g2d); } } |