changeset 21323:030d4d6c2b58

Implement figure property "InvertHardCopy" for printing (bug #47230). * graphics.in.h: Change default value of "InvertHardCopy" to "on" to match Matlab. * print.m: Change figure background and top-level axes background colors to white when printing and InvertHardCopy is "on". Restore original colors after print.
author Rik <rik@octave.org>
date Tue, 23 Feb 2016 14:11:34 -0800
parents 909129eb77c5
children 5169d5993d77
files libinterp/corefcn/graphics.in.h scripts/plot/util/print.m
diffstat 2 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.in.h	Tue Feb 23 15:05:45 2016 -0500
+++ b/libinterp/corefcn/graphics.in.h	Tue Feb 23 14:11:34 2016 -0800
@@ -3395,7 +3395,7 @@
       string_property filename , ""
       bool_property graphicssmoothing , "on"
       bool_property integerhandle S , "on"
-      bool_property inverthardcopy , "off"
+      bool_property inverthardcopy , "on"
       callback_property keypressfcn , Matrix ()
       callback_property keyreleasefcn , Matrix ()
       radio_property menubar , "none|{figure}"
--- a/scripts/plot/util/print.m	Tue Feb 23 15:05:45 2016 -0500
+++ b/scripts/plot/util/print.m	Tue Feb 23 14:11:34 2016 -0800
@@ -350,7 +350,7 @@
       props(n).h = hobj(n);
       props(n).name = "units";
       props(n).value = {get(hobj(n), "units")};
-      set (hobj(n), "units", "data")
+      set (hobj(n), "units", "data");
     endfor
 
     ## print() requires axes units = "normalized"
@@ -361,7 +361,7 @@
       props(m+n).h = hax(n);
       props(m+n).name = "units";
       props(m+n).value = {get(hax(n), "units")};
-      set (hax(n), "units", "normalized")
+      set (hax(n), "units", "normalized");
     endfor
 
     ## print() requires figure units to be "pixels"
@@ -379,14 +379,33 @@
     fpos(3:4) = opts.canvas_size;
     set (opts.figure, "position", fpos);
 
-    ## Set figure background to none.
-    ## This is done both for consistency with Matlab and to eliminate
-    ## the visible box along the figure's perimeter.
-    props(m+3).h = opts.figure;
-    props(m+3).name = "color";
-    props(m+3).value{1} = get (props(m+3).h, props(m+3).name);
-    set (props(m+3).h, "color", "none");
-    nfig = m + 3;
+    ## Implement InvertHardCopy option
+    do_hardcopy = strcmp (get (opts.figure, "inverthardcopy"), "on");
+
+    if (do_hardcopy)
+      ## Set figure background to white.
+      props(m+3).h = opts.figure;
+      props(m+3).name = "color";
+      props(m+3).value{1} = get (props(m+3).h, props(m+3).name);
+      set (props(m+3).h, "color", "white");
+      nfig = m + 3;
+    else
+      nfig = m + 2;
+    endif
+
+    if (do_hardcopy)
+      ## Set background to white for all top-level axes objects
+      hax = findall (opts.figure, "-depth", 1, "type", "axes",
+                                  "-not", "tag", "legend");
+      m = numel (props);
+      for n = 1:numel(hax)
+        props(m+n).h = hax(n);
+        props(m+n).name = "color";
+        props(m+n).value{1} = get(hax(n), "color");
+        set (hax(n), "color", "white");
+      endfor
+      nfig += n;
+    endif
 
     if (opts.force_solid != 0)
       h = findall (opts.figure, "-property", "linestyle");