Mercurial > hg > octave-lyh
changeset 9098:5ecdb3d3568f
Allow fontsize to be specified for all objects with fontname == "*".
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 06 Apr 2009 18:57:42 -0400 |
parents | 705c24e3db58 |
children | 3a5d41b382ab |
files | scripts/ChangeLog scripts/plot/__gnuplot_default_font__.m scripts/plot/__go_draw_axes__.m scripts/plot/__go_draw_figure__.m |
diffstat | 4 files changed, 55 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2009-04-06 Ben Abbott <bpabbott@mac.com> + + * plot/__gnuplot_default_font__.m: Remove file from archive. + * plot/__go_draw_axes__.m, plot/__go_draw_figure__.m: Allow + fontsize to be specified for all terminals with fontname == "*". + 2009-04-06 Jaroslav Hajek <highegg@gmail.com> * polynomial/polyscale.m: New function.
deleted file mode 100644 --- a/scripts/plot/__gnuplot_default_font__.m +++ /dev/null @@ -1,86 +0,0 @@ -## Copyright (C) 2009 Ben Abbott -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{fontname}, @var{fontsize}] =} __gnuplot_default_font__ (@var{h}, @var{term}) -## Undocumented internal function. -## @end deftypefn - -## Author: Ben Abbott <bpabbott@bens-macbook.local> -## Created: 2009-03-16 - -function varargout = __gnuplot_default_font__ (h) - - if (nargin == 0) - h = gcf (); - endif - - plot_stream = get (h, "__plot_stream__"); - - term = __gnuplot_get_var__ (h, "GPVAL_TERM"); - term_options = __gnuplot_get_var__ (h, "GPVAL_TERMOPTIONS"); - words = regexp (term_options, '(\b[^\s]+\b|"[^"]+"|''[^'']+'')', "matches"); - - n = find (strcmp (words, "fname") | strcmp (words, "font"), 1); - if (! isempty (n)) - font_name = words{n+1}; - if (font_name(1)=="\"" || font_name(1)=="'") - font_name = font_name(2:(end-1)); - endif - m = find (strcmp (words, "fontsize") | strcmp (words, "fsize"), 1); - if (! isempty (m)) - font_size = sscanf (words{m+1}, "%d"); - elseif (! isempty (strfind (font_name, ","))) - k = strfind (font_name, ",")(1); - font_size = sscanf (font_name((k+1):end), "%d"); - font_name = font_name(1:(k-1)); - else - font_size = 12; - endif - elseif (numel (words) > 1 && (words{end-1}(1)=="\"" || words{end-1}(1)=="'")) - font_name = words{end-1}(2:(end-1)); - font_size = sscanf (words{end}, "%d"); - elseif (strcmp (term, {"epslatex"})) - font_name = "*"; - font_size = sscanf (words{end}, "%d"); - else - font_name = "*"; - font_size = 12; - endif - varargout = {font_name, font_size, words}; - -endfunction - -%!demo -%! figure(1) -%! drawnow -%! terms = {"aqua", "corel", "dxf", "emf", "epslatex", "fig", "gif", ... -%! "hpgl", "jpeg", "mf", "pbm", "pdf", "png", "postscript", ... -%! "pslatex", "pstex", "svg", "tex", "wxt", "x11"}; -%! plot_stream = get (gcf, "__plot_stream__"); -%! orig_term = __gnuplot_get_var__ (gcf, "GPVAL_TERM"); -%! unwind_protect -%! for n = 1:numel(terms) -%! status = fprintf (plot_stream(1), "\nset term %s;\n", terms{n}); -%! fflush (plot_stream(1)); -%! [fname, fsize, term_opts] = __gnuplot_default_font__(gcf); -%! fprintf ("%10s: font name = '%s', font size = %d\n", terms{n}, fname, fsize) -%! endfor -%! unwind_protect_cleanup -%! status = fprintf (plot_stream(1), "\nset term %s;\n", orig_term); -%! fflush (plot_stream(1)); -%! end_unwind_protect -
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -36,7 +36,6 @@ end_unwind_protect parent_figure_obj = get (axis_obj.parent); - term = __gnuplot_get_var__ (axis_obj.parent, "GPVAL_TERM"); ## Set to false for plotyy axes. if (strcmp (axis_obj.tag, "plotyy")) @@ -96,7 +95,7 @@ fputs (plot_stream, "unset title;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, term); + fontspec = create_fontspec (f, s); fprintf (plot_stream, "set title \"%s\" %s %s", undo_string_escapes (tt), fontspec, __do_enhanced_option__ (enhanced, t)); @@ -117,7 +116,7 @@ fprintf (plot_stream, "unset x2label;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, term); + fontspec = create_fontspec (f, s); if (strcmpi (axis_obj.xaxislocation, "top")) fprintf (plot_stream, "set x2label \"%s\" %s %s %s", undo_string_escapes (tt), colorspec, fontspec, @@ -145,7 +144,7 @@ fprintf (plot_stream, "unset y2label;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, term); + fontspec = create_fontspec (f, s); if (strcmpi (axis_obj.yaxislocation, "right")) fprintf (plot_stream, "set y2label \"%s\" %s %s %s", undo_string_escapes (tt), colorspec, fontspec, @@ -172,7 +171,7 @@ fputs (plot_stream, "unset zlabel;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string"); - fontspec = create_fontspec (f, s, term); + fontspec = create_fontspec (f, s); fprintf (plot_stream, "set zlabel \"%s\" %s %s %s", undo_string_escapes (tt), colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); @@ -941,7 +940,7 @@ case "text" [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string"); - fontspec = create_fontspec (f, s, term); + fontspec = create_fontspec (f, s); lpos = obj.position; halign = obj.horizontalalignment; angle = obj.rotation; @@ -1233,16 +1232,11 @@ endfunction -function fontspec = create_fontspec (f, s, term) - if (nargin > 3 || any (strcmp (term, {"x11", "wxt"}))) - include_size_with_anonymous_fontname = true; +function fontspec = create_fontspec (f, s) + if (strcmp (f, "*")) + fontspec = sprintf ("font \",%d\"", s); else - include_size_with_anonymous_fontname = false; - endif - if (! strcmp (f, "*") || include_size_with_anonymous_fontname) fontspec = sprintf ("font \"%s,%d\"", f, s); - else - fontspec = ""; endif endfunction @@ -1438,8 +1432,7 @@ obj.zticklabel = ticklabel_to_cell (obj.zticklabel); [fontname, fontsize] = get_fontname_and_size (obj); - term = __gnuplot_get_var__ (obj.parent, "GPVAL_TERM"); - fontspec = create_fontspec (fontname, fontsize, term); + fontspec = create_fontspec (fontname, fontsize); ## A Gnuplot tic scale of 69 is equivalent to Octave's 0.5. ticklength = sprintf ("scale %4.1f", (69/0.5)*obj.ticklength(1));
--- a/scripts/plot/__go_draw_figure__.m +++ b/scripts/plot/__go_draw_figure__.m @@ -53,60 +53,47 @@ implicit_margin = implicit_margin * [1 1]; endif - ## Substitute the gnuplot default font for objects with fontname == "*" - show_hidden_handles = get (0, "showhiddenhandles"); - default_font_name = __gnuplot_default_font__ (h); - term = __gnuplot_get_var__ (h, "GPVAL_TERM"); - unwind_protect - set (0, "showhiddenhandles", "on"); - h_default_font_name = findobj (h, "fontname", "*"); - set (h_default_font_name, "fontname", default_font_name); - - ## Get complete list of children. - kids = allchild (h); - nkids = length (kids); + ## Get complete list of children. + kids = allchild (h); + nkids = length (kids); - if (nkids > 0) - fputs (plot_stream, "\nreset;\n"); - fputs (plot_stream, "set autoscale fix;\n"); - fputs (plot_stream, "set multiplot;\n"); - fputs (plot_stream, "set origin 0, 0\n"); - fputs (plot_stream, "set size 1, 1\n"); - for i = 1:nkids - type = get (kids(i), "type"); - switch (type) - case "axes" - ## Rely upon listener to convert axes position to "normalized" units. - orig_axes_units = get (kids(i), "units"); - orig_axes_position = get (kids(i), "position"); - unwind_protect - set (kids(i), "units", "normalized"); - if (output_to_paper) - axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]); - axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2); - set (kids(i), "position", axes_position_on_page); - __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); - else - ## Return axes "units" and "position" back to their original values. - __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); - endif - unwind_protect_cleanup - set (kids(i), "units", orig_axes_units); - set (kids(i), "position", orig_axes_position); - end_unwind_protect - otherwise - error ("__go_draw_figure__: unknown object class, %s", type); - endswitch - endfor - fputs (plot_stream, "unset multiplot;\n"); - else - fputs (plot_stream, "\nreset; clear;\n"); - fflush (plot_stream); - endif - unwind_protect_cleanup - set (h_default_font_name, "fontname", "*"); - set (0, "showhiddenhandles", show_hidden_handles); - end_unwind_protect + if (nkids > 0) + fputs (plot_stream, "\nreset;\n"); + fputs (plot_stream, "set autoscale fix;\n"); + fputs (plot_stream, "set multiplot;\n"); + fputs (plot_stream, "set origin 0, 0\n"); + fputs (plot_stream, "set size 1, 1\n"); + for i = 1:nkids + type = get (kids(i), "type"); + switch (type) + case "axes" + ## Rely upon listener to convert axes position to "normalized" units. + orig_axes_units = get (kids(i), "units"); + orig_axes_position = get (kids(i), "position"); + unwind_protect + set (kids(i), "units", "normalized"); + if (output_to_paper) + axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]); + axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2); + set (kids(i), "position", axes_position_on_page); + __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); + else + ## Return axes "units" and "position" back to their original values. + __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin); + endif + unwind_protect_cleanup + set (kids(i), "units", orig_axes_units); + set (kids(i), "position", orig_axes_position); + end_unwind_protect + otherwise + error ("__go_draw_figure__: unknown object class, %s", type); + endswitch + endfor + fputs (plot_stream, "unset multiplot;\n"); + else + fputs (plot_stream, "\nreset; clear;\n"); + fflush (plot_stream); + endif else error ("__go_draw_figure__: expecting figure object, found `%s'", htype);