def dvitypetester(self, advifile): with os.popen("dvitype %s" % advifile) as dvitypefile: dvitypelines = dvitypefile.readlines() dvitypelineno = dvitypelines.index(" \n") + 1 pyxdvifile = io.StringIO() df = dvifile.DVIfile(advifile, debug=1, debugfile=pyxdvifile) while df.readpage(): pass pyxdvifilelines = list(pyxdvifile.getvalue().split("\n")) pyxdvifilelineno = 0 while dvitypelineno < len(dvitypelines) and pyxdvifilelineno < len( pyxdvifilelines): dvitypeline = dvitypelines[dvitypelineno].rstrip() if dvitypeline.startswith("[") and dvitypeline.endswith("]"): dvitypelineno += 1 continue pyxdvifileline = pyxdvifilelines[pyxdvifilelineno].rstrip() if pyxdvifileline.startswith("[") and pyxdvifileline.endswith("]"): pyxdvifilelineno += 1 continue pyxdvifilelinere = (pyxdvifileline.replace("+", "\\+").replace( "(", "\\(").replace(")", "\\)").replace("???", "-?\\d+") + "( warning: \\|h\\|>\\d+!)?" + "$") if re.match(pyxdvifilelinere, dvitypeline): dvitypelineno += 1 pyxdvifilelineno += 1 else: raise ValueError("difference:\n%s\n%s" % (dvitypeline, pyxdvifileline)) # print "difference:" # print "\t", dvitypeline # print "\t", pyxdvifileline # dvitypelineno += 1 # pyxdvifilelineno += 1 # don't be strict about empty tailing lines while dvitypelineno < len( dvitypelines) and not dvitypelines[dvitypelineno].strip(): dvitypelineno += 1 while pyxdvifilelineno < len(pyxdvifilelines) and not pyxdvifilelines[ pyxdvifilelineno].strip(): pyxdvifilelineno += 1 assert dvitypelineno == len(dvitypelines) assert pyxdvifilelineno == len(pyxdvifilelines)
help="optional paper format string") parser.add_option( "-b", "--writebbox", action="store_true", dest="writebbox", default=0, help= "Add bouding box information on PS and PDF when a paperformat is defined") (options, args) = parser.parse_args() if len(args) != 1: parser.error("can process a single dvi-file only") if options.paperformat: options.paperformat = getattr(document.paperformat, options.paperformat) df = dvifile.DVIfile(args[0]) d = document.document() while 1: dvipage = df.readpage() if not dvipage: break if options.paperformat: aligntrafo = trafo.translate(-unit.t_inch, unit.t_inch + paperformat.height) aligneddvipage = canvas.canvas([aligntrafo]) aligneddvipage.insert(dvipage) p = document.page(aligneddvipage, paperformat=paperformat) else: p = document.page(dvipage) d.append(p) if options.writebbox:
# # Copyright (C) 2005-2011 André Wobst <*****@*****.**> # # dvitype is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # epstopng is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with epstopng; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from optparse import OptionParser from pyx import version from pyx.dvi import dvifile parser = OptionParser(usage="usage: %prog dvi-file", version="%prog " + version.version) (options, args) = parser.parse_args() if len(args) != 1: parser.error("can process a single dvi-file only") df = dvifile.DVIfile(args[0], debug=True) while df.readpage(): pass