git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@262 4cde692c-a291-49d1-8350-778aa11640f8
71 lines
2.1 KiB
Python
Executable File
71 lines
2.1 KiB
Python
Executable File
#! /usr/bin/env python
|
|
|
|
"""ttroundtrip font1 ... fontN
|
|
Dump each TT/OT font as a TTX file, 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)
|