1#!/usr/bin/env python
2
3# Pre-generates the expected output subset files (via fonttools) for
4# specified subset test suite(s).
5
6import io
7import os
8import sys
9
10from subprocess import check_call
11from subset_test_suite import SubsetTestSuite
12
13
14def usage():
15	print "Usage: generate-expected-outputs.py <test suite file> ..."
16
17
18def generate_expected_output(input_file, unicodes, profile_flags, output_path):
19	args = ["fonttools", "subset", input_file]
20	args.extend(profile_flags)
21	args.extend(["--notdef-outline",
22		     "--name-IDs=*",
23		     "--name-languages=*",
24		     "--name-legacy",
25		     "--drop-tables+=DSIG,GPOS,GSUB,GDEF",
26		     "--unicodes=%s" % unicodes,
27		     "--output-file=%s" % output_path])
28	check_call(args)
29
30
31args = sys.argv[1:]
32if not args:
33	usage()
34
35for path in args:
36	with io.open(path, mode="r", encoding="utf-8") as f:
37		test_suite = SubsetTestSuite(path, f.read())
38		output_directory = test_suite.get_output_directory()
39
40		print "Generating output files for %s" % output_directory
41		for test in test_suite.tests():
42			unicodes = test.unicodes()
43			font_name = test.get_font_name()
44			print "Creating subset %s/%s" % (output_directory, font_name)
45			generate_expected_output(test.font_path, unicodes, test.get_profile_flags(),
46						 os.path.join(output_directory,
47							      font_name))
48