# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1444589516 -7200
#      Sun Oct 11 20:51:56 2015 +0200
# Node ID 0177ab6f609616a67a5ca5d9eb54fb537308b8ae
# Parent  1c5a86b7f83876a47c6fe43f190bbb582b59e6ee
get screenpixelsperinch only once, and use /=

diff -r 1c5a86b7f838 -r 0177ab6f6096 scripts/plot/util/__gnuplot_drawnow__.m
--- a/scripts/plot/util/__gnuplot_drawnow__.m	Sat Oct 10 16:52:59 2015 -0700
+++ b/scripts/plot/util/__gnuplot_drawnow__.m	Sun Oct 11 20:51:56 2015 +0200
@@ -185,8 +185,9 @@
                || any (strcmp (term, {"canvas", "emf", "gif", "jpeg", ...
                                       "pbm", "png", "pngcairo", "svg"}))))
           ## Convert to inches
-          gnuplot_pos = gnuplot_pos / get (0, "screenpixelsperinch");
-          gnuplot_size = gnuplot_size / get (0, "screenpixelsperinch");
+          pixelsperinch =  get(0, "ScreenPixelsPerInch");
+          gnuplot_pos /= pixelsperinch;
+          gnuplot_size /= pixelsperinch;
         endif
         if (all (gnuplot_size > 0))
           terminals_with_size = {"canvas", "emf", "epslatex", "fig", ...
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1444593076 -7200
#      Sun Oct 11 21:51:16 2015 +0200
# Node ID 7d31d09086c73e6103f81ca3823d430e4066ae01
# Parent  0177ab6f609616a67a5ca5d9eb54fb537308b8ae
base papersize conversion on screenpixelsperinch (fix pdf pagesize)

diff -r 0177ab6f6096 -r 7d31d09086c7 scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Sun Oct 11 20:51:56 2015 +0200
+++ b/scripts/plot/util/private/__ghostscript__.m	Sun Oct 11 21:51:16 2015 +0200
@@ -94,8 +94,9 @@
     if (ischar (opts.papersize))
       gs_opts = sprintf ("%s -sPAPERSIZE=%s", gs_opts, opts.papersize);
     elseif (isnumeric (opts.papersize) && numel (opts.papersize) == 2)
+      papersize_pt = fix (opts.papersize * 72 / get (0 , "screenpixelsperinch"));
       gs_opts = sprintf ("%s -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d",
-                         gs_opts, fix (opts.papersize));
+                         gs_opts, papersize_pt);
       if (opts.papersize(1) > opts.papersize(2))
         ## Lanscape mode: This option will result in automatic rotation of the
         ##                document page if the requested page size matches one
diff -r 0177ab6f6096 -r 7d31d09086c7 scripts/plot/util/private/__print_parse_opts__.m
--- a/scripts/plot/util/private/__print_parse_opts__.m	Sun Oct 11 20:51:56 2015 +0200
+++ b/scripts/plot/util/private/__print_parse_opts__.m	Sun Oct 11 21:51:16 2015 +0200
@@ -560,7 +560,7 @@
                    9.8, 13.9;  6.9,  9.8;  9.0, 12.0; 12.0, 18.0;
                   18.0, 24.0; 24.0, 36.0; 36.0, 48.0;  8.5, 11.0;
                   11.0, 17.0; 18.0, 24.0; 24.0, 36.0; 36.0, 48.0;
-                  11.0, 17.0] * 72;
+                  11.0, 17.0];
   endif
 
   papertype = get (hfig, "papertype");
@@ -568,7 +568,7 @@
   paperposition = get (hfig, "paperposition");
   if (strcmp (papertype, "<custom>"))
     papersize = get (hfig, "papersize");
-    papersize = convert2points (papersize , paperunits);
+    papersize = convert2pixels (papersize , paperunits);
   else
     papersize = papersizes (strcmp (papertypes, papertype), :);
   endif
@@ -576,7 +576,7 @@
   if (strcmp (paperunits, "normalized"))
     paperposition .*= papersize([1,2,1,2]);
   else
-    paperposition = convert2points (paperposition, paperunits);
+    paperposition = convert2pixels (paperposition, paperunits);
   endif
 
   ## FIXME: This will be obsoleted by listeners for paper properties.
@@ -608,12 +608,13 @@
 
 endfunction
 
-function value = convert2points (value, units)
+function value = convert2pixels (value, units)
+  ## units conversions are based on screenpixelsperinch, for consistency with listeners
   switch (units)
     case "inches"
-      value *= 72;
+      value *= get (0, "screenpixelsperinch");
     case "centimeters"
-      value *= 72 / 2.54;
+      value *= get (0, "screenpixelsperinch") / 2.54;
     case "normalized"
       error ("print:customnormalized",
              "print.m: papersize=='<custom>' and paperunits='normalized' may not be combined");
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1444852324 -7200
#      Wed Oct 14 21:52:04 2015 +0200
# Node ID d3b9e89847a9f3cdeab54559db64d5c78fc9afbc
# Parent  7d31d09086c73e6103f81ca3823d430e4066ae01
72 => screenpixelsperinch, for print -Ssx,sy file.png

diff -r 7d31d09086c7 -r d3b9e89847a9 scripts/plot/util/private/__print_parse_opts__.m
--- a/scripts/plot/util/private/__print_parse_opts__.m	Sun Oct 11 21:51:16 2015 +0200
+++ b/scripts/plot/util/private/__print_parse_opts__.m	Wed Oct 14 21:52:04 2015 +0200
@@ -361,7 +361,7 @@
       ## Work around the eps bbox having whole numbers (both gnuplot & gl2ps).
       arg_st.scalefontsize = arg_st.ghostscript.resolution / 72;
     endif
-    arg_st.ghostscript.resolution = 72;
+    arg_st.ghostscript.resolution = get (0, "screenpixelsperinch");
     arg_st.ghostscript.papersize = arg_st.canvas_size;
     arg_st.ghostscript.epscrop = true;
     arg_st.ghostscript.pageoffset = [0, 0];
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1445021699 -7200
#      Fri Oct 16 20:54:59 2015 +0200
# Node ID 4a4ed286608a208a1c67828cd56a1c49cf0bdc73
# Parent  d3b9e89847a9f3cdeab54559db64d5c78fc9afbc
set and use opts.ghostscript.formatted_for_printing instead of setting papersize to "" for bitmaps

diff -r d3b9e89847a9 -r 4a4ed286608a scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Wed Oct 14 21:52:04 2015 +0200
+++ b/scripts/plot/util/private/__ghostscript__.m	Fri Oct 16 20:54:59 2015 +0200
@@ -60,12 +60,6 @@
     opts.(args{n}) = args{n+1};
   endfor
 
-  if (isempty (opts.papersize))
-    format_for_printer = false;
-  else
-    format_for_printer = true;
-  endif
-
   gs_opts = ["-dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=" opts.device];
 
   if (! isempty (opts.level) && ismember (opts.level, [1, 2, 3]))
@@ -77,7 +71,9 @@
     gs_opts = sprintf ("%s -dTextAlphaBits=%d -dGraphicsAlphaBits=%d",
                        gs_opts, fix (opts.antialiasing_textalphabits),
                        fix (opts.antialiasing_graphicsalphabits));
-    gs_opts = sprintf ("%s -r%dx%d", gs_opts, fix ([1, 1] * opts.resolution));
+    gs_opts = sprintf ("%s -r%gx%g", gs_opts, [1, 1] * opts.resolution);
+    ## need set the exact geometry, in order to avoid small roundoff errors
+    gs_opts = sprintf ("%s -g%dx%d", gs_opts, opts.papersize);
   elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"})))
     gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts);
     if (strcmp (opts.device, "pdfwrite"))
@@ -90,7 +86,7 @@
     ## papersize is specified by the eps bbox
     gs_opts = sprintf ("%s -dEPSCrop", gs_opts);
   endif
-  if (format_for_printer)
+  if (opts.formatted_for_printing)
     if (ischar (opts.papersize))
       gs_opts = sprintf ("%s -sPAPERSIZE=%s", gs_opts, opts.papersize);
     elseif (isnumeric (opts.papersize) && numel (opts.papersize) == 2)
@@ -169,7 +165,7 @@
       endif
     endif
   endif
-  if (! isempty (offsetfile) && format_for_printer)
+  if (! isempty (offsetfile) && opts.formatted_for_printing)
     cmd = sprintf ("%s %s", cmd, offsetfile);
   endif
   if (! isempty (opts.source))
diff -r d3b9e89847a9 -r 4a4ed286608a scripts/plot/util/private/__print_parse_opts__.m
--- a/scripts/plot/util/private/__print_parse_opts__.m	Wed Oct 14 21:52:04 2015 +0200
+++ b/scripts/plot/util/private/__print_parse_opts__.m	Fri Oct 16 20:54:59 2015 +0200
@@ -43,6 +43,7 @@
   arg_st.ghostscript.debug = false;
   arg_st.ghostscript.device = "";
   arg_st.ghostscript.epscrop = true;
+  arg_st.ghostscript.formatted_for_printing = false; # same as arg_st.formatted_for_printing
   arg_st.ghostscript.level = 2;
   arg_st.ghostscript.output = "";
   arg_st.ghostscript.papersize = "";
@@ -368,9 +369,10 @@
   endif
 
   if (arg_st.formatted_for_printing)
+    arg_st.ghostscript.formatted_for_printing = true;
     arg_st.ghostscript.resolution = [];
   else
-    arg_st.ghostscript.papersize = "";
+    arg_st.ghostscript.formatted_for_printing = false;
     arg_st.ghostscript.pageoffset = [0, 0];
   endif
 
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1445094123 -7200
#      Sat Oct 17 17:02:03 2015 +0200
# Node ID e6f77786f9189f41155c31a5e267ba1c3620f38a
# Parent  4a4ed286608a208a1c67828cd56a1c49cf0bdc73
set the geometry only when explicitely given

diff -r 4a4ed286608a -r e6f77786f918 scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Fri Oct 16 20:54:59 2015 +0200
+++ b/scripts/plot/util/private/__ghostscript__.m	Sat Oct 17 17:02:03 2015 +0200
@@ -72,8 +72,11 @@
                        gs_opts, fix (opts.antialiasing_textalphabits),
                        fix (opts.antialiasing_graphicsalphabits));
     gs_opts = sprintf ("%s -r%gx%g", gs_opts, [1, 1] * opts.resolution);
-    ## need set the exact geometry, in order to avoid small roundoff errors
-    gs_opts = sprintf ("%s -g%dx%d", gs_opts, opts.papersize);
+    if isnumeric (opts.papersize)
+      ## size has been given with the "-Ssx,xy" option.
+      ## need to set the exact geometry, in order to avoid small roundoff errors
+      gs_opts = sprintf ("%s -g%dx%d", gs_opts, opts.papersize);
+    endif
   elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"})))
     gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts);
     if (strcmp (opts.device, "pdfwrite"))
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1445448608 -7200
#      Wed Oct 21 19:30:08 2015 +0200
# Node ID 1979cf89aaa6c25b79f21a153a87841eaebdacce
# Parent  e6f77786f9189f41155c31a5e267ba1c3620f38a
print the intermediate eps output from gl2ps to a debug file

diff -r e6f77786f918 -r 1979cf89aaa6 scripts/plot/util/private/__opengl_print__.m
--- a/scripts/plot/util/private/__opengl_print__.m	Sat Oct 17 17:02:03 2015 +0200
+++ b/scripts/plot/util/private/__opengl_print__.m	Wed Oct 21 19:30:08 2015 +0200
@@ -161,6 +161,10 @@
 
   for n = 1:numel (pipeline)
     if (opts.debug)
+      ## print the intermediate eps output from gl2ps to a debug file
+      [debug_file_dir, debug_file_base] = fileparts(opts.debug_file);
+      debug_file_eps = fullfile(debug_file_dir, [debug_file_base ".eps"]);
+      pipeline{n} = sprintf("tee %s | %s", debug_file_eps, pipeline{n});
       fprintf ("opengl-pipeline: '%s'\n", pipeline{n});
     endif
 
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1445770168 -3600
#      Sun Oct 25 11:49:28 2015 +0100
# Node ID e13c43dbcdac0f1496663ce000be55779beb14f3
# Parent  1979cf89aaa6c25b79f21a153a87841eaebdacce
round-off papersize for gs -g<sx>,<sy>

diff -r 1979cf89aaa6 -r e13c43dbcdac scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Wed Oct 21 19:30:08 2015 +0200
+++ b/scripts/plot/util/private/__ghostscript__.m	Sun Oct 25 11:49:28 2015 +0100
@@ -75,7 +75,8 @@
     if isnumeric (opts.papersize)
       ## size has been given with the "-Ssx,xy" option.
       ## need to set the exact geometry, in order to avoid small roundoff errors
-      gs_opts = sprintf ("%s -g%dx%d", gs_opts, opts.papersize);
+      ## note: gs -g<sx>,<sy> requires integers
+      gs_opts = sprintf ("%s -g%dx%d", gs_opts, round(opts.papersize));
     endif
   elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"})))
     gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts);
# HG changeset patch
# User ederag <edera@gmx.fr>
# Date 1445770892 -3600
#      Sun Oct 25 12:01:32 2015 +0100
# Node ID bd95a1641010ce55d34f17bdeef3a8b175c7f370
# Parent  e13c43dbcdac0f1496663ce000be55779beb14f3
specific record for the -S<sx>,<sy> option usage

diff -r e13c43dbcdac -r bd95a1641010 scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Sun Oct 25 11:49:28 2015 +0100
+++ b/scripts/plot/util/private/__ghostscript__.m	Sun Oct 25 12:01:32 2015 +0100
@@ -72,7 +72,7 @@
                        gs_opts, fix (opts.antialiasing_textalphabits),
                        fix (opts.antialiasing_graphicsalphabits));
     gs_opts = sprintf ("%s -r%gx%g", gs_opts, [1, 1] * opts.resolution);
-    if isnumeric (opts.papersize)
+    if opts.size_from_cmd_line
       ## size has been given with the "-Ssx,xy" option.
       ## need to set the exact geometry, in order to avoid small roundoff errors
       ## note: gs -g<sx>,<sy> requires integers
diff -r e13c43dbcdac -r bd95a1641010 scripts/plot/util/private/__print_parse_opts__.m
--- a/scripts/plot/util/private/__print_parse_opts__.m	Sun Oct 25 11:49:28 2015 +0100
+++ b/scripts/plot/util/private/__print_parse_opts__.m	Sun Oct 25 12:01:32 2015 +0100
@@ -49,6 +49,7 @@
   arg_st.ghostscript.papersize = "";
   arg_st.ghostscript.pageoffset = [];
   arg_st.ghostscript.resolution = 150;
+  arg_st.ghostscript.size_from_cmd_line = false;
   arg_st.ghostscript.antialiasing = false;
   arg_st.ghostscript.antialiasing_textalphabits = 4;
   arg_st.ghostscript.antialiasing_graphicsalphabits = 4;
@@ -153,6 +154,7 @@
         endif
       elseif (length (arg) > 2 && arg(1:2) == "-S")
         arg_st.canvas_size = str2num (arg(3:end));
+        arg_st.ghostscript.size_from_cmd_line = true;
       elseif (length (arg) > 2 && arg(1:2) == "-r")
         arg_st.ghostscript.resolution = str2double (arg(3:end));
       elseif (length (arg) > 2 && arg(1:2) == "-f")
