Add to possibility to input figure handles in xs2xxx routines
Jean-Baptiste Silvy [Wed, 14 Jan 2009 16:29:05 +0000 (17:29 +0100)]
13 files changed:
scilab/modules/graphic_export/graphics_Import.def
scilab/modules/graphic_export/help/en_US/xs2bmp.xml
scilab/modules/graphic_export/help/en_US/xs2emf.xml
scilab/modules/graphic_export/help/en_US/xs2eps.xml
scilab/modules/graphic_export/help/en_US/xs2fig.xml
scilab/modules/graphic_export/help/en_US/xs2gif.xml
scilab/modules/graphic_export/help/en_US/xs2jpg.xml
scilab/modules/graphic_export/help/en_US/xs2pdf.xml
scilab/modules/graphic_export/help/en_US/xs2png.xml
scilab/modules/graphic_export/help/en_US/xs2ppm.xml
scilab/modules/graphic_export/help/en_US/xs2ps.xml
scilab/modules/graphic_export/help/en_US/xs2svg.xml
scilab/modules/graphic_export/src/c/xs2file.c

index cf5f207..02d7c41 100644 (file)
@@ -6,3 +6,5 @@ EXPORTS
 sciGetNum
 getFigureFromIndex
 sciIsExistingFigure
+sciGetEntityType
+sciGetPointerFromHandle
index c0b74a0..f71ce6f 100644 (file)
   <refnamediv>
     <refname>xs2bmp</refname>
 
-    <refpurpose>send graphics to a file in BMP syntax</refpurpose>
+    <refpurpose>send graphics to a BMP file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2bmp(win_num,filen)</synopsis>
+    <synopsis>xs2bmp(win_num, file_name)
+xs2bmp(fig, file_name)</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar.</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -58,9 +67,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2bmp</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in BMP
-    format.</para>
+    <para><literal>xs2bmp</literal> exports the display of a graphic window into a BMP file.</para>
   </refsection>
 
   <refsection>
@@ -70,6 +77,7 @@
     plot2d()
     //BMP export
     xs2bmp(0,'foo.bmp')
+       xs2bmp(gcf(), 'foo.bmp');
   </programlisting>
   </refsection>
 
index 7b434b7..d44e208 100644 (file)
   <refnamediv>
     <refname>xs2emf</refname>
 
-    <refpurpose>send graphics to a file in EMF syntax (Only for
-    Windows)</refpurpose>
+    <refpurpose>send graphics to an EMF file (Only for
+    Windows).</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2emf(win_num,filen [,orientation])</synopsis>
+    <synopsis>xs2emf(win_num, file_name [,orientation])
+xs2emf(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar.</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
@@ -58,8 +67,7 @@
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or 'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
     </variablelist>
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2emf</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in EMF
-    format.</para>
+    <para><literal>xs2emf</literal> exports the display of a graphic window into an EMF file.</para>
 
-    <para>For format EMF we create an EPS file which will be convert into EMF
-    format by pstoedit.</para>
+    <para>The export file is obtained by creating an EPS file and converting it into EMF
+    format using pstoedit.</para>
 
   </refsection>
 
@@ -84,6 +90,7 @@
     plot2d()
     //EMF export
     xs2emf(0,'foo.emf')
+    xs2emf(gcf(),'foo.emf')
   </programlisting>
   </refsection>
 
index 0d1c67a..06e18a5 100644 (file)
   <refnamediv>
     <refname>xs2eps</refname>
 
-    <refpurpose>save graphics to a Postscript file.</refpurpose>
+    <refpurpose>send graphics to an EPS file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2eps(win_num,filen [,orientation])</synopsis>
+    <synopsis>xs2eps(win_num, file_name [,orientation])
+xs2eps(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer, id of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>fig</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>handle of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>file_name</term>
+
+        <listitem>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
@@ -57,8 +66,8 @@
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or
+          'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
     </variablelist>
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2eps</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in Postscript
-    syntax. Note that <literal>filen</literal> must not have extension.</para>
-
-    <para><literal>xs2eps</literal> produces a complete encapsulated Postscrip
-    file.<literal> </literal></para>
+    <para><literal>xs2eps</literal> exports the display of a graphic window
+    into a complete Encapsulated PostScript file.</para>
   </refsection>
 
   <refsection>
@@ -82,8 +87,8 @@
     scf(0)
     plot2d()
     //EPS export
-    filename='foo'; // ! no extension
-    xs2eps(0,filename)
+    xs2eps(0,'foo.eps')
+    xs2eps(gcf(),'foo.eps')
   </programlisting>
   </refsection>
 
       <member><link linkend="xs2emf">xs2emf</link></member>
     </simplelist>
   </refsection>
-</refentry>
\ No newline at end of file
+</refentry>
index 2cf1560..ef8be6a 100644 (file)
   <refnamediv>
     <refname>xs2fig</refname>
 
-    <refpurpose>send graphics to a file in FIG syntax</refpurpose>
+    <refpurpose>send graphics to a FIG file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2fig(win_num, filen [,orientation])</synopsis>
+    <synopsis>xs2fig(win_num, file_name [,orientation])
+xs2fig(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar.</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
@@ -57,8 +66,7 @@
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or 'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
     </variablelist>
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2fig</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in FIG
-    format.</para>
+    <para><literal>xs2fig</literal> exports the display of a graphic window into an FIG file.</para>
 
-    <para>For format FIG we create an EPS file which will be convert into FIG
-    format by pstoedit.</para>
-
-    <para>To export FIG files GPL Ghostscript (32bits) need to be
-    installed.</para>
-
-    <para>Link to get GPL Ghostscript : http://www.ghostscript.com/awki</para>
+    <para>The export file is obtained by creating an EPS file and converting it into FIG
+    format using pstoedit.</para>
+       
   </refsection>
-
   <refsection>
     <title>Examples</title>
 
@@ -88,6 +89,7 @@
     scf(0)
     plot2d()
     xs2fig(0,'foo.fig')
+    xs2fig(gcf(),'foo.fig')
   </programlisting>
   </refsection>
 
index c4edc19..3f0ee5c 100644 (file)
   <refnamediv>
     <refname>xs2gif</refname>
 
-    <refpurpose>send graphics to a file in GIF syntax</refpurpose>
+    <refpurpose>send graphics to a GIF file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2gif(win_num,filen)</synopsis>
+    <synopsis>xs2gif(win_num,file_name)
+xs2gif(fig,file_name)</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -58,9 +67,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2gif</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in GIF
-    format. </para>
+    <para><literal>xs2gif</literal> exports the display of a graphic window into a GIF file.</para>
 
     <para>To convert a sequence of "GIF" files to an animated GIF file one can
     use the "convert" program for ImageMagic
@@ -84,6 +91,7 @@
     plot2d()
     //GIF export
     xs2gif(0,'foo.gif')
+    xs2gif(gcf(),'foo.gif')
   </programlisting>
   </refsection>
 
index de696dd..354b5f3 100644 (file)
   <refnamediv>
     <refname>xs2jpg</refname>
 
-    <refpurpose>send graphics to a file in JPG syntax</refpurpose>
+    <refpurpose>send graphics to a JPG file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2jpg(win_num,filen)</synopsis>
+    <synopsis>xs2jpg(win_num, file_name)
+xs2jpg(fig, file_name)</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar.</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -58,9 +67,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2jpg</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in JPG
-    format. </para>
+    <para><literal>xs2jpg</literal> exports the display of a graphic window into a JPG file.</para>
   </refsection>
 
   <refsection>
@@ -70,6 +77,7 @@
     plot2d()
     //JPG export
     xs2jpg(0,'foo.jpg')
+    xs2jpg(gcf(),'foo.jpg')
   </programlisting>
   </refsection>
 
index f8d92a1..d56bcff 100644 (file)
@@ -30,7 +30,8 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2pdf(win_num,filen [,orientation])</synopsis>
+    <synopsis>xs2pdf(win_num, file_name [,orientation])
+xs2pdf(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar .</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
@@ -57,8 +66,7 @@
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or 'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -67,9 +75,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2pdf</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in PDF syntax.
-    Note that <literal>filen</literal> must not have extension.</para>
+    <para><literal>xs2pdf</literal> exports the display of a graphic window into an PDF file.</para>
   </refsection>
 
   <refsection>
@@ -79,8 +85,8 @@
     scf(0)
     plot2d()
     //PDF export
-    filename='foo'; // ! no extension
-    xs2pdf(0,filename)
+    xs2pdf(0,'foo.pdf')
+    xs2pdf(gcf(),'foo.pdf')
   </programlisting>
   </refsection>
 
index 6be7019..cc200e0 100644 (file)
   <refnamediv>
     <refname>xs2png</refname>
 
-    <refpurpose>send graphics to a file in PNG syntax</refpurpose>
+    <refpurpose>send graphics to a PNG file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2png(win_num,filen)</synopsis>
+    <synopsis>xs2png(win_num, file_name)
+xs2png(fig, file_name)</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar.</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -58,9 +67,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2png</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in PNG
-    format. </para>
+    <para><literal>xs2png</literal> exports the display of a graphic window into a PNG file.</para>
   </refsection>
 
   <refsection>
@@ -70,6 +77,7 @@
     plot2d()
     //PNG export
     xs2png(0,'foo.png')
+    xs2png(gcf(),'foo.png')
   </programlisting>
   </refsection>
 
index 13c95f9..5d10fcb 100644 (file)
   <refnamediv>
     <refname>xs2ppm</refname>
 
-    <refpurpose>send graphics to a file in PPM syntax</refpurpose>
+    <refpurpose>send graphics to a PPM file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2ppm(win_num,filen)</synopsis>
+    <synopsis>xs2ppm(win_num, file_name)
+xs2ppm(fig, file_name)</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer, id of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+         
+         <varlistentry>
+        <term>fig</term>
+
+        <listitem>
+          <para>handle of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>file_name</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -58,9 +67,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2ppm</literal> sends the recorded graphics of the window
-    <literal>win_num</literal> in the file <literal>filen</literal> in PPM
-    format. </para>
+    <para><literal>xs2ppm</literal> exports the display of a graphic window into a PPM file.</para>
   </refsection>
 
   <refsection>
@@ -70,6 +77,7 @@
     plot2d()
     //PPM export
     xs2ppm(0,'foo.ppm')
+    xs2ppm(gcf(),'foo.ppm');
   </programlisting>
   </refsection>
 
index 62cfee3..fdae6c7 100644 (file)
   <refnamediv>
     <refname>xs2ps</refname>
 
-    <refpurpose>send graphics to a file in PS syntax</refpurpose>
+    <refpurpose>send graphics to a PS file.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2ps(win_num,filen,[orientation])</synopsis>
+    <synopsis>xs2ps(win_num, file_name [,orientation])
+xs2ps(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer, id of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>fig</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>handle of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>file_name</term>
+
+        <listitem>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or
+          'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
-    </variablelist>
+       </variablelist>
   </refsection>
 
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2ps</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in Postscript
-    syntax. The <literal>filen</literal> must not have suffix
-    extension.</para>
+    <para><literal>xs2ps</literal> exports the display of a graphic window
+    into a PostScript file.</para>
 
     <para>Note that the generated Postscript file cannot be direcly printed
     since it requires a header file. The function <literal>xs2eps</literal>
-    can be used to directly produce an encapsulated Postscript file with an
+    can be used to directly produce an encapsulated Postscript file with a
     header.</para>
   </refsection>
 
@@ -85,8 +92,9 @@
 scf(0);
 plot2d();
 // Postcript export
-filename='foo.ps';
-xs2ps(0,filename);</programlisting>
+xs2ps(0,'foo.ps');
+xs2ps(gcf(),'foo.ps');
+</programlisting>
   </refsection>
 
   <refsection>
index cb4401d..07a62b3 100644 (file)
@@ -30,7 +30,8 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2svg(win_num,filen [,orientation])</synopsis>
+    <synopsis>xs2svg(win_num, file_name [,orientation])
+xs2svg(fig, file_name [,orientation])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
         <term>win_num</term>
 
         <listitem>
-          <para>integer scalar or vector .</para>
+          <para>integer, id of the figure to export.</para>
         </listitem>
       </varlistentry>
 
       <varlistentry>
-        <term>filen</term>
+        <term>fig</term>
 
         <listitem>
-          <para>string, file name.</para>
+          <para>handle of the figure to export.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>file_name</term>
+
+        <listitem>
+          <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
 
@@ -57,8 +66,8 @@
         <term>orientation</term>
 
         <listitem>
-          <para>optional character, with possible values 'p' (portrait) or 'l'
-          (landscape). The default value is 'p'.</para>
+          <para>optional character, with possible values 'portrait' or
+          'landscape'. The default value is 'portrait'.</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -67,9 +76,7 @@
   <refsection>
     <title>Description</title>
 
-    <para><literal>xs2svg</literal> saves the recorded graphics of the window
-    <literal>win_num</literal> to file <literal>filen</literal> in SVG syntax.
-    Note that <literal>filen</literal> must not have extension.</para>
+    <para><literal>xs2svg</literal> exports the display of a graphic window into a SVG file.</para>
   </refsection>
 
   <refsection>
@@ -79,8 +86,8 @@
     scf(0)
     plot2d()
     //SVG export
-    filename='foo'; // ! no extension
-    xs2svg(0,filename)
+    xs2svg(0,'foo.svg')
+    xs2svg(gcf(),'foo.svg');
   </programlisting>
   </refsection>
 
index 73326db..d94740f 100644 (file)
@@ -29,6 +29,15 @@ BOOL isVectorialExport(ExportFileType fileType);
 /*--------------------------------------------------------------------------*/
 int xs2file(char * fname, ExportFileType fileType )
 {
+       sciPointObj * exportedFigure = NULL;
+       int nbRow;
+       int nbCol;
+       size_t stackPointer;
+       char * fileName = NULL;
+       ExportOrientation orientation = EXPORT_PORTRAIT; /* default orientation */
+       int status;
+       
+       /* Check input and output sizes */
        CheckLhs(0,1);
        if (isVectorialExport(fileType))
        {
@@ -39,105 +48,129 @@ int xs2file(char * fname, ExportFileType fileType )
                CheckRhs(2,2);
        }
 
-       if ( (GetType(2) == sci_strings) && IsAScalar(1) )
+       /* Get exported figure */
+       if (IsAScalar(1))
        {
-               int m1,n1,l1;
-               int figurenum = -1;
-               char * fileName = NULL;
-               int status;
-               ExportOrientation orientation = EXPORT_PORTRAIT; /* default orientation */
-
-               /* get figure number */
-               GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1);
-               figurenum = *istk(l1);
-
-               /* Check that figure number exists */
-               if (!sciIsExistingFigure(figurenum))
+               /* window is specified by its number */
+               int figureIndex;
+               GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&nbRow,&nbCol,&stackPointer);
+               figureIndex = *istk(stackPointer);
+               if (!sciIsExistingFigure(figureIndex))
                {
-                       Scierror(999, "%s: Figure with figure_id %d does not exist.\n",fname, figurenum);
+                       Scierror(999, "%s: Figure with figure_id %d does not exist.\n",fname, figureIndex);
                        LhsVar(1)=0;
                        return -1;
                }
+               exportedFigure = getFigureFromIndex(figureIndex);
+       }
+       else if (GetType(1) == sci_handles)
+       {
+               /* handle given */
+               GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &nbRow, &nbCol, &stackPointer);
+               if (nbRow * nbCol != 1)
+               {
+                       Scierror(999,_("%s: Wrong size for input argument #%d: An Integer or a 'Figure' handle expected.\n"),fname, 1);
+                       LhsVar(1)=0;
+                       return 0;
+               }
 
-               /* get file name */
-               GetRhsVar(2,STRING_DATATYPE,&m1,&n1,&l1);
-               fileName = cstk(l1);
+               exportedFigure = sciGetPointerFromHandle((long) *hstk(stackPointer));
 
-               /* Get orientation */
-               if (Rhs == 3)
+               if (exportedFigure == NULL)
                {
-                       int nbCol;
-                       int nbRow;
-                       int stackPointer;
-                       char * sciOrientation;
-                       /* vectorial export with orientation specified */
-                       if (GetType(3) != sci_strings)
-                       {
-                               Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname, 3, "portrait", "landscape");
-                               return 0;
-                       }
-                       GetRhsVar(3,STRING_DATATYPE,&nbRow,&nbCol,&stackPointer);
-                       sciOrientation = cstk(stackPointer);
-                       /* Value should be 'landscape' or 'portrait' but check only the first character */
-                       /* for compatibility with Scilab 4*/
-                       if (strcmp(sciOrientation, "landscape") == 0 || strcmp(sciOrientation, "l") == 0)
-                       {
-                               orientation = EXPORT_LANDSCAPE;
-                       }
-                       else if(strcmp(sciOrientation, "portrait") == 0 || strcmp(sciOrientation, "p") == 0)
-                       {
-                               orientation = EXPORT_PORTRAIT;
-                       }
-                       else
-                       {
-                               Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname, 3, "portrait", "landscape");
-                               return 0;
-                       }
+                       Scierror(999,_("%s: The handle is not or no more valid.\n"),fname);
+      LhsVar(1) = 0;
+      return -1;
                }
 
-               /* Call the function for exporting file */
-               status = exportToFile(getFigureFromIndex(figurenum), fileName, fileType, orientation);
-
-               /* treat errors */
-               switch(status)
+               if (sciGetEntityType(exportedFigure) != SCI_FIGURE)
                {
-               case EXPORT_UNKNOWN_GLEXCEPTION_ERROR :
-                       Scierror(999,_("%s: OpenGL error during export.\n"),fname);
-                       break;
-               case EXPORT_IOEXCEPTION_ERROR :
-                       Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
-                       break;
-               case EXPORT_INVALID_FILE :
-                       Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
-                       break;
-               case EXPORT_GL2PS_ERROR :
-                       Scierror(999,_("%s: GL2PS error during export.\n"),fname);
-                       break;
-               case EXPORT_GL2PS_OVERFLOW :
-                       Scierror(999,_("%s: Unable to create export file, figure is too complex.\n"),fname);
-                       break;
-               case EXPORT_GL2PS_UNINITIALIZED :
-                       Scierror(999,_("%s: GL2PS error during export.\n"),fname);
-                       break;
-               default :
-                       break;
+                       Scierror(999,_("%s: Wrong type for input argument #%d: An Integer or a 'Figure' handle expected.\n"),fname, 1);
+                       LhsVar(1)=0;
+                       return 0;
                }
+       }
+       else
+       {
+               Scierror(999,_("%s: Wrong type for input argument #%d: An Integer or a 'Figure' handle expected.\n"),fname, 1);
+               LhsVar(1)=0;
+               return 0;
+       }
 
+       /* Get file name */
+       if (GetType(2) == sci_strings)
+       {
+               GetRhsVar(2,STRING_DATATYPE,&nbCol,&nbRow,&stackPointer);
+               fileName = cstk(stackPointer);
        }
        else
        {
-               if ( !IsAScalar(1) )
+               Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 2);
+               LhsVar(1)=0;
+               return 0;
+       }
+
+       /* Get orientation if specified */
+       if (Rhs == 3)
+       {
+               char * sciOrientation;
+               /* vectorial export with orientation specified */
+               if (GetType(3) != sci_strings)
                {
-                       Scierror(999,_("%s: Wrong type for input argument #%d: An Integer expected.\n"),fname, 1);
+                       Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 3);
+                       LhsVar(1)=0;
                        return 0;
                }
-               if ( GetType(2) != sci_strings)
+               GetRhsVar(3,STRING_DATATYPE,&nbRow,&nbCol,&stackPointer);
+               sciOrientation = cstk(stackPointer);
+               /* Value should be 'landscape' or 'portrait' but check only the first character */
+               /* for compatibility with Scilab 4*/
+               if (strcmp(sciOrientation, "landscape") == 0 || strcmp(sciOrientation, "l") == 0)
+               {
+                       orientation = EXPORT_LANDSCAPE;
+               }
+               else if(strcmp(sciOrientation, "portrait") == 0 || strcmp(sciOrientation, "p") == 0)
+               {
+                       orientation = EXPORT_PORTRAIT;
+               }
+               else
                {
-                       Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 2);
+                       Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname, 3, "portrait", "landscape");
+                       LhsVar(1)=0;
                        return 0;
                }
        }
 
+
+       /* Call the function for exporting file */
+       status = exportToFile(exportedFigure, fileName, fileType, orientation);
+
+       /* treat errors */
+       switch(status)
+       {
+       case EXPORT_UNKNOWN_GLEXCEPTION_ERROR :
+               Scierror(999,_("%s: OpenGL error during export.\n"),fname);
+               break;
+       case EXPORT_IOEXCEPTION_ERROR :
+               Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
+               break;
+       case EXPORT_INVALID_FILE :
+               Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
+               break;
+       case EXPORT_GL2PS_ERROR :
+               Scierror(999,_("%s: GL2PS error during export.\n"),fname);
+               break;
+       case EXPORT_GL2PS_OVERFLOW :
+               Scierror(999,_("%s: Unable to create export file, figure is too complex.\n"),fname);
+               break;
+       case EXPORT_GL2PS_UNINITIALIZED :
+               Scierror(999,_("%s: GL2PS error during export.\n"),fname);
+               break;
+       default :
+               break;
+       }
+
+
        LhsVar(1)=0;
        return 0;
 }