From 91df98b41fc04b20b4620d294b21c53a5304aece Mon Sep 17 00:00:00 2001 From: jvr Date: Fri, 24 May 2002 18:36:57 +0000 Subject: [PATCH] test script: batch roundtripper git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@261 4cde692c-a291-49d1-8350-778aa11640f8 --- Tools/ttroundtrip | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 Tools/ttroundtrip diff --git a/Tools/ttroundtrip b/Tools/ttroundtrip new file mode 100755 index 000000000..e694f32be --- /dev/null +++ b/Tools/ttroundtrip @@ -0,0 +1,71 @@ +#! /usr/bin/env python + +"""ttroundtrip font1 ... fontN +Dump each font as TTX, compile again to TTF or OTF and dump again. +Then do a diff on the two TTX files. Log problems and diffs to a +file called "report.txt" in the current directory. This is only +for testing FontTools/TTX, the resulting files are deleted +afterwards.""" + + +import sys +import os +import tempfile + + +report = open("report.txt", "w") + + +class Error(Exception): pass + + +def doCommand(cmd, verbose=1, okresult=None): + print "--> ", cmd + f = os.popen(cmd) + lines = [] + for line in f: + if verbose: + sys.stdout.write(line) + lines.append(line) + result = os.wait()[1] >> 8 + if result and result <> okresult: + raise Error, result + return "".join(lines) + + +if not sys.argv[1:]: + print __doc__ +else: + for ttFile in sys.argv[1:]: + print "--- roundtripping %s ---" % ttFile + fn = os.path.basename(ttFile) + xmlFile1 = tempfile.mktemp(".%s.ttx1" % fn) + ttFile2 = tempfile.mktemp(".%s" % fn) + xmlFile2 = tempfile.mktemp(".%s.ttx2" % fn) + + try: + cmd = 'ttdump -i -f "%s" "%s"' % (ttFile, xmlFile1) + doCommand(cmd, 0) + cmd = 'ttcompile -f "%s" "%s"' % (xmlFile1, ttFile2) + doCommand(cmd, 0) + cmd = 'ttdump -i -f "%s" "%s"' % (ttFile2, xmlFile2) + doCommand(cmd, 0) + cmd = 'diff -c2 -I ".*modified value\|checkSumAdjustment.*" "%s" "%s"' % (xmlFile1, xmlFile2) + diff = doCommand(cmd, 0, okresult=1) + if diff: + report.write("=============================================================\n") + report.write("%s\n" % xmlFile1) + report.write("%s\n" % xmlFile2) + report.write("-------------------------------------------------------------\n") + report.write(diff) + print diff + print "--- done ---" + except Error, why: + report.write("=============================================================\n") + report.write("%s\n" % ttFile) + report.write("*** round tripping aborted (code %s) ***\n" % why) + report.write("-------------------------------------------------------------\n") + print "*** round tripping aborted (code %s) ***" % why + for tmpFile in (xmlFile1, ttFile2, xmlFile2): + if os.path.exists(tmpFile): + os.remove(tmpFile)