blob: 2e94e4e78d4a94bf01cb9bf2bbb3b7690f1fe404 [file] [log] [blame]
Ebrahim Byagowi8d199072020-02-19 14:56:55 +03301#!/usr/bin/env python3
Garret Rieger4cdae912018-01-26 13:57:48 -08002
3# Pre-generates the expected output subset files (via fonttools) for
4# specified subset test suite(s).
5
6import os
7import sys
8
9from subprocess import check_call
10from subset_test_suite import SubsetTestSuite
11
12
13def usage():
cclaussb5c12b92018-12-30 13:07:28 +010014 print("Usage: generate-expected-outputs.py <test suite file> ...")
Garret Rieger4cdae912018-01-26 13:57:48 -080015
16
Garret Rieger5241d7f2018-02-27 13:15:40 -080017def generate_expected_output(input_file, unicodes, profile_flags, output_path):
18 args = ["fonttools", "subset", input_file]
Garret Rieger5241d7f2018-02-27 13:15:40 -080019 args.extend(["--notdef-outline",
Qunxin Liu36a5c042020-01-21 13:37:28 -080020 "--layout-features=*",
Michiharu Ariza66361c72019-06-05 14:51:04 -070021 "--drop-tables+=DSIG,GPOS,GSUB,GDEF",
Qunxin Liu36a5c042020-01-21 13:37:28 -080022 "--drop-tables-=sbix",
Garret Rieger5241d7f2018-02-27 13:15:40 -080023 "--unicodes=%s" % unicodes,
24 "--output-file=%s" % output_path])
Garret Riegerc740c862019-05-16 10:57:33 -070025 args.extend(profile_flags)
Garret Rieger5241d7f2018-02-27 13:15:40 -080026 check_call(args)
Garret Rieger4cdae912018-01-26 13:57:48 -080027
28
29args = sys.argv[1:]
30if not args:
31 usage()
32
33for path in args:
Ebrahim Byagowiad871552020-05-29 00:11:19 +043034 with open(path, mode="r", encoding="utf-8") as f:
Garret Rieger4cdae912018-01-26 13:57:48 -080035 test_suite = SubsetTestSuite(path, f.read())
36 output_directory = test_suite.get_output_directory()
37
cclaussb5c12b92018-12-30 13:07:28 +010038 print("Generating output files for %s" % output_directory)
Garret Rieger4cdae912018-01-26 13:57:48 -080039 for test in test_suite.tests():
40 unicodes = test.unicodes()
41 font_name = test.get_font_name()
cclaussb5c12b92018-12-30 13:07:28 +010042 print("Creating subset %s/%s" % (output_directory, font_name))
Garret Rieger5241d7f2018-02-27 13:15:40 -080043 generate_expected_output(test.font_path, unicodes, test.get_profile_flags(),
44 os.path.join(output_directory,
45 font_name))