3
"""usage: ttroundtrip [options] font1 ... fontN
5
Dump each TT/OT font as a TTX file, compile again to TTF or OTF
6
and dump again. Then do a diff on the two TTX files. Append problems
7
and diffs to a file called "report.txt" in the current directory.
8
This is only for testing FontTools/TTX, the resulting files are
11
This tool supports some of ttx's command line options (-i, -t
12
and -x). Specifying -t or -x implies ttx -m <originalfile> on
22
from fontTools import ttx
24
class Error(Exception): pass
32
def roundTrip(ttFile1, options, report):
33
fn = os.path.basename(ttFile1)
34
xmlFile1 = tempfile.mktemp(".%s.ttx1" % fn)
35
ttFile2 = tempfile.mktemp(".%s" % fn)
36
xmlFile2 = tempfile.mktemp(".%s.ttx2" % fn)
39
ttx.ttDump(ttFile1, xmlFile1, options)
40
if options.onlyTables or options.skipTables:
41
options.mergeFile = ttFile1
42
ttx.ttCompile(xmlFile1, ttFile2, options)
43
options.mergeFile = None
44
ttx.ttDump(ttFile2, xmlFile2, options)
46
diffcmd = 'diff -c2 -I ".*modified value\|checkSumAdjustment.*" "%s" "%s"' % (xmlFile1, xmlFile2)
47
output = os.popen(diffcmd, "r", 1)
50
line = output.readline()
53
sys.stdout.write(line)
56
report.write("=============================================================\n")
57
report.write(" \"%s\" differs after round tripping\n" % ttFile1)
58
report.write("-------------------------------------------------------------\n")
59
report.writelines(lines)
61
print "(TTX files are the same)"
63
for tmpFile in (xmlFile1, ttFile2, xmlFile2):
64
if os.path.exists(tmpFile):
70
rawOptions, files = getopt.getopt(args, "it:x:")
71
except getopt.GetoptError:
77
report = open("report.txt", "a+")
78
options = ttx.Options(rawOptions, len(files))
81
roundTrip(ttFile, options, report)
82
except KeyboardInterrupt:
86
print "*** round tripping aborted ***"
88
report.write("=============================================================\n")
89
report.write(" An exception occurred while round tripping")
90
report.write(" \"%s\"\n" % ttFile)
91
traceback.print_exc(file=report)
92
report.write("-------------------------------------------------------------\n")