2018-01-26 21:57:48 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Pre-generates the expected output subset files (via fonttools) for
|
|
|
|
# specified subset test suite(s).
|
|
|
|
|
2018-01-26 22:25:39 +00:00
|
|
|
import io
|
2018-01-26 21:57:48 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from subprocess import check_call
|
|
|
|
from subset_test_suite import SubsetTestSuite
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
print "Usage: generate-expected-outputs.py <test suite file> ..."
|
|
|
|
|
|
|
|
|
|
|
|
def generate_expected_output(input_file, unicodes, output_path):
|
|
|
|
check_call(["fonttools", "subset",
|
2018-02-27 02:51:56 +00:00
|
|
|
input_file,
|
|
|
|
"--notdef-outline",
|
|
|
|
"--name-IDs=*",
|
|
|
|
"--name-languages=*",
|
|
|
|
"--name-legacy",
|
|
|
|
"--drop-tables+=DSIG,GPOS,GSUB,GDEF",
|
|
|
|
"--unicodes=%s" % unicodes,
|
|
|
|
"--output-file=%s" % output_path])
|
2018-01-26 21:57:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
if not args:
|
|
|
|
usage()
|
|
|
|
|
|
|
|
for path in args:
|
2018-01-26 22:25:39 +00:00
|
|
|
with io.open(path, mode="r", encoding="utf-8") as f:
|
2018-01-26 21:57:48 +00:00
|
|
|
test_suite = SubsetTestSuite(path, f.read())
|
|
|
|
output_directory = test_suite.get_output_directory()
|
|
|
|
|
|
|
|
print "Generating output files for %s" % output_directory
|
|
|
|
for test in test_suite.tests():
|
|
|
|
unicodes = test.unicodes()
|
|
|
|
font_name = test.get_font_name()
|
|
|
|
print "Creating subset %s/%s" % (output_directory, font_name)
|
|
|
|
generate_expected_output(test.font_path, unicodes,
|
|
|
|
os.path.join(output_directory,
|
|
|
|
font_name))
|