Mercurial > hg > octave-shane
changeset 12023:ff22f50a0266 release-3-2-x
print.m: reimplement options -landscape and -portrait.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 25 Jun 2009 06:36:46 +0200 |
parents | bf661469a039 |
children | 6d6e703f467c |
files | scripts/ChangeLog scripts/plot/__go_draw_figure__.m scripts/plot/gnuplot_drawnow.m scripts/plot/print.m |
diffstat | 4 files changed, 133 insertions(+), 134 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,15 @@ +2009-06-24 Ben Abbott <bpabbott@mac.com> + + * plot/__go_draw_figure__.m: Modify the implicit margin when gnuplot's + output is landscape. + * plot/gnuplot_drawnow.m: Simplify handling of the figure's paper + properties, and rely upon listeners for units conversion. Minor code + improvements. + * plot/print.m: Reimplement -landscape and -portrait to modify the + properties papersize and paperposition. Produce compatible results + when paperpositionmode=='auto'. Simplfy units conversion and + restoration of initial figure properties. + 2009-06-24 Marco Caliari <marco.caliari@univr.it> * general/repmat.m: Call kron, not spkron.
--- a/scripts/plot/__go_draw_figure__.m +++ b/scripts/plot/__go_draw_figure__.m @@ -36,19 +36,26 @@ if (nargin >= 4 && nargin <= 6) htype = get (h, "type"); if (strcmp (htype, "figure")) - - ## When printing, determine the paperposition in inches. + ## When printing, set paperunits to inches and rely on a listener to convert + ## the values for papersize and paperposition. if (output_to_paper) orig_paper_units = get (h, "paperunits"); + gpval_term = __gnuplot_get_var__ (h, "GPVAL_TERM"); + gpval_termoptions = __gnuplot_get_var__ (h, "GPVAL_TERMOPTIONS"); unwind_protect set (h, "paperunits", "inches"); paper_size = get (h, "papersize"); paper_position = get (h, "paperposition"); paper_position = paper_position ./ paper_size([1, 2, 1, 2]); - implicit_margin = implicit_margin ./ paper_size([1, 2]); + implicit_margin = implicit_margin ./ paper_size; unwind_protect_cleanup set (h, "paperunits", orig_paper_units); end_unwind_protect + if (strcmp (gpval_term, "postscript") + && ! isempty (strfind (gpval_termoptions, "landscape"))) + ## This needed to obtain the expected result. + implicit_margin(2) = -implicit_margin(2); + endif else implicit_margin = implicit_margin * [1 1]; endif
--- a/scripts/plot/gnuplot_drawnow.m +++ b/scripts/plot/gnuplot_drawnow.m @@ -109,10 +109,8 @@ endfunction function [enhanced, implicit_margin] = gnuplot_set_term (plot_stream, new_stream, h, term, file) - ## Generate the gnuplot "set terminal <term> ..." command. Include - ## the subset of properties "position", "units", "paperposition", - ## "paperunits", "name", and "numbertitle". When "term" originates - ## from print.m, it may include gnuplot terminal options. + ## Generate the gnuplot "set terminal <term> ..." command. + ## When "term" originates from print.m, it may include other options. if (nargin < 4) ## This supports the gnuplot backend. term = gnuplot_default_term (); @@ -166,11 +164,27 @@ || any (strfind (opts_str, "size ") == 1))) ## Convert position to units used by gnuplot. if (output_to_screen (term)) - ## Get figure size in pixels. - [gnuplot_size, gnuplot_pos] = get_figsize (h); + ## Get figure size in pixels. Rely on listener + ## to handle coversion of position property. + units = get (h, "units"); + unwind_protect + set (h, "units", "pixels"); + position_in_pixesl = get (h, "position"); + unwind_protect_cleanup + set (h, "units", units); + end_unwind_protect + gnuplot_pos = position_in_pixesl(1:2); + gnuplot_size = position_in_pixesl(3:4); else - ## Get size of the printed plot in inches. - gnuplot_size = get_papersize (h); + ## Get size of the printed plot in inches. Rely on listener + ## to handle coversion of papersize property. + paperunits = get (h, "paperunits"); + unwind_protect + set (h, "paperunits", "inches"); + gnuplot_size = get (h, "papersize"); + unwind_protect_cleanup + set (h, "paperunits", paperunits); + end_unwind_protect if (term_units_are_pixels (term)) ## Convert to inches using the property set by print(). gnuplot_size = gnuplot_size * get (h, "__pixels_per_inch__"); @@ -195,13 +209,19 @@ endif if (any (strncmpi (term, terminals_with_size, 3))) if (term_units_are_pixels (term)) - size_str = sprintf ("size %d,%d", gnuplot_size(1), gnuplot_size(2)); + size_str = sprintf ("size %d,%d", gnuplot_size); else - size_str = sprintf ("size %.15g,%.15g", gnuplot_size(1), gnuplot_size(2)); + size_str = sprintf ("size %.15g,%.15g", gnuplot_size); endif if (strncmpi (term, "X11", 3) && __gnuplot_has_feature__ ("x11_figure_position")) ## X11 allows the window to be positioned as well. - screen_size = get (0, "screensize")(3:4); + units = get (0, "units"); + unwind_protect + set (0, "units", "pixels"); + screen_size = get (0, "screensize")(3:4); + unwind_protect_cleanup + set (0, "units", units); + end_unwind_protect if (all (screen_size > 0)) ## For X11, set the figure positon as well as the size ## gnuplot position is UL, Octave's is LL (same for screen/window) @@ -213,13 +233,13 @@ endif elseif (strncmpi (term, "aqua", 3)) ## Aqua has size, but the format is different. - size_str = sprintf ("size %d %d", gnuplot_size(1), gnuplot_size(2)); + size_str = sprintf ("size %d %d", gnuplot_size); elseif (strncmpi (term, "fig", 3)) ## Fig also has size, but the format is different. - size_str = sprintf ("size %.15g %.15g", gnuplot_size(1), gnuplot_size(2)); + size_str = sprintf ("size %.15g %.15g", gnuplot_size); elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) ## The size for corel and hpgl are goes at the end (implicit). - size_str = sprintf ("%.15g %.15g",gnuplot_size(1), gnuplot_size(2)); + size_str = sprintf ("%.15g %.15g", gnuplot_size); elseif (any (strncmpi (term, {"dxf"}, 3))) ## DXF uses autocad units. size_str = ""; @@ -334,93 +354,3 @@ ret = any (strncmpi ({"emf", "gif", "jpeg", "pbm", "png", "svg"}, term, 3)); endfunction -function [fig_size, fig_pos] = get_figsize (h) - ## Determine the size of the figure in pixels. - position = get (h, "position"); - units = get (h, "units"); - t.inches = 1; - t.centimeters = 2.54; - t.pixels = get (0, "screenpixelsperinch"); - ## gnuplot treats pixels/points for the screen the same (?). - t.points = t.pixels; - screensize = get (0, "screensize")(3:4); - t.normalized = screensize / t.pixels; - fig_size = position(3:4) * (t.pixels / t.(units)); - fig_pos = position(1:2) * (t.pixels / t.(units)); - fig_pos(1) = max (min (fig_pos(1), screensize(1)), 10); - fig_pos(2) = max (min (fig_pos(2), screensize(2)), 10); - fig_size(1) = max (min (fig_size(1), screensize(1)), 10-fig_pos(1)); - fig_size(2) = max (min (fig_size(2), screensize(2)), 10-fig_pos(2)); -endfunction - -function papersize = get_papersize (h) - ## Returns the papersize in inches - ## FIXME - a listener should hanlde this. - persistent papertypes papersizes - if (isempty (papertypes)) - papertypes = {"usletter", "uslegal", ... - "a0", "a1", "a2", "a3", "a4", "a5", ... - "b0", "b1", "b2", "b3", "b4", "b5", ... - "arch-a", "arch-b", "arch-c", "arch-d", "arch-e", ... - "a", "b", "c", "d", "e", ... - "tabloid", "<custom>"}; - papersizes = [ 8.500, 11.000; - 8.500, 14.000; - 33.135, 46.847; - 23.404, 33.135; - 16.548, 23.404; - 11.694, 16.528; - 8.268, 11.693; - 5.847, 8.264; - 40.543, 57.366; - 28.683, 40.503; - 20.252, 28.683; - 14.342, 20.252; - 10.126, 14.342; - 7.171, 10.126; - 9.000, 12.000; - 12.000, 18.000; - 18.000, 24.000; - 24.000, 36.000; - 36.000, 48.000; - 8.500, 11.000; - 11.000, 17.000; - 17.000, 22.000; - 22.000, 34.000; - 34.000, 44.000; - 11.000, 17.000; - 8.500, 11.000]; - ## <custom> has a page size since we're not doing any checking here. - papersizes = round (1000 * papersizes); - endif - - paperunits = get (h, "paperunits"); - if (strcmpi (paperunits, "normalized")) - papertype = get (h, "papertype"); - n = find (strcmpi (papertypes, papertype)); - papersize = 0.001 * papersizes(n, :); - paperunits = "inches"; - else - t.points = 72; - t.centimeters = 2.54; - t.inches = 1.00; - ## FIXME -- this papersize/type administration should be done at a - ## lower level. - if (strcmpi (get (h, "papertype"), "<custom>")) - ## If the type is custom but the size is a standard, then set the - ## standard type. - papersize = get (h, "papersize"); - papersize = papersize * t.(paperunits); - n = find (all ((ones ([size(papersizes, 1), 1]) - * round (1000*papersize) - papersizes) == 0, 2)); - if (! isempty (n)) - set (h, "papertype", papertypes{n}); - endif - else - papertype = get (h, "papertype"); - n = find (strcmpi (papertypes, papertype)); - papersize = papersizes(n,:) * 0.001; - set (h, "papersize", papersize * t.(paperunits)); - endif - endif -endfunction
--- a/scripts/plot/print.m +++ b/scripts/plot/print.m @@ -18,12 +18,14 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} print (@var{filename}, @var{options}) +## @deftypefn {Function File} {} print () +## @deftypefnx {Function File} {} print (@var{options}) +## @deftypefnx {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. +## filename is specified, the 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. @@ -44,7 +46,7 @@ ## Solid or dashed lines. ## @item -portrait ## @itemx -landscape -## Plot orientation, as returned by "orient". +## Specify the orientation of the plot for printed output. ## @item -d@var{device} ## Output device, where @var{device} is one of: ## @table @code @@ -130,9 +132,10 @@ ## For a complete list, type `system ("gs -h")' to see what formats ## and devices are available. ## -## For output sent to a printer, the size is determined by the -## figure's "papersize" property. For output to a file the, size -## is determined by the "paperposition" property. +## When the ghostscript is sent to a printer the size is determined +## by the figure's "papersize" property. When the ghostscript output +## is sent to a file the size is determined by the figure's +## "paperposition" property. ## ## @itemx -r@var{NUM} ## Resolution of bitmaps in pixels per inch. For both metafiles and @@ -169,7 +172,8 @@ function print (varargin) - orientation = orient (); + persistent warn_on_inconsistent_orientation = true + orientation = ""; use_color = 0; # 0=default, -1=mono, +1=color force_solid = 0; # 0=default, -1=dashed, +1=solid fontsize = ""; @@ -314,8 +318,15 @@ if (! any (strcmp (dev, dev_list)) && have_ghostscript) ghostscript_output = name; ghostscript_device = dev; - dev = "epsc"; - name = cstrcat (tmpnam, ".eps"); + if (doprint) + ## If printing, use color postscript. + dev = "psc"; + name = cstrcat (tmpnam, ".ps"); + else + ## If saving to a file, use color encapsulated postscript. + dev = "epsc"; + name = cstrcat (tmpnam, ".eps"); + endif else ghostscript_output = ""; endif @@ -344,7 +355,7 @@ if (dev(1) == "e") options = "eps "; else - options = cstrcat (orientation, " "); + options = ""; endif termn = "postscript"; endif @@ -426,7 +437,6 @@ if (isempty (canvas_size) && isempty (resolution) && any (strcmp (dev, {"pbm", "gif", "jpeg", "png"}))) - ##options = "large"; options = ""; elseif (strcmp (dev, "svg")) ## Referring to size, either "dynamic" or "fixed" @@ -503,19 +513,51 @@ endif name = cstrcat (tmpnam, ".ps"); termn = "postscript"; - options = cstrcat (options, " portrait"); ## All "options" for pdf work for postscript as well. else error ("print: the device, \"%s\", is not available.", dev) endif endif + is_eps_file = strncmp (dev, "eps", 3); + p.units = get (gcf, "units"); + p.paperunits = get (gcf, "paperunits"); + p.papersize = get (gcf, "papersize"); + p.paperposition = get (gcf, "paperposition"); + p.paperpositionmode = get (gcf, "paperpositionmode"); + p.paperorientation = get (gcf, "paperorientation"); + if (p.papersize(1) > p.papersize(2)) + paperorientation = "landscape"; + else + paperorientation = "portrait"; + endif + if (! strcmp (paperorientation, get (gcf, "paperorientation")) + && warn_on_inconsistent_orientation) + msg = {"print.m - inconsistent papersize and paperorientation properties.\n", + sprintf(" papersize = %.2f, %.2f\n", p.papersize), + sprintf(" paperorientation = \"%s\"\n", p.paperorientation), + " the paperorientation property has been ignored"}; + warning ("%s",msg{:}) + warn_on_inconsistent_orientation = false; + endif + + if (strcmp (termn, "postscript") && ! strncmp (dev, "eps", 3)) + if (isempty (orientation)) + orientation = paperorientation; + endif + ## This is done here to accommodate ghostscript conversion. + options = cstrcat (orientation, " ", options); + end + new_terminal = cstrcat (termn, " ", options); - mono = use_color < 0; + mono = (use_color < 0); + + terminals_for_prn = {"postscript", "pdf", "pdfcairo"}; + output_for_printer = any (strncmp (termn, terminals_for_prn, numel(termn))); if (isempty (resolution)) - if (any (strcmp (dev, {"emf", "svg"}))) + if (any (strcmp (dev, {"emf", "svg"})) || output_for_printer) resolution = get (0, "screenpixelsperinch"); else resolution = 150; @@ -533,21 +575,13 @@ set (gcf, "__pixels_per_inch__", resolution) unwind_protect - paper_position_mode = get (gcf, "paperpositionmode"); - terminals_for_prn = {"postscript", "pdf", "pdfcairo"}; - restore_properties = false; - is_eps_file = strncmp (dev, "eps", 3); - output_for_printer = any (strncmp (termn, terminals_for_prn, numel(termn))); + set (gcf, "paperunits", "inches"); + set (gcf, "units", "pixels"); + restore_properties = true; if ((! output_for_printer || is_eps_file) && ! doprint) ## If not PDF or PostScript, and the result is not being sent to a printer, ## render an image the size of the paperposition box. - restore_properties = true; - p.paperunits = get (gcf, "paperunits"); - p.papertype = get (gcf, "papertype"); - p.papersize = get (gcf, "papersize"); - p.paperposition = get (gcf, "paperposition"); - p.paperpositionmode = get (gcf, "paperpositionmode"); - set (gcf, "paperunits", "inches"); + ## Trigger the listener to convert all paper props to inches. if (! isempty (canvas_size)) size_in_pixels = sscanf (canvas_size ,"%d, %d"); size_in_pixels = reshape (size_in_pixels, [1, numel(size_in_pixels)]); @@ -558,10 +592,26 @@ paperposition_in_inches(1:2) = 0; papersize_in_inches = paperposition_in_inches(3:4); endif - set (gcf, "papertype", "<custom>"); set (gcf, "papersize", papersize_in_inches); set (gcf, "paperposition", paperposition_in_inches); set (gcf, "paperpositionmode", "manual"); + else + if (strcmp (p.paperpositionmode, "auto")) + size_in_pixels = get (gcf, "position")(3:4); + paperposition_in_inches(3:4) = size_in_pixels ./ resolution; + paperposition_in_inches(1:2) = (p.papersize - paperposition_in_inches(3:4))/2; + else + paperposition_in_inches = p.paperposition; + endif + if (! isempty (orientation) && ! strcmp (orientation, paperorientation)) + ## When -landscape/portrait changes the orientation, flip both the + ## papersize and paperposition. + restore_properties = true; + set (gcf, "papersize", p.papersize([2, 1])); + set (gcf, "paperposition", paperposition_in_inches([2, 1, 4, 3])); + else + set (gcf, "paperposition", paperposition_in_inches); + endif endif if (use_color < 0) [objs_with_color, color_of_objs] = convert_color2mono (gcf);