diff options
author | Simon Steiner <ssteiner@apache.org> | 2015-02-10 13:21:17 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2015-02-10 13:21:17 +0000 |
commit | a56f97607b7260a1ebfde968d53d35a5b333d6df (patch) | |
tree | 784096b60a3d7ffcb49c3e1526f6a7016f001b40 | |
parent | 1a9d4862297fce26abab8f6f8dd93369a2a7f7ad (diff) | |
download | xmlgraphics-fop-a56f97607b7260a1ebfde968d53d35a5b333d6df.tar.gz xmlgraphics-fop-a56f97607b7260a1ebfde968d53d35a5b333d6df.zip |
FOP-2448: PDF to PS deduplication of images
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1658710 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | lib/xmlgraphics-commons-svn-trunk.jar | bin | 632559 -> 632951 bytes | |||
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSDocumentHandler.java | 43 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java | 5 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java | 5 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSImageUtils.java | 3 |
5 files changed, 46 insertions, 10 deletions
diff --git a/lib/xmlgraphics-commons-svn-trunk.jar b/lib/xmlgraphics-commons-svn-trunk.jar Binary files differindex 733564726..262c55b31 100644 --- a/lib/xmlgraphics-commons-svn-trunk.jar +++ b/lib/xmlgraphics-commons-svn-trunk.jar diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java index 158cb0fc1..b40fef8ba 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java @@ -30,6 +30,7 @@ import java.io.OutputStream; import java.net.URI; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -142,7 +143,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { return new PSRendererConfigurator(getUserAgent(), new PSRendererConfigParser()); } - PSRenderingUtil getPSUtil() { + public PSRenderingUtil getPSUtil() { return this.psUtil; } @@ -160,12 +161,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { } //Setup for PostScript generation - this.gen = new PSGenerator(out) { - /** Need to subclass PSGenerator to have better URI resolution */ - public Source resolveURI(String uri) { - return getUserAgent().resolveURI(uri); - } - }; + this.gen = new FOPPSGeneratorImpl(out); this.gen.setPSLevel(psUtil.getLanguageLevel()); this.currentPageNumber = 0; this.documentBoundingBox = new Rectangle2D.Double(); @@ -179,6 +175,37 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { } } + public interface FOPPSGenerator { + PSDocumentHandler getHandler(); + BufferedOutputStream getTempStream(URI uri) throws IOException; + Map<Integer, URI> getImages(); + } + + public class FOPPSGeneratorImpl extends PSGenerator implements FOPPSGenerator { + private Map<Integer, URI> images = new HashMap<Integer, URI>(); + public FOPPSGeneratorImpl(OutputStream out) { + super(out); + } + + /** Need to subclass PSGenerator to have better URI resolution */ + @Override + public Source resolveURI(String uri) { + return getUserAgent().resolveURI(uri); + } + + public PSDocumentHandler getHandler() { + return PSDocumentHandler.this; + } + + public BufferedOutputStream getTempStream(URI uri) throws IOException { + return new BufferedOutputStream(getUserAgent().getResourceResolver().getOutputStream(uri)); + } + + public Map<Integer, URI> getImages() { + return images; + } + } + private void writeHeader() throws IOException { //PostScript Header gen.writeln(DSCConstants.PS_ADOBE_30); @@ -558,7 +585,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { * @param uri the image URI * @return a PSResource instance */ - protected PSResource getFormForImage(String uri) { + public PSResource getFormForImage(String uri) { if (uri == null || "".equals(uri)) { throw new IllegalArgumentException("uri must not be empty or null"); } diff --git a/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java b/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java index 7bbe9bd8b..2ed64e770 100644 --- a/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java @@ -26,6 +26,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Map; +import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter; import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; import org.apache.xmlgraphics.ps.PSGenerator; @@ -94,7 +95,9 @@ public class PSGraphics2DAdapter extends AbstractGraphics2DAdapter { gen.concatMatrix(sx, 0, 0, sy, fx, fy); final boolean textAsShapes = false; - PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen); + PSGraphics2D graphics = (painter instanceof GeneralGraphics2DImagePainter) + ? (PSGraphics2D) ((GeneralGraphics2DImagePainter) painter).getGraphics(textAsShapes, gen) + : new PSGraphics2D(textAsShapes, gen); graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); AffineTransform transform = new AffineTransform(); // scale to viewbox diff --git a/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java index ed0b4e24a..f7f22020a 100644 --- a/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java @@ -30,6 +30,7 @@ import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; +import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter; import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; import org.apache.xmlgraphics.ps.FormGenerator; @@ -84,7 +85,9 @@ public class PSImageHandlerGraphics2D implements PSImageHandler { gen.concatMatrix(sx, 0, 0, sy, fx, fy); final boolean textAsShapes = false; - PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen); + PSGraphics2D graphics = (painter instanceof GeneralGraphics2DImagePainter) + ? (PSGraphics2D) ((GeneralGraphics2DImagePainter) painter).getGraphics(textAsShapes, gen) + : new PSGraphics2D(textAsShapes, gen); graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); AffineTransform transform = new AffineTransform(); // scale to viewbox diff --git a/src/java/org/apache/fop/render/ps/PSImageUtils.java b/src/java/org/apache/fop/render/ps/PSImageUtils.java index e9d4ff27f..5f7aa7b79 100644 --- a/src/java/org/apache/fop/render/ps/PSImageUtils.java +++ b/src/java/org/apache/fop/render/ps/PSImageUtils.java @@ -48,6 +48,9 @@ public class PSImageUtils extends org.apache.xmlgraphics.ps.PSImageUtils { * @return true if the image shall be inlined, false if forms shall be used. */ public static boolean isImageInlined(ImageInfo info, PSRenderingContext renderingContext) { + if (info.getMimeType().equals("application/pdf")) { + return true; + } String uri = info.getOriginalURI(); if (uri == null || "".equals(uri)) { return true; |