Mercurial > octave-nkf
annotate scripts/plot/__go_draw_figure__.m @ 9062:6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 30 Mar 2009 19:06:52 -0400 |
parents | eb63fbe60fab |
children | 5ecdb3d3568f |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2005, 2007, 2008, 2009 John W. Eaton |
6405 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6405 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6405 | 18 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8249
diff
changeset
|
19 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8249
diff
changeset
|
20 ## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono}) |
6895 | 21 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8249
diff
changeset
|
22 ## @end deftypefn |
6405 | 23 |
24 ## Author: jwe | |
25 | |
8889
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
26 function __go_draw_figure__ (h, plot_stream, enhanced, mono, output_to_paper, implicit_margin) |
6405 | 27 |
8889
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
28 if (nargin < 5) |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
29 output_to_paper = false; |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
30 elseif (nargin < 6) |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
31 ## Gnuplot has implicit margins for some output. For example, for postscript |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
32 ## the margin is 50pts. If not specified asssume 0. |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
33 implicit_margin = 0; |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
34 endif |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
35 |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
36 if (nargin >= 4 && nargin <= 6) |
8249 | 37 htype = get (h, "type"); |
38 if (strcmp (htype, "figure")) | |
6405 | 39 |
9062
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
40 ## When printing, determine the paperposition in inches. |
8889
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
41 if (output_to_paper) |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
42 orig_paper_units = get (h, "paperunits"); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
43 unwind_protect |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
44 set (h, "paperunits", "inches"); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
45 paper_size = get (h, "papersize"); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
46 paper_position = get (h, "paperposition"); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
47 paper_position = paper_position ./ paper_size([1, 2, 1, 2]); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
48 implicit_margin = implicit_margin ./ paper_size([1, 2]); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
49 unwind_protect_cleanup |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
50 set (h, "paperunits", orig_paper_units); |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
51 end_unwind_protect |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
52 else |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
53 implicit_margin = implicit_margin * [1 1]; |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
54 endif |
665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents:
8812
diff
changeset
|
55 |
9062
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
56 ## Substitute the gnuplot default font for objects with fontname == "*" |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
57 show_hidden_handles = get (0, "showhiddenhandles"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
58 default_font_name = __gnuplot_default_font__ (h); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
59 term = __gnuplot_get_var__ (h, "GPVAL_TERM"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
60 unwind_protect |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
61 set (0, "showhiddenhandles", "on"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
62 h_default_font_name = findobj (h, "fontname", "*"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
63 set (h_default_font_name, "fontname", default_font_name); |
6405 | 64 |
9062
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
65 ## Get complete list of children. |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
66 kids = allchild (h); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
67 nkids = length (kids); |
6405 | 68 |
9062
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
69 if (nkids > 0) |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
70 fputs (plot_stream, "\nreset;\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
71 fputs (plot_stream, "set autoscale fix;\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
72 fputs (plot_stream, "set multiplot;\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
73 fputs (plot_stream, "set origin 0, 0\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
74 fputs (plot_stream, "set size 1, 1\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
75 for i = 1:nkids |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
76 type = get (kids(i), "type"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
77 switch (type) |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
78 case "axes" |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
79 ## Rely upon listener to convert axes position to "normalized" units. |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
80 orig_axes_units = get (kids(i), "units"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
81 orig_axes_position = get (kids(i), "position"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
82 unwind_protect |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
83 set (kids(i), "units", "normalized"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
84 if (output_to_paper) |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
85 axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
86 axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
87 set (kids(i), "position", axes_position_on_page); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
88 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
89 else |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
90 ## Return axes "units" and "position" back to their original values. |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
91 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
92 endif |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
93 unwind_protect_cleanup |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
94 set (kids(i), "units", orig_axes_units); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
95 set (kids(i), "position", orig_axes_position); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
96 end_unwind_protect |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
97 otherwise |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
98 error ("__go_draw_figure__: unknown object class, %s", type); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
99 endswitch |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
100 endfor |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
101 fputs (plot_stream, "unset multiplot;\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
102 else |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
103 fputs (plot_stream, "\nreset; clear;\n"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
104 fflush (plot_stream); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
105 endif |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
106 unwind_protect_cleanup |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
107 set (h_default_font_name, "fontname", "*"); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
108 set (0, "showhiddenhandles", show_hidden_handles); |
6a495ba41f75
__gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
109 end_unwind_protect |
6405 | 110 else |
111 error ("__go_draw_figure__: expecting figure object, found `%s'", | |
8249 | 112 htype); |
6405 | 113 endif |
114 else | |
115 print_usage (); | |
116 endif | |
117 | |
118 endfunction | |
119 |