[ 
https://issues.apache.org/jira/browse/PIVOT-815?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13142974#comment-13142974
 ] 

Noel Grandin commented on PIVOT-815:
------------------------------------

Please try this patch:


Index: ApplicationContext.java
===================================================================
--- ApplicationContext.java     (revision 1196545)
+++ ApplicationContext.java     (working copy)
@@ -21,6 +21,7 @@
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
+import java.awt.PrintGraphics;
 import java.awt.RenderingHints;
 import java.awt.Transparency;
 import java.awt.dnd.DnDConstants;
@@ -425,6 +426,10 @@
 
         @Override
         public void paint(Graphics graphics) {
+            if (graphics instanceof PrintGraphics) {
+                print(graphics);
+                return;
+            }
             // Intersect the clip region with the bounds of this component
             // (for some reason, AWT does not do this automatically)
             graphics.clipRect(0, 0, getWidth(), getHeight());
@@ -455,6 +460,25 @@
         }
 
         @Override
+        public void print(Graphics graphics) {
+            // Intersect the clip region with the bounds of this component
+            // (for some reason, AWT does not do this automatically)
+            graphics.clipRect(0, 0, getWidth(), getHeight());
+
+            java.awt.Rectangle clipBounds = graphics.getClipBounds();
+            if (clipBounds != null
+                && !clipBounds.isEmpty()) {
+                try {
+                    // When printing, there is no point in using offscreen 
buffers.
+                    paintDisplay((Graphics2D)graphics);
+                } catch (RuntimeException exception) {
+                    System.err.println("Exception thrown during print(): " + 
exception);
+                    throw exception;
+                }
+            }
+        }
+
+        @Override
         public void update(Graphics graphics) {
             paint(graphics);
         }

                
> Printing crashes with Out Of Memory exception
> ---------------------------------------------
>
>                 Key: PIVOT-815
>                 URL: https://issues.apache.org/jira/browse/PIVOT-815
>             Project: Pivot
>          Issue Type: Bug
>          Components: wtk, wtk-terra
>    Affects Versions: 2.0
>         Environment: Windows 7 x64, Java 1.6.0_29
>            Reporter: Drazen Dotlic
>            Assignee: Sandro Martini
>              Labels: crash, outofmemory, printing
>             Fix For: 2.0.1
>
>         Attachments: PrintUtilities.java
>
>
> Printing using Java's Printable interface... We have a single Pivot Window 
> (it's an applet) and the layout isn't really complicated. Implementing print 
> method of the Printable interface in our case boils down to drawing into the 
> provided Graphics.
> This has worked perfectly until recently (not sure which version broke 
> things, but we're talking last few weeks). Now when we print we get an "Out 
> of Memory" exception. Call stack does not show any obvious anomalies like 
> infinite loops and such, here it is:
> java.lang.OutOfMemoryError: Java heap space
>       at java.awt.image.DataBufferInt.<init>(Unknown Source)
>       at java.awt.image.Raster.createPackedRaster(Unknown Source)
>       at 
> java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
>       at java.awt.image.BufferedImage.<init>(Unknown Source)
>       at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
>       at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
>       at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown Source)
>       at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown Source)
>       at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
>       at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
>       at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
>       at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
>       at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
>       at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.makeBufferedImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.renderImageXform(Unknown Source)
>       at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.scaleImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
>       at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
>       at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
>       at sun.java2d.SunGraphics2D.copyImage(Unknown Source)
>       at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
>       at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
>       at sun.print.PeekGraphics.drawImage(Unknown Source)
>       at 
> org.apache.pivot.wtk.ApplicationContext$DisplayHost.paintVolatileBuffered(ApplicationContext.java:541)
>       at 
> org.apache.pivot.wtk.ApplicationContext$DisplayHost.paint(ApplicationContext.java:436)
>       at 
> com.barchart.realtime.core.service.PrintService.paint(PrintService.java:60)
>       at 
> com.barchart.realtime.core.service.PrintService.print(PrintService.java:84)
>       at sun.print.RasterPrinterJob.printPage(Unknown Source)
>       at sun.print.RasterPrinterJob.print(Unknown Source)
> If you need more info, do not hesitate to ask. I would have provided a test 
> case, but it's not easy to extract code from a commercial product. Besides, I 
> suspect this is some kind of obvious accidental mistake which should be easy 
> to repeat with a very simple test case.pr

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to