deco.arrow: fix arrows at pos=0
[PyX/mjg.git] / contrib / dviconvert.py
blob9995329304b5e9f57cc893921549fa03c35e544f
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
5 # Copyright (C) 2005-2011 André Wobst <wobsta@users.sourceforge.net>
7 # dviconvert 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
21 import sys, os
22 sys.path.insert(0, "%s/.." % (os.path.dirname(__file__) or "."))
24 from optparse import OptionParser
25 from pyx import *
26 from pyx import bbox, version
27 from pyx.dvi import dvifile
29 parser = OptionParser(usage="usage: %prog [-b] [-p paperformat] -o output-file dvi-file",
30 version="%prog " + version.version)
31 parser.add_option("-o", "--output",
32 type="string", dest="output",
33 help="output-file")
34 parser.add_option("-p", "--paperformat",
35 type="string", dest="paperformat", default=None,
36 help="optional paper format string")
37 parser.add_option("-b", "--writebbox",
38 action="store_true", dest="writebbox", default=0,
39 help="Add bouding box information on PS and PDF when a paperformat is defined")
40 (options, args) = parser.parse_args()
41 if len(args) != 1:
42 parser.error("can process a single dvi-file only")
44 if options.paperformat:
45 options.paperformat = getattr(document.paperformat, options.paperformat)
46 df = dvifile.DVIfile(args[0])
47 d = document.document()
48 while 1:
49 dvipage = df.readpage()
50 if not dvipage:
51 break
52 if options.paperformat:
53 aligntrafo = trafo.translate(unit.t_inch, -unit.t_inch + options.paperformat.height)
54 aligneddvipage = canvas.canvas([aligntrafo])
55 aligneddvipage.insert(dvipage)
56 p = document.page(aligneddvipage, paperformat=options.paperformat, centered=0)
57 else:
58 p = document.page(dvipage)
59 d.append(p)
60 if options.writebbox:
61 d.writetofile(options.output)
62 else:
63 d.writetofile(options.output, writebbox=1)