]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla#51760: PS images stored as an embedded file which has no length limit.
authorPeter Hancock <phancock@apache.org>
Mon, 26 Sep 2011 10:06:22 +0000 (10:06 +0000)
committerPeter Hancock <phancock@apache.org>
Mon, 26 Sep 2011 10:06:22 +0000 (10:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1175764 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
status.xml

index b2934d4dde613e080f006699eb05f2aaac8daa16..682d9286ebdbca01b0a67360c328f5a91af457be 100644 (file)
@@ -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;
+    }
 }
index c636c33e3e3846953a46974b4e977a31a7d0edea..4ee7029e047114268faff4f4e9291e810ab7aaed 100644 (file)
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Fonts" dev="PH" type="fix" fixes-bug="51760" due-to="Mehdi Houshmand">
+        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.
+      </action>
       <action context="Fonts" dev="PH" type="fix" fixes-bug="51759" due-to="Mehdi Houshmand">
         PDFFactory responsible for asdigning name to a subset font.
       </action>