]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/orient.m
update packages
[CreaPhase.git] / octave_packages / m / plot / orient.m
1 ## Copyright (C) 2001-2012 Paul Kienzle
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} orient (@var{orientation})
21 ## Set the default print orientation.  Valid values for
22 ## @var{orientation} include @code{"landscape"}, @code{"portrait"},
23 ## and @code{"tall"}.
24 ##
25 ## The @code{"tall"} option sets the orientation to portait and fills
26 ## the page with the plot, while leaving a 0.25in border.
27 ##
28 ## If called with no arguments, return the default print orientation.
29 ## @end deftypefn
30
31 ## Author: Paul Kienzle
32 ## Adapted-By: jwe
33
34 function retval = orient (varargin)
35
36   nargs = nargin;
37
38   if (nargs > 0 && numel (varargin{1}) == 1 && isfigure (varargin{1}))
39     cf = varargin{1};
40     varargin(1) = [];
41     nargs--;
42   else
43     cf = gcf ();
44   endif
45
46   if (nargs == 0)
47     retval = get (cf, "paperorientation");
48   elseif (nargin == 1)
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]));
59       endif
60     elseif (strcmpi (varargin{1}, 'tall'))
61       orient ("portrait");
62       papersize = get (cf, "papersize");
63       set (cf, "paperposition", [0.25, 0.25, (papersize - 0.5)]);
64     else
65       error ("orient: unknown ORIENTATION");
66     endif
67   else
68     print_usage ();
69   endif
70
71 endfunction
72
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)];
77 %!  hfig = figure ();
78 %!  set (hfig, "visible", "off")
79 %!  set (hfig, "paperorientation", "portrait")
80 %!  set (hfig, "papersize", papersize)
81 %!  set (hfig, "paperposition", paperposition)
82 %!test
83 %!  orient portrait
84 %!  assert (orient, "portrait") # default
85 %!  assert (get (hfig, "papersize"), papersize)
86 %!  assert (get (hfig, "paperposition"), paperposition)
87 %!test
88 %!  orient landscape
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]))
92 %!test
93 %!  orient portrait # change back to portrait
94 %!  assert (orient, "portrait")
95 %!  assert (get (hfig, "papersize"), papersize)
96 %!  assert (get (hfig, "paperposition"), paperposition)
97 %!test
98 %!  orient landscape
99 %!  orient tall
100 %!  assert (orient, "portrait")
101 %!  assert (get (hfig, "papersize"), papersize)
102 %!  assert (get (hfig, "paperposition"), tallpaperposition)
103 %!fail ("orient ('nobody')", "unknown ORIENTATION")
104 %!test
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)
109 %!  close (hfig)