- comment on not using strokecolor for patterns
[PyX/mjg.git] / contrib / dvips.py
blob940887e866b703c478c3b76eeff41739f0d282bb
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-1 -*-
5 # Copyright (C) 2003 Jörg Lehmann <joergl@users.sourceforge.net>
7 # epstopng is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # epstopng is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with epstopng; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 import getopt, sys
23 from pyx import dvifile, canvas, trafo, unit
26 progname = "dvips v0.1: dvi to ps converter based on PyX"
29 def dvips(dviname, psname, vshift="-1 t cm"):
30 fontmap = dvifile.readfontmap(["psfonts.map"])
31 df = dvifile.dvifile(dviname, fontmap=fontmap)
32 d = canvas.document()
33 nr = 1
34 while 1:
35 c = df.readpage()
36 if c is None: break
37 print "[%d]" % nr,
38 sys.stdout.flush()
39 nr += 1
40 p = canvas.page(paperformat="a4")
41 p.insert(c, [trafo.translate(0, unit.length(vshift)+p.bbox().height())])
42 d.append(p)
43 d.writePSfile(psname)
46 def usage():
47 print progname
48 print "Copyright (C) 2004 Jörg Lehmann <joergl@users.sourceforge.net>"
49 print "usage: dvips [options] <eps-file>"
50 print "-h, --help: show this help"
51 print "-o, --output <file>: output file name (optional)"
54 def main():
55 try:
56 opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output"])
57 except getopt.GetoptError:
58 # print help information and exit:
59 usage()
60 sys.exit(2)
61 output = None
62 for o, a in opts:
63 if o in ("-h", "--help"):
64 usage()
65 sys.exit()
66 if o in ("-o", "--output"):
67 output = a
68 if len(args) == 1:
69 input = args[0]
70 elif len(args):
71 raise RuntimeError("can't handle several input files")
72 else:
73 raise RuntimeError("must specify an input file (reading from stdin is not yet supported)")
74 if not input.endswith(".dvi"):
75 input = input + ".dvi"
76 if output is None:
77 output = input[:-4] + ".ps"
78 dvips(input, output)
80 def profilefunction(f):
81 import hotshot, hotshot.stats
82 prof = hotshot.Profile("test.prof")
83 prof.runcall(f)
84 prof.close()
85 stats = hotshot.stats.load("test.prof")
86 stats.strip_dirs()
87 stats.sort_stats('time', 'calls')
88 stats.print_stats(10)
90 if __name__ == "__main__":
91 main()
92 # profilefunction(main)