[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: |
Fri, 22 May 2009 15:43:37 +0200 |
User-agent: |
Thunderbird 2.0.0.18 (Windows/20081105) |
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.
benjamin
ghostscript handling for windows in print.m
diff -r 5ca0f5103861 scripts/ChangeLog
--- a/scripts/ChangeLog Thu May 21 13:18:53 2009 +0200
+++ b/scripts/ChangeLog Fri May 22 15:28:20 2009 +0200
@@ -1,3 +1,10 @@
+2009-05-22 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-19 Carlo de Falco <address@hidden>
* pkg/pkg.m: Fix a bug when quering only one non installed package
diff -r 5ca0f5103861 scripts/plot/gnuplot_drawnow.m
--- a/scripts/plot/gnuplot_drawnow.m Thu May 21 13:18:53 2009 +0200
+++ b/scripts/plot/gnuplot_drawnow.m Fri May 22 15:28:20 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 5ca0f5103861 scripts/plot/print.m
--- a/scripts/plot/print.m Thu May 21 13:18:53 2009 +0200
+++ b/scripts/plot/print.m Fri May 22 15:28:20 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
ensure quoted gnuplot binary
diff -r e29f83e30461 scripts/ChangeLog
--- a/scripts/ChangeLog Thu May 21 13:18:30 2009 +0200
+++ b/scripts/ChangeLog Fri May 22 15:29:59 2009 +0200
@@ -1,3 +1,8 @@
+2009-05-22 Benjamin Lindner <address@hidden>
+
+ * plot/__gnuplot_version__.m: quote gnuplot_binary to allow spaces
+ in file name
+
2009-05-19 Carlo de Falco <address@hidden>
* pkg/pkg.m: Fix a bug when quering only one non installed package
diff -r e29f83e30461 scripts/plot/__gnuplot_version__.m
--- a/scripts/plot/__gnuplot_version__.m Thu May 21 13:18:30 2009 +0200
+++ b/scripts/plot/__gnuplot_version__.m Fri May 22 15:29:59 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,
- Re: [CHANGESET] updated print.m,
Benjamin Lindner <=