Author: phancock
Date: Mon Sep 26 10:06:22 2011
New Revision: 1175764

URL: http://svn.apache.org/viewvc?rev=1175764&view=rev
Log:
Bugzilla#51760: PS images stored as an embedded file which has no length limit.

Modified:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
    xmlgraphics/fop/trunk/status.xml

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=1175764&r1=1175763&r2=1175764&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
 Mon Sep 26 10:06:22 2011
@@ -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.FormGen
 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 im
     }
 
     /** {@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 im
         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;
+    }
 }

Modified: xmlgraphics/fop/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1175764&r1=1175763&r2=1175764&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Mon Sep 26 10:06:22 2011
@@ -60,6 +60,11 @@
       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>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to