Mercurial > octave-nkf
comparison scripts/plot/__go_draw_figure__.m @ 8889:665b264b6a50
Compatible support of figure paper properties and resolution for the gnuplot backend.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 28 Feb 2009 19:36:09 -0500 |
parents | 7d48766c21a5 |
children | eb63fbe60fab |
comparison
equal
deleted
inserted
replaced
8888:0c7b0049c023 | 8889:665b264b6a50 |
---|---|
21 ## Undocumented internal function. | 21 ## Undocumented internal function. |
22 ## @end deftypefn | 22 ## @end deftypefn |
23 | 23 |
24 ## Author: jwe | 24 ## Author: jwe |
25 | 25 |
26 function __go_draw_figure__ (h, plot_stream, enhanced, mono) | 26 function __go_draw_figure__ (h, plot_stream, enhanced, mono, output_to_paper, implicit_margin) |
27 | 27 |
28 if (nargin == 4) | 28 if (nargin < 5) |
29 output_to_paper = false; | |
30 elseif (nargin < 6) | |
31 ## Gnuplot has implicit margins for some output. For example, for postscript | |
32 ## the margin is 50pts. If not specified asssume 0. | |
33 implicit_margin = 0; | |
34 endif | |
35 | |
36 if (nargin >= 4 && nargin <= 6) | |
29 htype = get (h, "type"); | 37 htype = get (h, "type"); |
30 if (strcmp (htype, "figure")) | 38 if (strcmp (htype, "figure")) |
31 | 39 |
32 ## Set figure properties here? | 40 ## Set figure properties here? |
41 | |
42 ## For output, determine the normalized paperposition. | |
43 if (output_to_paper) | |
44 orig_paper_units = get (h, "paperunits"); | |
45 unwind_protect | |
46 set (h, "paperunits", "inches"); | |
47 paper_size = get (h, "papersize"); | |
48 paper_position = get (h, "paperposition"); | |
49 paper_position = paper_position ./ paper_size([1, 2, 1, 2]); | |
50 implicit_margin = implicit_margin ./ paper_size([1, 2]); | |
51 unwind_protect_cleanup | |
52 set (h, "paperunits", orig_paper_units); | |
53 end_unwind_protect | |
54 else | |
55 implicit_margin = implicit_margin * [1 1]; | |
56 endif | |
33 | 57 |
34 ## Get complete list of children. | 58 ## Get complete list of children. |
35 kids = allchild (h); | 59 kids = allchild (h); |
36 nkids = length (kids); | 60 nkids = length (kids); |
37 | 61 |
38 if (nkids > 0) | 62 if (nkids > 0) |
39 axes_count = 0; | |
40 for i = 1:nkids | |
41 obj = __get__ (kids(i)); | |
42 switch (obj.type) | |
43 case "axes" | |
44 axes_count++; | |
45 endswitch | |
46 endfor | |
47 | 63 |
48 fputs (plot_stream, "\nreset;\n"); | 64 fputs (plot_stream, "\nreset;\n"); |
49 fputs (plot_stream, "set autoscale fix;\n"); | 65 fputs (plot_stream, "set autoscale fix;\n"); |
50 fputs (plot_stream, "set multiplot;\n"); | 66 fputs (plot_stream, "set multiplot;\n"); |
51 fputs (plot_stream, "set origin 0, 0\n"); | 67 fputs (plot_stream, "set origin 0, 0\n"); |
52 fputs (plot_stream, "set size 1, 1\n"); | 68 fputs (plot_stream, "set size 1, 1\n"); |
53 | 69 |
54 for i = 1:nkids | 70 for i = 1:nkids |
55 obj = get (kids(i)); | 71 type = get (kids(i), "type"); |
56 switch (obj.type) | 72 switch (type) |
57 case "axes" | 73 case "axes" |
58 __go_draw_axes__ (kids (i), plot_stream, enhanced, mono); | 74 ## Rely upon listener to convert axes position to "normalized" units. |
75 orig_axes_units = get (kids(i), "units"); | |
76 orig_axes_position = get (kids(i), "position"); | |
77 unwind_protect | |
78 set (kids(i), "units", "normalized"); | |
79 if (output_to_paper) | |
80 axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]); | |
81 axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2); | |
82 set (kids(i), "position", axes_position_on_page); | |
83 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); | |
84 else | |
85 ## Return axes "units" and "position" back to their original values. | |
86 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); | |
87 endif | |
88 unwind_protect_cleanup | |
89 set (kids(i), "units", orig_axes_units); | |
90 set (kids(i), "position", orig_axes_position); | |
91 end_unwind_protect | |
59 otherwise | 92 otherwise |
60 error ("__go_draw_figure__: unknown object class, %s", | 93 error ("__go_draw_figure__: unknown object class, %s", type); |
61 obj.type); | |
62 endswitch | 94 endswitch |
63 endfor | 95 endfor |
64 | 96 |
65 fputs (plot_stream, "unset multiplot;\n"); | 97 fputs (plot_stream, "unset multiplot;\n"); |
66 else | 98 else |