octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [CHANGESET] updated print.m


From: Benjamin Lindner
Subject: Re: [CHANGESET] updated print.m
Date: Sun, 24 May 2009 10:12:53 +0200
User-agent: Thunderbird 2.0.0.18 (Windows/20081105)

Ben Abbott wrote:

On May 22, 2009, at 9:43 AM, Benjamin Lindner wrote:

I've pushed this changeset. If anyone has trouble printing let me know (particularly on Windows).

I did a check using print.m on mingw32 (not printing to hardware) using this simple test sequence:

plot(0:0.1:10, sin(0:0.1:10), "@-;sin;", 0:0.1:10, cos(0:0.1:10), "@-;cos;");
print -depsc2 test.eps
print -dpsc2  test.ps
print -dpng   test.png
print -demf   test.emf
print -dpdf   test.pdf

and all work except the pdf output.

I suggest the attached two changesets for the windows users:
1) ensure that gnuplot_binary is quoted when used, because it may contain spaces (this sadly happens quite frequently under windows).

2.a) in print.m, for the same reason, ensure that ghostscript_binary is always quoted when used. 2.b) use double quotes, since cmd.exe does not seem to understand single quotes. 2.c) the windows binary of ghostscript uses the environment variable GSC as location for the console ghostscript binary. I added code in print.m to test for %GSC% and use it, and default to "gswin32c" otherwise. 2.d) single-quote the output file name in gnuplot_drawnow.m to allow for backslash file separators. Otherwise print("-demf","t:\\temp\\test.emf") will not work, while print("-demf","t:/temp/test.emf") works.

With this I get working output for all 5 file formats.

Somethig else I realized: gnuplot's pdfcairo terminal is not recognized, so even while gnuplot has a direct pdf output terminal, print.m uses the indirect way ps->pdf via ghostscript.


Ben,

I tried to import your changesets using "hg import ..." and "patch -p1 < your.patch", but they do not apply for me.

I assume there are some EOL problems ... which might be introduced by my email client.

Can you resend them as attachements, and if you create them using "hg import ..." please include the hg header as well. Also John has committed a patch since you last pulled. That needs to be corrected as well.


Sorry, I mixed up changesets with mq patches.

I updated my 3.1.x repos and corrected my changes.
I have now attached the exported changesets.

benjamin
# HG changeset patch
# User Benjamin Lindner <address@hidden>
# Date 1243152559 -7200
# Node ID 692621f2fd099bca03e5cbf574085730b91b7408
# Parent  ec08d8d25076ff80241dd66ea0aac5edf17eed4d
ghostscript handling for windows in print.m

diff -r ec08d8d25076 -r 692621f2fd09 scripts/ChangeLog
--- a/scripts/ChangeLog Sun May 24 10:08:35 2009 +0200
+++ b/scripts/ChangeLog Sun May 24 10:09:19 2009 +0200
@@ -1,3 +1,10 @@
+2009-05-24 Benjamin Lindner <address@hidden>
+
+       * plot/gnuplot_drawnow.m: single-quote output name to allow backslash
+       characters as filesep under windows
+       * plot/print.m: Support ps->pdf using ghostscript under windows, check
+       for %GSC% environment variable.
+
 2009-05-24 Benjamin Lindner <address@hidden>
 
        * plot/__gnuplot_version__.m: quote gnuplot_binary to allow spaces
diff -r ec08d8d25076 -r 692621f2fd09 scripts/plot/gnuplot_drawnow.m
--- a/scripts/plot/gnuplot_drawnow.m    Sun May 24 10:08:35 2009 +0200
+++ b/scripts/plot/gnuplot_drawnow.m    Sun May 24 10:09:19 2009 +0200
@@ -278,7 +278,7 @@
 
   if (nargin == 5)
     if (! isempty (file))
-      fprintf (plot_stream, "set output \"%s\";\n", file);
+      fprintf (plot_stream, "set output '%s';\n", file);
     endif
   endif
 
diff -r ec08d8d25076 -r 692621f2fd09 scripts/plot/print.m
--- a/scripts/plot/print.m      Sun May 24 10:08:35 2009 +0200
+++ b/scripts/plot/print.m      Sun May 24 10:09:19 2009 +0200
@@ -186,7 +186,11 @@
   if (isunix ())
     persistent ghostscript_binary = "gs";
   elseif (ispc ())
-    persistent ghostscript_binary = "gswin32c";
+    if (~isempty (getenv ("GSC")))
+      persistent ghostscript_binary = getenv ("GSC");
+    else
+      persistent ghostscript_binary = "gswin32c";
+    endif
   endif
 
   old_fig = get (0, "currentfigure");
@@ -253,7 +257,8 @@
       [status, output] = system (sprintf ("which %s 2>&1", 
ghostscript_binary));
       have_ghostscript = (status == 0);
     elseif (ispc ())
-      have_ghostscript = true;
+      [status, output] = system (sprintf ("if exist \"%s\" ( exit /B 1 ) else 
( exit /B 0 )", ghostscript_binary));
+      have_ghostscript = (status ~= 0);
     endif
 
     doprint = isempty (name);
@@ -571,12 +576,12 @@
       endif
       ghostscript_options = sprintf ("%s -sDEVICE=%s", ghostscript_options,
                                      ghostscript_device);
-      command = sprintf ("%s %s -sOutputFile='%s' '%s' 2>&1", 
ghostscript_binary,
+      command = sprintf ("\"%s\" %s -sOutputFile=\"%s\" \"%s\" 2>&1", 
ghostscript_binary,
                           ghostscript_options, ghostscript_output, name);
       [errcode, output] = system (command);
       unlink (name);
       if (errcode)
-        error ("print: Conversion failed, %s -> %s.", name, 
ghostscript_output);
+        error ("print: Conversion failed, %s -> %s.\nError was:\n%s\n", name, 
ghostscript_output, output);
       endif
     elseif (is_eps_file && tight_flag && ! doprint)
       ## If the saved output file is an eps file, use ghostscript to set a 
tight bbox.
@@ -625,7 +630,7 @@
   box_string = "%%BoundingBox:";
 
   ghostscript_options = "-q -dBATCH -dSAFER -dNOPAUSE -dTextAlphaBits=4 
-sDEVICE=bbox";
-  cmd = sprintf ("%s %s '%s' 2>&1", ghostscript_binary, ghostscript_options, 
eps_file_name);
+  cmd = sprintf ("\"%s\" %s \"%s\" 2>&1", ghostscript_binary, 
ghostscript_options, eps_file_name);
   [status, output] = system (cmd);
 
   if (status == 0)
@@ -672,7 +677,7 @@
     end_unwind_protect
   elseif (warn_on_no_ghostscript)
     warn_on_no_ghostscript = false;
-    warning ("print.m: Ghostscript could not be used to adjust bounding box.")
+    warning ("print.m: Ghostscript could not be used to adjust bounding 
box.\nError was:\n%s\n", output)
   endif
 
 endfunction
# HG changeset patch
# User Benjamin Lindner <address@hidden>
# Date 1243152330 -7200
# Node ID fbbef32dc1eab043c56840b4874551fe5e455933
# Parent  7b94eb96bec7b6d19e84e14c2e506d364fa54d18
ensure quoted gnuplot binary

diff -r 7b94eb96bec7 -r fbbef32dc1ea scripts/ChangeLog
--- a/scripts/ChangeLog Sun May 24 10:04:44 2009 +0200
+++ b/scripts/ChangeLog Sun May 24 10:05:30 2009 +0200
@@ -1,3 +1,8 @@
+2009-05-24 Benjamin Lindner <address@hidden>
+
+       * plot/__gnuplot_version__.m: quote gnuplot_binary to allow spaces
+       in file name
+
 2009-05-22  John W. Eaton  <address@hidden>
 
        * general/interp3.m: Don't require interpolation grid to have same
diff -r 7b94eb96bec7 -r fbbef32dc1ea scripts/plot/__gnuplot_version__.m
--- a/scripts/plot/__gnuplot_version__.m        Sun May 24 10:04:44 2009 +0200
+++ b/scripts/plot/__gnuplot_version__.m        Sun May 24 10:05:30 2009 +0200
@@ -30,7 +30,7 @@
   persistent __version__ = "";
 
   if (isempty (__version__))
-    [status, output] = system (sprintf ("%s --version", gnuplot_binary ()));
+    [status, output] = system (sprintf ("\"%s\" --version", gnuplot_binary 
()));
     if (status != 0)
       ## This message ends in a newline so that the traceback messages
       ## are skipped and people might actually see the message, read it,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]