# HG changeset patch # User Ben Abbott # Date 1238454412 14400 # Node ID 6a495ba41f75db2f134729fbcf07675365c0801d # Parent f89864234b5d2a590453d3855dffa37141e77e2b __gnuplot_default_font__.m: New function: determine gnuplot's terminal dependent default font. diff -r f89864234b5d -r 6a495ba41f75 scripts/ChangeLog --- a/scripts/ChangeLog Sun Mar 29 22:18:21 2009 -0700 +++ b/scripts/ChangeLog Mon Mar 30 19:06:52 2009 -0400 @@ -1,3 +1,10 @@ +2009-03-30 Ben Abbott + + * plot/__gnuplot_default_font__.m: New function: determine gnuplot's + terminal dependent default font. + * plot/__go_draw_figure__.m: Substitute gnuplot default font when + "fontname" = "*". + 2009-03-29 John W. Eaton * testfun/Makefile.in (SOURCES): Add rundemos.m to the list. diff -r f89864234b5d -r 6a495ba41f75 scripts/plot/Makefile.in --- a/scripts/plot/Makefile.in Sun Mar 29 22:18:21 2009 -0700 +++ b/scripts/plot/Makefile.in Mon Mar 30 19:06:52 2009 -0400 @@ -47,6 +47,7 @@ __errcomm__.m \ __errplot__.m \ __ezplot__.m \ + __gnuplot_default_font__.m \ __gnuplot_get_var__.m \ __gnuplot_has_feature__.m \ __go_close_all__.m \ diff -r f89864234b5d -r 6a495ba41f75 scripts/plot/__gnuplot_default_font__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/__gnuplot_default_font__.m Mon Mar 30 19:06:52 2009 -0400 @@ -0,0 +1,86 @@ +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{fontname}, @var{fontsize}] =} __gnuplot_default_font__ (@var{h}, @var{term}) +## Undocumented internal function. +## @end deftypefn + +## Author: Ben Abbott +## 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 + diff -r f89864234b5d -r 6a495ba41f75 scripts/plot/__go_draw_figure__.m --- a/scripts/plot/__go_draw_figure__.m Sun Mar 29 22:18:21 2009 -0700 +++ b/scripts/plot/__go_draw_figure__.m Mon Mar 30 19:06:52 2009 -0400 @@ -37,9 +37,7 @@ htype = get (h, "type"); if (strcmp (htype, "figure")) - ## Set figure properties here? - - ## For output, determine the normalized paperposition. + ## When printing, determine the paperposition in inches. if (output_to_paper) orig_paper_units = get (h, "paperunits"); unwind_protect @@ -55,50 +53,60 @@ implicit_margin = implicit_margin * [1 1]; endif - ## Get complete list of children. - kids = allchild (h); - nkids = length (kids); - - if (nkids > 0) + ## 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); - 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"); + ## Get complete list of children. + kids = allchild (h); + nkids = length (kids); - 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 + 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 else error ("__go_draw_figure__: expecting figure object, found `%s'", htype);