optional textdx/textdy columns to the text style added
[PyX/mjg.git] / contrib / dviconvert.py
blob934d7fe3a772541849b08256714249c2035f7556
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-1 -*-
5 # Copyright (C) 2005 André Wobst <wobsta@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
21 from optparse import OptionParser
22 from pyx import *
23 from pyx import bbox, dvifile, version
25 parser = OptionParser(usage="usage: %prog [-b] [-p paperformat] -o output-file dvi-file",
26 version="%prog " + version.version)
27 parser.add_option("-o", "--output",
28 type="string", dest="output",
29 help="output-file")
30 parser.add_option("-p", "--paperformat",
31 type="string", dest="paperformat", default=None,
32 help="optional paper format string")
33 parser.add_option("-b", "--writebbox",
34 action="store_true", dest="writebbox", default=0,
35 help="Add bouding box information on PS and PDF when a paperformat is defined")
36 (options, args) = parser.parse_args()
37 if len(args) != 1:
38 parser.error("can process a single dvi-file only")
40 if options.paperformat:
41 options.paperformat = getattr(document.paperformat, options.paperformat)
42 df = dvifile.dvifile(args[0], dvifile.readfontmap(["psfonts.map"]))
43 d = document.document()
44 while 1:
45 dvipage = df.readpage()
46 if not dvipage:
47 break
48 if options.paperformat:
49 aligntrafo = trafo.translate(-unit.t_inch, unit.t_inch + paperformat.height)
50 aligneddvipage = canvas.canvas([aligntrafo])
51 aligneddvipage.insert(dvipage)
52 p = document.page(aligneddvipage, paperformat=paperformat)
53 else:
54 p = document.page(dvipage)
55 d.append(p)
56 if options.writebbox:
57 d.writetofile(options.output)
58 else:
59 d.writetofile(options.output, writebbox=1)