Mercurial > hg > octave-lojdl
changeset 12112:3ab05b7b61ee release-3-2-x
orient.m: Flip papersize and paperposition when orientation changes. Add support for 'tall' option. Add tests.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Wed, 18 Nov 2009 20:18:47 -0500 |
parents | 050b8c0e1531 |
children | 232a0ddce7cd |
files | scripts/ChangeLog scripts/plot/orient.m |
diffstat | 2 files changed, 61 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2009-11-18 Ben Abbott <bpabbott@mac.com> + + * plot/orient.m: Flip papersize and paperposition when orientation + changes. Add support for 'tall' option. Add tests. + 2009-11-26 David Grundberg <individ@acc.umu.se> * linear-algebra/dot.m: Conjugate first argument.
--- a/scripts/plot/orient.m +++ b/scripts/plot/orient.m @@ -19,7 +19,12 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} orient (@var{orientation}) ## Set the default print orientation. Valid values for -## @var{orientation} include @code{"landscape"} and @code{"portrait"}. +## @var{orientation} include @code{"landscape"}, @code{"portrait"}, +## and @code{"tall"}. +## +## The @code{"tall"} option sets the orientation to portait and fills +## the page with the plot, while leaving a 0.25in border. +## ## If called with no arguments, return the default print orientation. ## @end deftypefn @@ -43,7 +48,19 @@ elseif (nargin == 1) orientation = varargin{1}; if (strcmpi (orientation, "landscape") || strcmpi (orientation, "portrait")) - set (cf, "paperorientation", orientation) + if (! strcmpi (get (cf, "paperorientation"), orientation)) + ## FIXME - with the proper listeners in place there won't be a need to set + ## the papersize and paperpostion here. + papersize = get (cf, "papersize"); + paperposition = get (cf, "paperposition"); + set (cf, "paperorientation", orientation) + set (cf, "papersize", papersize([2, 1])); + set (cf, "paperposition", paperposition([2, 1, 4, 3])); + endif + elseif (strcmpi (varargin{1}, 'tall')) + orient ("portrait") + papersize = get (cf, "papersize"); + set (cf, "paperposition", [0.25, 0.25, (papersize - 0.5)]); else error ("orient: unknown orientation"); endif @@ -53,12 +70,40 @@ endfunction -%!shared -%! set (gcf (), "visible", "off") -%!assert(orient,"portrait") # default -%!test orient('landscape') -%!assert(orient,"landscape") # change to landscape -%!test orient('portrait') -%!assert(orient,"portrait") # change to portrait -%!fail("orient('nobody')","unknown orientation") -%!assert(orient,"portrait") # errors don't change the state +%!shared papersize, paperposition, tallpaperposition, hfig +%! papersize = [8.5, 11]; +%! paperposition = [0.25, 2.5, 8, 6]; +%! tallpaperposition = [0.25, 0.25, (papersize-0.5)]; +%! hfig = figure (); +%! set (hfig, "visible", "off") +%! set (hfig, "paperorientation", "portrait") +%! set (hfig, "papersize", papersize) +%! set (hfig, "paperposition", paperposition) +%!test +%! orient portrait +%! assert (orient, "portrait") # default +%! assert (get (hfig, "papersize"), papersize) +%! assert (get (hfig, "paperposition"), paperposition) +%!test +%! orient landscape +%! assert (orient,"landscape") # change to landscape +%! assert (get (hfig, "papersize"), papersize([2, 1])) +%! assert (get (hfig, "paperposition"), paperposition([2, 1, 4, 3])) +%!test +%! orient portrait # change back to portrait +%! assert (orient, "portrait") +%! assert (get (hfig, "papersize"), papersize) +%! assert (get (hfig, "paperposition"), paperposition) +%!test +%! orient landscape +%! orient tall +%! assert (orient, "portrait") +%! assert (get (hfig, "papersize"), papersize) +%! assert (get (hfig, "paperposition"), tallpaperposition) +%!fail ("orient ('nobody')", "unknown orientation") +%!test +%! orient portrait # errors don't change the state +%! assert (orient, "portrait") +%! assert (get (hfig, "papersize"), papersize) +%! assert (get (hfig, "paperposition"), tallpaperposition) +%! close (hfig)