# HG changeset patch # User Kai Habel # Date 1289846474 -3600 # Node ID 093c9facf0f0f56c20d6170759f13cda81f8d3b7 # Parent d048ce3f7cefebfd5c71a20adaf63f440915a648 Add saveas function diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-11-15 Kai Habel + + * NEWS: Add saveas. Fix uimenu. + 2010-11-14 Michael Goffioul * mkoctfile.cc.in: replace %OCTAVE_CONF_F77_INTEGER8_FLAG% with diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -314,12 +314,12 @@ ** The following functions are new in Octave 3.4: accumdim erfcx luupdate ppder rsf2csf - bitpack fileread merge ppint sizemax - bitunpack fminbnd nfields ppjumps strread - blkmm fskipl nth_element pqpnonneg textread - cbrt ifelse onCleanup randi whitebg - chop ishermitian pbaspect repelems - daspect isindex powerset reset + bitpack fileread merge ppint saveas + bitunpack fminbnd nfields ppjumps sizemax + blkmm fskipl nth_element pqpnonneg strread + cbrt ifelse onCleanup randi textread + chop ishermitian pbaspect repelems uimenu + daspect isindex powerset reset whitebg ** Using the image function to view images with external programs such as display, xv, and xloadimage is no longer supported. The @@ -439,8 +439,8 @@ allchild ezmesh gtext specular available_backends ezmeshc intwarning surfl backend ezplot ishghandle trisurf - cla ezplot3 isocolors uimenu - clabel ezpolar isonormals waitforbuttonpress + cla ezplot3 isocolors waitforbuttonpress + clabel ezpolar isonormals comet ezsurf isosurface dellistener findall linkprop diffuse gcbf plotmatrix diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,11 @@ +2010-11-15 Kai Habel + + * plot/saveas.m: New file. + * plot/module.mk: Add saveas.m + * plot/__print_parse_opts__.m: Parse arguments correctly when first + argument is a figure handle. + * plot/print.m: Add saveas to seealso entry. + 2010-11-14 Michael Goffioul * plot/print.m: Use "del" instead of "delete" in DOS shell, and diff --git a/scripts/plot/__print_parse_opts__.m b/scripts/plot/__print_parse_opts__.m --- a/scripts/plot/__print_parse_opts__.m +++ b/scripts/plot/__print_parse_opts__.m @@ -71,6 +71,11 @@ endif arg_st.unlink = {}; + if (isfigure (varargin{1})) + arg_st.figure = varargin{1}; + varargin(1) = []; + endif + for i = 1:nargin arg = strtrim (varargin{i}); if (ischar (arg)) diff --git a/scripts/plot/module.mk b/scripts/plot/module.mk --- a/scripts/plot/module.mk +++ b/scripts/plot/module.mk @@ -138,6 +138,7 @@ plot/replot.m \ plot/ribbon.m \ plot/rose.m \ + plot/saveas.m \ plot/scatter.m \ plot/scatter3.m \ plot/semilogx.m \ diff --git a/scripts/plot/print.m b/scripts/plot/print.m --- a/scripts/plot/print.m +++ b/scripts/plot/print.m @@ -248,7 +248,7 @@ ## print -dcdj550 ## @end example ## -## @seealso{figure, orient} +## @seealso{figure, orient, saveas} ## @end deftypefn function print (varargin) diff --git a/scripts/plot/saveas.m b/scripts/plot/saveas.m new file mode 100644 --- /dev/null +++ b/scripts/plot/saveas.m @@ -0,0 +1,100 @@ +## Copyright (C) 2010 Kai Habel +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} saveas (@var{h}, @var{file_name}) +## @deftypefnx {Function File} {} saveas (@var{h}, @var{file_name}, @var{file_ext}) +## Save the graphic object @var{h} to file @var{file_name} in graphic +## format @var{file_ext}. +## +## @var{file_ext} should be one of the following formats: +## +## @table @code +## @item ps +## Postscript +## @item eps +## Encapsulated Postscript +## @item jpg +## JPEG Image +## @item png +## PNG Image +## @item emf +## Enhanced Meta File +## @item pdf +## Portable Document Format +## @end table +## +## All device formats specified in @code{print} can also be used. If @var{file_ext} +## is omitted it is extracted from @var{file_name}. The default value is +## pdf. +## +## @example +## figure (1); +## clf (); +## surf (peaks); +## saveas(1, "figure1.png"); +## @end example +## +## @seealso{print} +## @end deftypefn + +## Author: Kai Habel + +function saveas (h, fname, fext = "pdf") + + if ((nargin != 2) && (nargin != 3)) + print_usage (); + endif + + if (ishandle (h)) + if (isfigure (h)) + fig = h; + else + fig = ancestor (h, "figure") + endif + else + error ("first argument must be a graphics handle"); + endif + + if (!ischar(fname)) + error ("file_name must be a string."); + endif + + if (nargin == 2) + [~, ~, ext] = fileparts (fname); + if (!isempty (ext)) + fext = ext(2:end); + endif + endif + + if (nargin == 3) + if (!ischar (fname)) + error ("fext must be a string."); + endif + + [~, ~, ext] = fileparts (fname); + + if (isempty (ext)) + fname = strcat (fname, ".", fext); + endif + endif + + prt_opt = strcat ("-d", tolower (fext)); + + print (fname, prt_opt) +endfunction