Mercurial > hg > octave-lyh
comparison scripts/plot/print.m @ 9249:470af0f93ca9
ghostscript handling for windows in print.m
author | Benjamin Lindner <lindnerb@users.sourceforge.net> |
---|---|
date | Sun, 24 May 2009 10:09:19 +0200 |
parents | 923c7cb7f13f |
children | 4f96a7770492 |
comparison
equal
deleted
inserted
replaced
9248:98034ebda172 | 9249:470af0f93ca9 |
---|---|
184 tight_flag = false; | 184 tight_flag = false; |
185 resolution = ""; | 185 resolution = ""; |
186 if (isunix ()) | 186 if (isunix ()) |
187 persistent ghostscript_binary = "gs"; | 187 persistent ghostscript_binary = "gs"; |
188 elseif (ispc ()) | 188 elseif (ispc ()) |
189 persistent ghostscript_binary = "gswin32c"; | 189 if (~isempty (getenv ("GSC"))) |
190 persistent ghostscript_binary = getenv ("GSC"); | |
191 else | |
192 persistent ghostscript_binary = "gswin32c"; | |
193 endif | |
190 endif | 194 endif |
191 | 195 |
192 old_fig = get (0, "currentfigure"); | 196 old_fig = get (0, "currentfigure"); |
193 unwind_protect | 197 unwind_protect |
194 ## Ensure the last figure is on the screen for single line commands like | 198 ## Ensure the last figure is on the screen for single line commands like |
251 | 255 |
252 if (isunix ()) | 256 if (isunix ()) |
253 [status, output] = system (sprintf ("which %s 2>&1", ghostscript_binary)); | 257 [status, output] = system (sprintf ("which %s 2>&1", ghostscript_binary)); |
254 have_ghostscript = (status == 0); | 258 have_ghostscript = (status == 0); |
255 elseif (ispc ()) | 259 elseif (ispc ()) |
256 have_ghostscript = true; | 260 [status, output] = system (sprintf ("if exist \"%s\" ( exit /B 1 ) else ( exit /B 0 )", ghostscript_binary)); |
261 have_ghostscript = (status ~= 0); | |
257 endif | 262 endif |
258 | 263 |
259 doprint = isempty (name); | 264 doprint = isempty (name); |
260 if (doprint) | 265 if (doprint) |
261 if (isempty (devopt)) | 266 if (isempty (devopt)) |
569 ## If output is a bitmap then include the resolution | 574 ## If output is a bitmap then include the resolution |
570 ghostscript_options = sprintf ("%s -r%d", ghostscript_options, resolution); | 575 ghostscript_options = sprintf ("%s -r%d", ghostscript_options, resolution); |
571 endif | 576 endif |
572 ghostscript_options = sprintf ("%s -sDEVICE=%s", ghostscript_options, | 577 ghostscript_options = sprintf ("%s -sDEVICE=%s", ghostscript_options, |
573 ghostscript_device); | 578 ghostscript_device); |
574 command = sprintf ("%s %s -sOutputFile='%s' '%s' 2>&1", ghostscript_binary, | 579 command = sprintf ("\"%s\" %s -sOutputFile=\"%s\" \"%s\" 2>&1", ghostscript_binary, |
575 ghostscript_options, ghostscript_output, name); | 580 ghostscript_options, ghostscript_output, name); |
576 [errcode, output] = system (command); | 581 [errcode, output] = system (command); |
577 unlink (name); | 582 unlink (name); |
578 if (errcode) | 583 if (errcode) |
579 error ("print: Conversion failed, %s -> %s.", name, ghostscript_output); | 584 error ("print: Conversion failed, %s -> %s.\nError was:\n%s\n", name, ghostscript_output, output); |
580 endif | 585 endif |
581 elseif (is_eps_file && tight_flag && ! doprint) | 586 elseif (is_eps_file && tight_flag && ! doprint) |
582 ## If the saved output file is an eps file, use ghostscript to set a tight bbox. | 587 ## If the saved output file is an eps file, use ghostscript to set a tight bbox. |
583 ## This may result in a smaller or larger bbox geometry. | 588 ## This may result in a smaller or larger bbox geometry. |
584 fix_eps_bbox (name, ghostscript_binary); | 589 fix_eps_bbox (name, ghostscript_binary); |
623 persistent warn_on_no_ghostscript = true | 628 persistent warn_on_no_ghostscript = true |
624 | 629 |
625 box_string = "%%BoundingBox:"; | 630 box_string = "%%BoundingBox:"; |
626 | 631 |
627 ghostscript_options = "-q -dBATCH -dSAFER -dNOPAUSE -dTextAlphaBits=4 -sDEVICE=bbox"; | 632 ghostscript_options = "-q -dBATCH -dSAFER -dNOPAUSE -dTextAlphaBits=4 -sDEVICE=bbox"; |
628 cmd = sprintf ("%s %s '%s' 2>&1", ghostscript_binary, ghostscript_options, eps_file_name); | 633 cmd = sprintf ("\"%s\" %s \"%s\" 2>&1", ghostscript_binary, ghostscript_options, eps_file_name); |
629 [status, output] = system (cmd); | 634 [status, output] = system (cmd); |
630 | 635 |
631 if (status == 0) | 636 if (status == 0) |
632 | 637 |
633 pattern = strcat (box_string, "[^%]*"); | 638 pattern = strcat (box_string, "[^%]*"); |
670 unwind_protect_cleanup | 675 unwind_protect_cleanup |
671 fclose (fid); | 676 fclose (fid); |
672 end_unwind_protect | 677 end_unwind_protect |
673 elseif (warn_on_no_ghostscript) | 678 elseif (warn_on_no_ghostscript) |
674 warn_on_no_ghostscript = false; | 679 warn_on_no_ghostscript = false; |
675 warning ("print.m: Ghostscript could not be used to adjust bounding box.") | 680 warning ("print.m: Ghostscript could not be used to adjust bounding box.\nError was:\n%s\n", output) |
676 endif | 681 endif |
677 | 682 |
678 endfunction | 683 endfunction |
679 | 684 |