[ChangeSet] print.m: support for figure handles
Ben Abbott
bpabbott at mac.com
Fri Feb 29 14:11:05 CST 2008
On Friday, February 29, 2008, at 10:40AM, "Søren Hauberg" <soren at hauberg.org> wrote:
>
>fre, 29 02 2008 kl. 07:05 -0800, skrev Ben Abbott:
>> I modified print.m to support a figure handle as an input.
>>
>> It is a trivial change, but permits printing as is often done (by me) in Matlab. For example,
>>
>> print (gcf, '-pdf', 'foo.pdf')
>>
>> Please consider the attached changeset.
>I don't know how matlab works, but wouldn't it make sense to do
>something like
>
>if (ishandle (arg))
> old_fig = gcf();
> figure (arg);
>endif
>
>...
>
>if (ishandle(arg))
> figure(old_fig);
>endif
>
>such that the current figure is still the current figure after the call
>to 'print' ?
>
>Søren
>
Good point. Matlab respects that behavior as well.
I've attached the correct changeset.
Ben
-------------- next part --------------
# HG changeset patch
# User Ben Abbott <bpabbott at mac.com>
# Date 1204315307 18000
# Node ID 04426cffcf41b42c437e353a681a41f42086012a
# Parent b84c5cbc081243fabec4026636f0c947c587c372
print.m: Figure handle as argument.
diff -r b84c5cbc0812 -r 04426cffcf41 scripts/ChangeLog
--- a/scripts/ChangeLog Fri Feb 29 04:09:03 2008 -0500
+++ b/scripts/ChangeLog Fri Feb 29 15:01:47 2008 -0500
@@ -1,3 +1,7 @@ 2008-02-29 John W. Eaton <jwe at octave.o
+2008-02-28 Ben Abbott <bpabbott at mac.com>
+
+ * plot/print.m: Modified to accept a figure handle as an optional input.
+
2008-02-29 John W. Eaton <jwe at octave.org>
* plot/print.m: Handle gif and jpg devices.
diff -r b84c5cbc0812 -r 04426cffcf41 scripts/plot/print.m
--- a/scripts/plot/print.m Fri Feb 29 04:09:03 2008 -0500
+++ b/scripts/plot/print.m Fri Feb 29 15:01:47 2008 -0500
@@ -19,10 +19,14 @@
## -*- texinfo -*-
## @deftypefn {Function File} {} print (@var{filename}, @var{options})
+## @deftypefnx {Function File} {} print (@var{h}, @var{filename}, @var{options})
## Print a graph, or save it to a file
##
## @var{filename} defines the file name of the output file. If no
## filename is specified, output is sent to the printer.
+##
+## @var{h} specifies the figure handle. If no handle is specified
+## the handle for the current figure is used.
##
## @var{options}:
## @table @code
@@ -138,6 +142,7 @@ function print (varargin)
debug = false;
debug_file = "octave-print-commands.log";
special_flag = "textnormal";
+ old_fig = [];
## Ensure the last figure is on the screen for single line commands like
## plot(...); print(...);
@@ -184,8 +189,11 @@ function print (varargin)
elseif (length (arg) > 0)
name = arg;
endif
+ elseif (ishandle (arg))
+ old_fig = gcf ();
+ figure (arg);
else
- error ("print: expects string options");
+ error ("print: inputs must be string options, or a figure handle.");
endif
endfor
@@ -431,4 +439,8 @@ function print (varargin)
unlink (printname);
endif
+ if (ishandle (old_fig))
+ figure (old_fig)
+ endif
+
endfunction
More information about the Octave-maintainers
mailing list