I'm trying to fix the bug of the command xs2jpg #4615, which
Guilherme Kunigami [Tue, 30 Jun 2009 07:13:08 +0000 (09:13 +0200)]
does not recognize the extension jpeg, appending a '.jpg' to the end of
it. I thought changing the code numbers of file types in ExportRenderer.java
would be very dangerous, since it seems to be a standand in other parts of
scilab.
So I added an extra variable fileExtension, to hold the actual file
extension (this one will be redundant except in the case of jpg and
jpeg). This variable is set in ExportRenderer.removeExtension() and will be
used in ExportBitmap.exportToBitmap() (where before was a hard-coded string,
which is now commented).

scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java

index 3528a08..d97e446 100644 (file)
@@ -53,6 +53,7 @@ public class ExportBitmap extends ExportToFile {
 
                /** Select the screen-shot format */            
                switch (getFiletype()) {
+/*
                case ExportRenderer.BMP_EXPORT:  file = new File(getFilename() + ".bmp");
                break;
                case ExportRenderer.GIF_EXPORT:  file = new File(getFilename() + ".gif");
@@ -61,6 +62,15 @@ public class ExportBitmap extends ExportToFile {
                break;
                case ExportRenderer.PNG_EXPORT:  file = new File(getFilename() + ".png");
                break;                                    
+*/
+
+               case ExportRenderer.BMP_EXPORT:  
+               case ExportRenderer.GIF_EXPORT:  
+               case ExportRenderer.JPG_EXPORT:  
+               case ExportRenderer.PNG_EXPORT:  
+                       file = new File(getFilename() + "." + ExportRenderer.getFileExtension());
+                       break;          
+
                default: return ExportRenderer.INVALID_FILE;
                }
 
index 7983c20..31e5403 100644 (file)
@@ -52,6 +52,9 @@ public abstract class ExportRenderer implements GLEventListener {
        private static String fileName;
        private static int fileType;
        private static int fileOrientation;
+
+       /** File extension */
+        private static String fileExtension;
        
        /** give the type of the error */
        private static int errorNumber;
@@ -66,6 +69,7 @@ public abstract class ExportRenderer implements GLEventListener {
                this.fileName = fileName;
                this.fileType = fileType;       
                this.fileOrientation = fileOrientation;
+               this.fileExtension = "";
                removeExtension();
        }       
 
@@ -146,6 +150,22 @@ public abstract class ExportRenderer implements GLEventListener {
        }
 
        /**
+        * getter 
+        * @return the fileExtension
+        */
+       public static String getFileExtension() {
+               return fileExtension;
+       }
+
+       /**
+        * setter 
+        * @param fileExtension the fileExtension to set
+        */
+       public void setFileExtension(String fileExtension) {
+               this.fileExtension = fileExtension;
+       }
+
+       /**
         * Function allowing to format the extension of the screen-shot file  
         */
        public void removeExtension() {         
@@ -156,23 +176,35 @@ public abstract class ExportRenderer implements GLEventListener {
                        suffix = suffix.toLowerCase();
                        if (suffix.equalsIgnoreCase("bmp") && this.fileType == ExportRenderer.BMP_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "bmp";
                        } else if (suffix.equalsIgnoreCase("gif") && this.fileType == ExportRenderer.GIF_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "gif";
                        } else if (suffix.equalsIgnoreCase("jpg") && this.fileType == ExportRenderer.JPG_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "jpg";
+                       } else if (suffix.equalsIgnoreCase("jpeg") && this.fileType == ExportRenderer.JPG_EXPORT) {
+                               this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "jpeg";
                        } else if (suffix.equalsIgnoreCase("png") && this.fileType == ExportRenderer.PNG_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "png";
                        } else if (suffix.equalsIgnoreCase("ppm") && this.fileType == ExportRenderer.PPM_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "ppm";
                        } else if (suffix.equalsIgnoreCase("eps") && this.fileType == ExportRenderer.EPS_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "eps";
                        } else if (suffix.equalsIgnoreCase("pdf") && this.fileType == ExportRenderer.PDF_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "pdf";
                        } else if (suffix.equalsIgnoreCase("svg") && this.fileType == ExportRenderer.SVG_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
+                               this.fileExtension = "svg";
                        } else if (suffix.equalsIgnoreCase("ps") && this.fileType == ExportRenderer.PS_EXPORT) {
                                this.fileName = this.fileName.substring(0, pos);
-                       }               
+                               this.fileExtension = "ps";
+                       }       
                }
        }
 
index 6cc87b9..9f7dea9 100644 (file)
@@ -43,7 +43,7 @@ public class FileExporter {
         */
        public static int fileExport(int figureIndex, String fileName, int fileType, int fileOrientation) {
                DrawableFigureGL exportedFig = FigureMapper.getCorrespondingFigure(figureIndex);
-               
+
                if (exportedFig == null) {
                        // figure no longer exists
                        return ExportRenderer.IOEXCEPTION_ERROR;