Bug 13741 fixed: Impossible to print an invisible figure under Windows 30/15930/1
Calixte DENIZET [Tue, 10 Feb 2015 14:16:20 +0000 (15:16 +0100)]
Change-Id: I5b73506df6cc3fde4898cdc83b30e15bcc250258

scilab/CHANGES_5.5.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/CallScilabBridge.java

index f44a779..0df9be2 100644 (file)
@@ -47,6 +47,7 @@ Scilab Bug Fixes
 
 * Bug #13725 fixed - Polyline was not correctly filled with big values.
 
+* Bug #13741 fixed - Impossible to print an invisible figure under Windows.
 
 
                      Changes between version 5.5.0 and 5.5.1
index 7b350dc..838f2b4 100644 (file)
@@ -25,12 +25,14 @@ import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.StringSelection;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.image.BufferedImage;
 import java.awt.print.PrinterJob;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import javax.imageio.ImageIO;
 import javax.print.Doc;
 import javax.print.DocFlavor;
 import javax.print.DocPrintJob;
@@ -872,11 +874,28 @@ public class CallScilabBridge {
             if (isWindowsPlateform()) {
                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(figID);
                 int figureID = figure.getId();
-                SwingScilabCanvas canvas;
-                canvas = ((SwingScilabDockablePanel) SwingView.getFromId(figID)).getContentCanvas();
-                ScilabPrint scilabPrint = new ScilabPrint(canvas.dumpAsBufferedImage(), printerJob, scilabPageFormat);
-                if (scilabPrint != null) {
-                    return true;
+                BufferedImage bimage = null;
+                if (figure.getVisible()) {
+                    bimage = ((SwingScilabDockablePanel) SwingView.getFromId(figID)).getContentCanvas().dumpAsBufferedImage();
+                } else {
+                    try {
+                        File tmpPrinterFile = File.createTempFile("scilabfigure", ".png");
+                        tmpPrinterFile.delete();
+                        FileExporter.fileExport(figID, tmpPrinterFile.getAbsolutePath(), "PNG", 1, 0);
+                        bimage = ImageIO.read(tmpPrinterFile);
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                        return false;
+                    }
+                }
+
+                if (bimage != null) {
+                    ScilabPrint scilabPrint = new ScilabPrint(bimage, printerJob, scilabPageFormat);
+                    if (scilabPrint != null) {
+                        return true;
+                    } else {
+                        return false;
+                    }
                 } else {
                     return false;
                 }