From 677accf2e9967c5eeda0ab118f145cf142401c41 Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Mon, 26 Sep 2011 10:06:22 +0000 Subject: [PATCH] Bugzilla#51760: PS images stored as an embedded file which has no length limit. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1175764 13f79535-47bb-0310-9956-ffa450edef68 --- .../render/ps/PSImageHandlerGraphics2D.java | 93 ++++++++++++++----- status.xml | 5 + 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java index b2934d4dd..682d9286e 100644 --- a/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java @@ -26,6 +26,7 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.io.IOException; +import org.apache.fop.render.RenderingContext; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; @@ -36,8 +37,6 @@ import org.apache.xmlgraphics.ps.FormGenerator; import org.apache.xmlgraphics.ps.PSGenerator; import org.apache.xmlgraphics.ps.PSProcSets; -import org.apache.fop.render.RenderingContext; - /** * Image handler implementation which handles vector graphics (Java2D) for PostScript output. */ @@ -97,34 +96,14 @@ public class PSImageHandlerGraphics2D implements PSImageHandler { } /** {@inheritDoc} */ - public void generateForm(RenderingContext context, Image image, PSImageFormResource form) + public void generateForm(RenderingContext context, Image image, final PSImageFormResource form) throws IOException { PSRenderingContext psContext = (PSRenderingContext)context; PSGenerator gen = psContext.getGenerator(); final ImageGraphics2D imageG2D = (ImageGraphics2D)image; ImageInfo info = image.getInfo(); - String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); - final Dimension2D dimensionsPt = info.getSize().getDimensionPt(); - final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt(); - - FormGenerator formGen = new FormGenerator( - form.getName(), imageDescription, dimensionsPt) { - protected void generatePaintProc(PSGenerator gen) - throws IOException { - gen.getResourceTracker().notifyResourceUsageOnPage( - PSProcSets.EPS_PROCSET); - gen.writeln("BeginEPSF"); - PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false); - adapter.paintImage(imageG2D.getGraphics2DImagePainter(), - null, - 0, 0, - (int)Math.round(dimensionsMpt.getWidth()), - (int)Math.round(dimensionsMpt.getHeight())); - gen.writeln("EndEPSF"); - } - - }; + FormGenerator formGen = buildFormGenerator(gen.getPSLevel(), form, info, imageG2D); formGen.generate(gen); } /** {@inheritDoc} */ @@ -150,4 +129,70 @@ public class PSImageHandlerGraphics2D implements PSImageHandler { return false; } + private FormGenerator buildFormGenerator(int psLanguageLevel, final PSImageFormResource form, + final ImageInfo info, final ImageGraphics2D imageG2D) { + String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); + final Dimension2D dimensionsPt = info.getSize().getDimensionPt(); + final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt(); + FormGenerator formGen; + + if (psLanguageLevel <= 2) { + formGen = new EPSFormGenerator(form.getName(), imageDescription, dimensionsPt) { + + @Override + void doGeneratePaintProc(PSGenerator gen) throws IOException { + paintImageG2D(imageG2D, dimensionsMpt, gen); + } + }; + } else { + formGen = new EPSFormGenerator(form.getName(), imageDescription, dimensionsPt) { + + @Override + protected void generateAdditionalDataStream(PSGenerator gen) throws IOException { + gen.writeln("/" + form.getName() + ":Data currentfile <<"); + gen.writeln(" /Filter /SubFileDecode"); + gen.writeln(" /DecodeParms << /EODCount 0 /EODString (%FOPEndOfData) >>"); + gen.writeln(">> /ReusableStreamDecode filter"); + paintImageG2D(imageG2D, dimensionsMpt, gen); + gen.writeln("%FOPEndOfData"); + gen.writeln("def"); + } + + @Override + void doGeneratePaintProc(PSGenerator gen) throws IOException { + gen.writeln(form.getName() + ":Data 0 setfileposition"); + gen.writeln(form.getName() + ":Data cvx exec"); + } + }; + } + return formGen; + } + + private static abstract class EPSFormGenerator extends FormGenerator { + + EPSFormGenerator(String formName, String title, Dimension2D dimensions) { + super(formName, title, dimensions); + } + + protected void paintImageG2D(final ImageGraphics2D imageG2D, Dimension2D dimensionsMpt, + PSGenerator gen) throws IOException { + PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false); + adapter.paintImage(imageG2D.getGraphics2DImagePainter(), + null, + 0, 0, + (int) Math.round(dimensionsMpt.getWidth()), + (int) Math.round(dimensionsMpt.getHeight())); + } + + @Override + protected final void generatePaintProc(PSGenerator gen) throws IOException { + gen.getResourceTracker().notifyResourceUsageOnPage( + PSProcSets.EPS_PROCSET); + gen.writeln("BeginEPSF"); + doGeneratePaintProc(gen); + gen.writeln("EndEPSF"); + } + + abstract void doGeneratePaintProc(PSGenerator gen) throws IOException; + } } diff --git a/status.xml b/status.xml index c636c33e3..4ee7029e0 100644 --- a/status.xml +++ b/status.xml @@ -60,6 +60,11 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Changes the way PostScript handles Graphics2D images such that if the language is set to + level 3, the image is stored as an embedded file which has no length limit. Previously it + was stored as an array which has a implementation limit of 65535 elements. + PDFFactory responsible for asdigning name to a subset font. -- 2.39.5