1 ## Copyright (C) 2001-2012 Paul Kienzle
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} orient (@var{orientation})
21 ## Set the default print orientation. Valid values for
22 ## @var{orientation} include @code{"landscape"}, @code{"portrait"},
25 ## The @code{"tall"} option sets the orientation to portait and fills
26 ## the page with the plot, while leaving a 0.25in border.
28 ## If called with no arguments, return the default print orientation.
31 ## Author: Paul Kienzle
34 function retval = orient (varargin)
38 if (nargs > 0 && numel (varargin{1}) == 1 && isfigure (varargin{1}))
47 retval = get (cf, "paperorientation");
49 orientation = varargin{1};
50 if (strcmpi (orientation, "landscape") || strcmpi (orientation, "portrait"))
51 if (! strcmpi (get (cf, "paperorientation"), orientation))
52 ## FIXME - with the proper listeners in place there won't be a need to set
53 ## the papersize and paperpostion here.
54 papersize = get (cf, "papersize");
55 paperposition = get (cf, "paperposition");
56 set (cf, "paperorientation", orientation);
57 set (cf, "papersize", papersize([2, 1]));
58 set (cf, "paperposition", paperposition([2, 1, 4, 3]));
60 elseif (strcmpi (varargin{1}, 'tall'))
62 papersize = get (cf, "papersize");
63 set (cf, "paperposition", [0.25, 0.25, (papersize - 0.5)]);
65 error ("orient: unknown ORIENTATION");
73 %!shared papersize, paperposition, tallpaperposition, hfig
74 %! papersize = [8.5, 11];
75 %! paperposition = [0.25, 2.5, 8, 6];
76 %! tallpaperposition = [0.25, 0.25, (papersize-0.5)];
78 %! set (hfig, "visible", "off")
79 %! set (hfig, "paperorientation", "portrait")
80 %! set (hfig, "papersize", papersize)
81 %! set (hfig, "paperposition", paperposition)
84 %! assert (orient, "portrait") # default
85 %! assert (get (hfig, "papersize"), papersize)
86 %! assert (get (hfig, "paperposition"), paperposition)
89 %! assert (orient,"landscape") # change to landscape
90 %! assert (get (hfig, "papersize"), papersize([2, 1]))
91 %! assert (get (hfig, "paperposition"), paperposition([2, 1, 4, 3]))
93 %! orient portrait # change back to portrait
94 %! assert (orient, "portrait")
95 %! assert (get (hfig, "papersize"), papersize)
96 %! assert (get (hfig, "paperposition"), paperposition)
100 %! assert (orient, "portrait")
101 %! assert (get (hfig, "papersize"), papersize)
102 %! assert (get (hfig, "paperposition"), tallpaperposition)
103 %!fail ("orient ('nobody')", "unknown ORIENTATION")
105 %! orient portrait # errors don't change the state
106 %! assert (orient, "portrait")
107 %! assert (get (hfig, "papersize"), papersize)
108 %! assert (get (hfig, "paperposition"), tallpaperposition)