diff scripts/plot/util/print.m @ 27007:dd31206c87c0

Fix scaling of fonts when printing with -Sxsz,ysz option (bug #55907). * print.m: Declare intermediate variables do_font (true when changing fontname), do_scalefontsize (true when -S option present and scaling fonts), and do_fontsize (true when -F option to scale fontsize is present). Use intermediate variable to improve readability of code. When scaling fontsize, rather than setting fontsize to single value, use for loop over text objects to scale and set new fontsize. * __print_parse_opts__.m: Initialize arg_st.fontsize to '[]'. When -S option given, check for -r option and issue a warning if present. Use a new scale factor formula that produces results close to those on screen (WYSIWYG).
author Rik <rik@octave.org>
date Fri, 29 Mar 2019 21:01:43 -0700
parents 734901c8979e
children 986128cf1e07
line wrap: on
line diff
--- a/scripts/plot/util/print.m	Fri Mar 29 15:56:34 2019 -0400
+++ b/scripts/plot/util/print.m	Fri Mar 29 21:01:43 2019 -0700
@@ -615,44 +615,65 @@
       endfor
     endif
 
-    if (! isempty (opts.font) || ! isempty (opts.fontsize))
+    do_font = ! isempty (opts.font);
+    do_scalefontsize =  ! isempty (opts.scalefontsize) && opts.scalefontsize != 1;
+    do_fontsize = ! isempty (opts.fontsize) || do_scalefontsize;
+    if (do_font || do_fontsize)
       h = findall (opts.figure, "-property", "fontname");
       m = numel (props);
       for n = 1:numel (h)
         if (ishghandle (h(n)))
-          if (! isempty (opts.font))
+          if (do_font)
             props(end+1).h = h(n);
             props(end).name = "fontname";
             props(end).value = {get(h(n), "fontname")};
           endif
-        endif
-        if (ishghandle (h(n)))
-          if (! isempty (opts.fontsize))
+          if (do_fontsize)
             props(end+1).h = h(n);
             props(end).name = "fontsize";
             props(end).value = {get(h(n), "fontsize")};
           endif
         endif
       endfor
-      if (! isempty (opts.font))
+      if (do_font)
         set (h(ishghandle (h)), "fontname", opts.font);
       endif
-      if (! isempty (opts.fontsize))
-        if (ischar (opts.fontsize))
-          fontsize = str2double (opts.fontsize);
+      if (do_fontsize)
+        if (! isempty (opts.fontsize))
+          ## Changing all fontsizes to a fixed value
+          if (ischar (opts.fontsize))
+            fontsize = str2double (opts.fontsize);
+          else
+            fontsize = opts.fontsize;
+          endif
+          if (do_scalefontsize)
+            ## This is done to work around the bbox being whole numbers.
+            fontsize *= opts.scalefontsize;
+          endif
+
+          ## FIXME: legend child objects need to be acted on first.
+          ##        or legend fontsize callback will destroy them.
+          hlist = h(ishghandle (h));
+          haxes = strcmp (get (hlist, "type"), "axes");
+          set (hlist(! haxes), "fontsize", fontsize);
+          set (hlist(haxes), "fontsize", fontsize);
+
         else
-          fontsize = opts.fontsize;
+          ## Scaling fonts
+          ## FIXME: legend child objects need to be acted on first.
+          ##        or legend fontsize callback will destroy them.
+          hlist = h(ishghandle (h));
+          haxes = strcmp (get (hlist, "type"), "axes");
+          for h = hlist(! haxes).'
+            fontsz = get (h, "fontsize");
+            set (h, "fontsize", fontsz * opts.scalefontsize);
+          endfor
+          for h = hlist(haxes).'
+            fontsz = get (h, "fontsize");
+            set (h, "fontsize", fontsz * opts.scalefontsize);
+          endfor
+
         endif
-        if (! isempty (opts.scalefontsize) && ! opts.scalefontsize != 1)
-          ## This is done to work around the bbox being whole numbers.
-          fontsize *= opts.scalefontsize;
-        endif
-        ## FIXME: legend child objects need to be acted on first.
-        ##        or legend fontsize callback will destroy them.
-        hlist = h(ishghandle (h));
-        haxes = strcmp (get (hlist, "type"), "axes");
-        set (hlist(! haxes), "fontsize", fontsize);
-        set (hlist(haxes), "fontsize", fontsize);
       endif
     endif