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