# HG changeset patch
# User Ben Abbott <bpabbott@mac.com>
# Date 1450981435 18000
#      Thu Dec 24 13:23:55 2015 -0500
# Node ID f51a46ee4c6ede3690e167466edc65af4a916b49
# Parent  0963ed3890122e4ced86b8cc44102007121bd02b
Rely upon print.m for mono/color conversion. This simplifies gnuplot support
and reduced complexity since all toolkits rely upon the same color/mono code.
maintenance (from bug #44187).

* scripts/plot/util/print.m: Handle color to gray scale conervsion for all
toolkits.
* scripts/plot/util/__gnuplot_drawnow__.m: Remove option for "mono".
* scripts/plot/util/private/__gnuplot_draw_figure__.m: ditto.
* scripts/plot/util/private/__gnuplot_draw_axes__.m: ditto.

diff --git a/scripts/plot/util/__gnuplot_drawnow__.m b/scripts/plot/util/__gnuplot_drawnow__.m
--- a/scripts/plot/util/__gnuplot_drawnow__.m
+++ b/scripts/plot/util/__gnuplot_drawnow__.m
@@ -17,13 +17,13 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {} {} __gnuplot_drawnow__ (@var{h}, @var{term}, @var{file}, @var{mono}, @var{debug_file})
+## @deftypefn {} {} __gnuplot_drawnow__ (@var{h}, @var{term}, @var{file}, @var{debug_file})
 ## Undocumented internal function.
 ## @end deftypefn
 
 ## Author: jwe
 
-function __gnuplot_drawnow__ (h, term, file, mono = false, debug_file)
+function __gnuplot_drawnow__ (h, term, file, debug_file)
 
   if (nargin < 1 || nargin > 5 || nargin == 2)
     print_usage ();
@@ -40,11 +40,11 @@ function __gnuplot_drawnow__ (h, term, f
       gnuplot_supports_term = __gnuplot_has_terminal__ (term, plot_stream);
       if (gnuplot_supports_term)
         enhanced = gnuplot_set_term (plot_stream(1), true, h, term, file);
-        __gnuplot_draw_figure__ (h, plot_stream(1), enhanced, mono);
+        __gnuplot_draw_figure__ (h, plot_stream(1), enhanced);
         if (nargin == 5)
           fid = fopen (debug_file, "wb");
           enhanced = gnuplot_set_term (fid, true, h, term, file);
-          __gnuplot_draw_figure__ (h, fid, enhanced, mono);
+          __gnuplot_draw_figure__ (h, fid, enhanced);
         endif
       else
         error ('__gnuplot_drawnow__: the gnuplot terminal, "%s", is not available',
@@ -83,7 +83,7 @@ function __gnuplot_drawnow__ (h, term, f
     else
       enhanced = gnuplot_set_term (plot_stream(1), new_stream, h, term);
     endif
-    __gnuplot_draw_figure__ (h, plot_stream(1), enhanced, mono);
+    __gnuplot_draw_figure__ (h, plot_stream(1), enhanced);
     fflush (plot_stream(1));
     if (strcmp (term, "dumb"))
       fid = -1;
@@ -269,8 +269,9 @@ function enhanced = gnuplot_set_term (pl
 
     ## Set the gnuplot terminal (type, enhanced, title, options & size).
     term_str = ["set terminal " term];
-    if (__gnuplot_has_feature__ ("needs_color_with_postscript") ...
-        && strcmp (term, "postscript"))
+    if (strcmpi (term, {"aifm", "cairolatex", "cgm", "context", "corel", ...
+      "emf", "epslatex", "fig", "lua", "pdf", "pdfcairo", "pngcairo", ...
+      "postscript", "pslatex"}))
       term_str = [term_str, " color"];
     endif
     if (! isempty (enh_str))
diff --git a/scripts/plot/util/print.m b/scripts/plot/util/print.m
--- a/scripts/plot/util/print.m
+++ b/scripts/plot/util/print.m
@@ -404,8 +404,7 @@ function print (varargin)
       set (h, "linestyle", linestyle);
     endif
 
-    if (opts.use_color < 0
-        && ! strcmp (get (opts.figure, "__graphics_toolkit__"), "gnuplot"))
+    if (opts.use_color < 0)
       color_props = {"color", "facecolor", "edgecolor", "colormap"};
       for c = 1:numel (color_props)
         h = findall (opts.figure, "-property", color_props{c});
diff --git a/scripts/plot/util/private/__gnuplot_draw_axes__.m b/scripts/plot/util/private/__gnuplot_draw_axes__.m
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m
+++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m
@@ -17,14 +17,14 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {} {} __gnuplot_draw_axes__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
+## @deftypefn {} {} __gnuplot_draw_axes__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{bg_is_set}, @var{fg_is_set}, @var{hlgnd})
 ## Undocumented internal function.
 ## @end deftypefn
 
 ## Author: jwe
 
-function __gnuplot_draw_axes__ (h, plot_stream, enhanced, mono,
-                           bg_is_set, fg_is_set, hlgnd)
+function __gnuplot_draw_axes__ (h, plot_stream, enhanced, bg_is_set,
+                                fg_is_set, hlgnd)
 
   showhiddenhandles = get (0, "showhiddenhandles");
   unwind_protect
@@ -153,7 +153,7 @@ function __gnuplot_draw_axes__ (h, plot_
     if (isempty (t.string))
       fputs (plot_stream, "unset title;\n");
     else
-      colorspec = get_text_colorspec (t.color, mono);
+      colorspec = get_text_colorspec (t.color);
       [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
       fontspec = create_fontspec (f, s, gnuplot_term);
       fprintf (plot_stream, "set title \"%s\" %s %s %s;\n",
@@ -165,7 +165,7 @@ function __gnuplot_draw_axes__ (h, plot_
   if (! isempty (axis_obj.xlabel))
     t = get (axis_obj.xlabel);
     angle = t.rotation;
-    colorspec = get_text_colorspec (t.color, mono);
+    colorspec = get_text_colorspec (t.color);
     if (isempty (t.string))
       fprintf (plot_stream, "unset xlabel;\n");
       fprintf (plot_stream, "unset x2label;\n");
@@ -193,7 +193,7 @@ function __gnuplot_draw_axes__ (h, plot_
   if (! isempty (axis_obj.ylabel))
     t = get (axis_obj.ylabel);
     angle = t.rotation;
-    colorspec = get_text_colorspec (t.color, mono);
+    colorspec = get_text_colorspec (t.color);
     if (isempty (t.string))
       fprintf (plot_stream, "unset ylabel;\n");
       fprintf (plot_stream, "unset y2label;\n");
@@ -221,7 +221,7 @@ function __gnuplot_draw_axes__ (h, plot_
   if (! isempty (axis_obj.zlabel))
     t = get (axis_obj.zlabel);
     angle = t.rotation;
-    colorspec = get_text_colorspec (t.color, mono);
+    colorspec = get_text_colorspec (t.color);
     if (isempty (t.string))
       fputs (plot_stream, "unset zlabel;\n");
     else
@@ -387,7 +387,7 @@ function __gnuplot_draw_axes__ (h, plot_
   zlim = axis_obj.zlim;
   clim = axis_obj.clim;
 
-  do_tics (axis_obj, plot_stream, ymirror, mono, gnuplot_term);
+  do_tics (axis_obj, plot_stream, ymirror, gnuplot_term);
 
   fputs (plot_stream, "unset logscale;\n");
   if (xlogscale)
@@ -601,7 +601,7 @@ function __gnuplot_draw_axes__ (h, plot_
                      rows (xdat), xaxisloc_using, yaxisloc_using);
         endif
 
-        style = do_linestyle_command (obj, obj.color, data_idx, mono,
+        style = do_linestyle_command (obj, obj.color, data_idx,
                                       plot_stream, errbars);
 
         withclause{data_idx} = sprintf ("with %s linestyle %d",
@@ -781,9 +781,7 @@ function __gnuplot_draw_axes__ (h, plot_
                                     [[xcol; xcol(end)], [ycol; ycol(end)], ...
                                     [zcol; zcol(end)], [ccdat; ccdat(end)]]'];
              else
-               if (mono)
-                 colorspec = "";
-               elseif (__gnuplot_has_feature__ ("transparent_patches")
+               if (__gnuplot_has_feature__ ("transparent_patches")
                        && isscalar (obj.facealpha))
                  colorspec = sprintf ("lc rgb \"#%02x%02x%02x\" fillstyle transparent solid %f",
                                       round (255*color), obj.facealpha);
@@ -917,15 +915,11 @@ function __gnuplot_draw_axes__ (h, plot_
              pt2 = sprintf ("pointtype %s", pt2);
            endif
 
-           if (mono)
-             colorspec = "";
+           if (ischar (color))
+             colorspec = "palette";
            else
-             if (ischar (color))
-               colorspec = "palette";
-             else
-               colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
-                                    round (255*color));
-             endif
+             colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                  round (255*color));
            endif
 
            sidx = 1;
@@ -966,7 +960,7 @@ function __gnuplot_draw_axes__ (h, plot_
                                           colorspec);
                  sidx += 1;
                endif
-               if (isnumeric (obj.markerfacecolor) && ! mono)
+               if (isnumeric (obj.markerfacecolor))
                  colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
                                       round (255*obj.markerfacecolor));
                endif
@@ -1023,14 +1017,12 @@ function __gnuplot_draw_axes__ (h, plot_
                endif
 
                if (! isempty (pt))
-                 if (! mono)
-                   if (strcmp (obj.markeredgecolor, "auto"))
-                     colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
-                                          round (255*color));
-                   elseif (isnumeric (obj.markeredgecolor) && ! mono)
-                     colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
-                                          round (255*obj.markeredgecolor));
-                   endif
+                 if (strcmp (obj.markeredgecolor, "auto"))
+                   colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                        round (255*color));
+                 elseif (isnumeric (obj.markeredgecolor))
+                   colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                        round (255*obj.markeredgecolor));
                  endif
                  style = "points";
                  if (isfield (obj, "markersize"))
@@ -1129,7 +1121,7 @@ function __gnuplot_draw_axes__ (h, plot_
           have_cdata(data_idx) = true;
           have_3d_patch(data_idx) = false;
           style = do_linestyle_command (obj, obj.edgecolor,
-                                        data_idx, mono,
+                                        data_idx,
                                         plot_stream);
 
           if (isempty (obj.displayname))
@@ -1343,7 +1335,7 @@ function __gnuplot_draw_axes__ (h, plot_
         endif
 
         if (isnumeric (color))
-          colorspec = get_text_colorspec (color, mono);
+          colorspec = get_text_colorspec (color);
         endif
 
         if (ischar (obj.string))
@@ -1615,7 +1607,7 @@ function __gnuplot_draw_axes__ (h, plot_
       ## color of the plot object.
       colorspec = "textcolor variable";
     else
-      colorspec = get_text_colorspec (textcolors, mono);
+      colorspec = get_text_colorspec (textcolors);
     endif
     fprintf (plot_stream, "set key %s %s;\nset key %s %s %s %s %s %s;\n",
              inout, pos, box, reverse, horzvert, fontspacespec, colorspec,
@@ -1627,7 +1619,7 @@ function __gnuplot_draw_axes__ (h, plot_
 
   cmap = [cmap; addedcmap];
   cmap_sz += rows (addedcmap);
-  if (mono == false && length (cmap) > 0)
+  if (length (cmap) > 0)
     fprintf (plot_stream,
              "set palette positive color model RGB maxcolors %i;\n",
              cmap_sz);
@@ -1795,7 +1787,7 @@ function fontspec = create_fontspec (f, 
   endif
 endfunction
 
-function style = do_linestyle_command (obj, linecolor, idx, mono,
+function style = do_linestyle_command (obj, linecolor, idx,
                                        plot_stream, errbars = "")
   style = {};
 
@@ -1805,10 +1797,8 @@ function style = do_linestyle_command (o
   found_style = false;
   if (isnumeric (linecolor))
     color = linecolor;
-    if (! mono)
-      fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
-               round (255*color));
-    endif
+    fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
+             round (255*color));
   else
     color = [0, 0, 0];
   endif
@@ -1887,7 +1877,7 @@ function style = do_linestyle_command (o
         endif
         fprintf (plot_stream, "set style line %d default;\n", idx);
         fprintf (plot_stream, "set style line %d", idx);
-        if (isnumeric (obj.markerfacecolor) && ! mono)
+        if (isnumeric (obj.markerfacecolor))
           fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
                    round (255*obj.markerfacecolor));
         endif
@@ -1930,14 +1920,12 @@ function style = do_linestyle_command (o
         endif
         fprintf (plot_stream, "set style line %d default;\n", idx);
         fprintf (plot_stream, "set style line %d", idx);
-        if (! mono)
-          if (strcmp (obj.markeredgecolor, "auto"))
-            fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
-                     round (255*color));
-          elseif (isnumeric (obj.markeredgecolor) && ! mono)
-            fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
-                     round (255*obj.markeredgecolor));
-          endif
+        if (strcmp (obj.markeredgecolor, "auto"))
+          fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
+                   round (255*color));
+        elseif (isnumeric (obj.markeredgecolor))
+          fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
+                   round (255*obj.markeredgecolor));
         endif
         if (! isempty (pt))
           style{sidx} = "points";
@@ -2051,7 +2039,7 @@ function __gnuplot_write_data__ (plot_st
 
 endfunction
 
-function do_tics (obj, plot_stream, ymirror, mono, gnuplot_term)
+function do_tics (obj, plot_stream, ymirror, gnuplot_term)
 
   obj.xticklabel = ticklabel_to_cell (obj.xticklabel);
   obj.yticklabel = ticklabel_to_cell (obj.yticklabel);
@@ -2075,68 +2063,68 @@ function do_tics (obj, plot_stream, ymir
 
   if (strcmpi (obj.xaxislocation, "top"))
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
-               obj.xticklabel, obj.xcolor, "x2", plot_stream, true, mono,
+               obj.xticklabel, obj.xcolor, "x2", plot_stream, true,
                "border", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
-               obj.xcolor, "x", plot_stream, true, mono, "border",
+               obj.xcolor, "x", plot_stream, true, "border",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.xscale, obj.xsgn, gnuplot_term);
   elseif (strcmpi (obj.xaxislocation, "zero"))
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
-               obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono,
+               obj.xticklabel, obj.xcolor, "x", plot_stream, true,
                "axis", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
-               obj.xcolor, "x2", plot_stream, true, mono, "axis",
+               obj.xcolor, "x2", plot_stream, true, "axis",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.xscale, obj.xsgn, gnuplot_term);
   else
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
-               obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono,
+               obj.xticklabel, obj.xcolor, "x", plot_stream, true,
                "border", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
-               obj.xcolor, "x2", plot_stream, true, mono, "border",
+               obj.xcolor, "x2", plot_stream, true, "border",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.xscale, obj.xsgn, gnuplot_term);
   endif
   if (strcmpi (obj.yaxislocation, "right"))
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
-               obj.yticklabel, obj.ycolor, "y2", plot_stream, ymirror, mono,
+               obj.yticklabel, obj.ycolor, "y2", plot_stream, ymirror,
                "border", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
-               obj.ycolor, "y", plot_stream, ymirror, mono, "border",
+               obj.ycolor, "y", plot_stream, ymirror, "border",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.yscale, obj.ysgn, gnuplot_term);
   elseif (strcmpi (obj.yaxislocation, "zero"))
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
-               obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono,
+               obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror,
                "axis", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
-               obj.ycolor, "y2", plot_stream, ymirror, mono, "axis",
+               obj.ycolor, "y2", plot_stream, ymirror, "axis",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.yscale, obj.ysgn, gnuplot_term);
   else
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
-               obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono,
+               obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror,
                "border", obj.tickdir, ticklength, fontname, fontspec,
                obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
     do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
-               obj.ycolor, "y2", plot_stream, ymirror, mono, "border",
+               obj.ycolor, "y2", plot_stream, ymirror, "border",
                "", "", fontname, fontspec, obj.ticklabelinterpreter,
                obj.yscale, obj.ysgn, gnuplot_term);
   endif
   do_tics_1 (obj.ztickmode, obj.ztick, obj.zminortick, obj.zticklabelmode,
-             obj.zticklabel, obj.zcolor, "z", plot_stream, true, mono,
+             obj.zticklabel, obj.zcolor, "z", plot_stream, true,
              "border", obj.tickdir, ticklength, fontname, fontspec,
              obj.ticklabelinterpreter, obj.zscale, obj.zsgn, gnuplot_term);
 endfunction
 
 function do_tics_1 (ticmode, tics, mtics, labelmode, labels, color, ax,
-                    plot_stream, mirror, mono, axispos, tickdir, ticklength,
+                    plot_stream, mirror, axispos, tickdir, ticklength,
                     fontname, fontspec, interpreter, scale, sgn, gnuplot_term)
   persistent warned_latex = false;
 
@@ -2176,7 +2164,7 @@ function do_tics_1 (ticmode, tics, mtics
     fmt = "%g";
     num_mtics = 5;
   endif
-  colorspec = get_text_colorspec (color, mono);
+  colorspec = get_text_colorspec (color);
   fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt);
   if (strcmpi (ticmode, "manual"))
     if (isempty (tics))
@@ -2226,13 +2214,8 @@ function ticklabel = ticklabel_to_cell (
   endif
 endfunction
 
-function colorspec = get_text_colorspec (color, mono)
-  if (mono)
-    colorspec = "";
-  else
-    colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"",
-                         round (255*color));
-  endif
+function colorspec = get_text_colorspec (color)
+  colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", round (255*color));
 endfunction
 
 function [f, s, fnt, it, bld] = get_fontname_and_size (t)
diff --git a/scripts/plot/util/private/__gnuplot_draw_figure__.m b/scripts/plot/util/private/__gnuplot_draw_figure__.m
--- a/scripts/plot/util/private/__gnuplot_draw_figure__.m
+++ b/scripts/plot/util/private/__gnuplot_draw_figure__.m
@@ -17,13 +17,13 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {} {} __gnuplot_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
+## @deftypefn {} {} __gnuplot_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced})
 ## Undocumented internal function.
 ## @end deftypefn
 
 ## Author: jwe
 
-function __gnuplot_draw_figure__ (h, plot_stream, enhanced, mono)
+function __gnuplot_draw_figure__ (h, plot_stream, enhanced)
 
   htype = get (h, "type");
   if (strcmp (htype, "figure"))
@@ -116,7 +116,7 @@ function __gnuplot_draw_figure__ (h, plo
                   if (bg_is_set)
                     fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", round (255 * (1 - bg)));
                   endif
-                  __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced, mono,
+                  __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced,
                                     bg_is_set, false, hlgnd);
                 unwind_protect_cleanup
                   ## Return axes "units" and "position" back to
@@ -169,7 +169,7 @@ function __gnuplot_draw_figure__ (h, plo
                     endif
                   endif
                 endfor
-                __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced, mono,
+                __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced,
                                   bg_is_set, fg_is_set, hlegend);
               unwind_protect_cleanup
                 ## Return axes "units" and "position" back to
