Mercurial > hg > octave-terminal
changeset 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 | f89864234b5d |
children | a6cf0ad87eee |
files | scripts/ChangeLog scripts/plot/Makefile.in scripts/plot/__gnuplot_default_font__.m scripts/plot/__go_draw_figure__.m |
diffstat | 4 files changed, 147 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2009-03-30 Ben Abbott <bpabbott@mac.com> + + * 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 <jwe@octave.org> * testfun/Makefile.in (SOURCES): Add rundemos.m to the list.
--- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -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 \
new file mode 100644 --- /dev/null +++ b/scripts/plot/__gnuplot_default_font__.m @@ -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 +## <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_figure__.m +++ b/scripts/plot/__go_draw_figure__.m @@ -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);