2 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
4 # Jockey is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2, or (at your option) any
9 # Jockey is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 """Guess where the Ghostscript executable is
27 and return its absolute path name."""
29 if os.environ.has_key("PATH"):
30 path = os.environ["PATH"]
31 for dir in path.split(os.pathsep):
32 for name in ("gs", "gs.exe", "gswin32c.exe"):
33 g = os.path.join(dir, name)
36 raise Exception, "Ghostscript not found."
39 def __write_contents(self, fp):
40 fp.write(pscanvas.preamble_text)
41 for name, id in self.__font_ids.items():
42 fp.write("/%s {/%s findfont SF} def\n" % (id, name))
43 fp.write("%d %d translate\n" % (-self.bbox[0], -self.bbox[1]))
44 fp.writelines(self.__output_lines)
45 fp.write("showpage end\n")
49 # Don't call pscanvas.T.close, as it creates a
51 basecanvas.T.close(self)
53 def start_gs(self, arg):
54 self.bbox = theme.adjust_bounding_box([xscale(self.__xmin),
59 gs_path = get_gs_path()
61 if self.__output_lines == []:
64 if sys.platform != "win32" and hasattr(os, "popen"):
66 cmdline = "\"%s\" -q %s -g%dx%d -q >/dev/null 2>&1" % \
68 self.bbox[2] - self.bbox[0],
69 self.bbox[3] - self.bbox[1])
70 self.pipe_fp = os.popen(cmdline, "w")
71 self.__write_contents(self.pipe_fp)
73 # XXX should use mktemp, but need to support python<=2.2 as well.
74 fname = tempfile.mktemp("xxx")
75 fp = open(fname, "wb")
76 self.__write_contents(fp)
78 cmdline = "\"%s\" -q %s -g%dx%d -q <%s >NUL" % \
80 self.bbox[2] - self.bbox[0],
81 self.bbox[3] - self.bbox[1], fname)