You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2015/02/10 14:21:18 UTC
svn commit: r1658710 - in /xmlgraphics/fop/trunk: lib/
src/java/org/apache/fop/render/ps/
Author: ssteiner
Date: Tue Feb 10 13:21:17 2015
New Revision: 1658710
URL: http://svn.apache.org/r1658710
Log:
FOP-2448: PDF to PS deduplication of images
Modified:
xmlgraphics/fop/trunk/lib/xmlgraphics-commons-svn-trunk.jar
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java
Modified: xmlgraphics/fop/trunk/lib/xmlgraphics-commons-svn-trunk.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/lib/xmlgraphics-commons-svn-trunk.jar?rev=1658710&r1=1658709&r2=1658710&view=diff
==============================================================================
Binary files - no diff available.
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java?rev=1658710&r1=1658709&r2=1658710&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java Tue Feb 10 13:21:17 2015
@@ -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 A
return new PSRendererConfigurator(getUserAgent(), new PSRendererConfigParser());
}
- PSRenderingUtil getPSUtil() {
+ public PSRenderingUtil getPSUtil() {
return this.psUtil;
}
@@ -160,12 +161,7 @@ public class PSDocumentHandler extends A
}
//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 A
}
}
+ 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 A
* @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");
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java?rev=1658710&r1=1658709&r2=1658710&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java Tue Feb 10 13:21:17 2015
@@ -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
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
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java?rev=1658710&r1=1658709&r2=1658710&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java Tue Feb 10 13:21:17 2015
@@ -30,6 +30,7 @@ import org.apache.xmlgraphics.image.load
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 im
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
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java?rev=1658710&r1=1658709&r2=1658710&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java Tue Feb 10 13:21:17 2015
@@ -48,6 +48,9 @@ public class PSImageUtils extends org.ap
* @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;
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org