diff --git a/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100.0.ttf b/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100.0.ttf new file mode 100644 index 000000000..936647c4c Binary files /dev/null and b/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100.0.ttf differ diff --git a/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=drop,wdth=100.ttf b/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=drop,wdth=100.ttf new file mode 100644 index 000000000..936647c4c Binary files /dev/null and b/test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=drop,wdth=100.ttf differ diff --git a/test/subset/data/fonts/Roboto-Variable.ABC.ttf b/test/subset/data/fonts/Roboto-Variable.ABC.ttf new file mode 100644 index 000000000..6cf001fc8 Binary files /dev/null and b/test/subset/data/fonts/Roboto-Variable.ABC.ttf differ diff --git a/test/subset/data/tests/pin_all_at_default.tests b/test/subset/data/tests/pin_all_at_default.tests new file mode 100644 index 000000000..068c8ad96 --- /dev/null +++ b/test/subset/data/tests/pin_all_at_default.tests @@ -0,0 +1,12 @@ +FONTS: +Roboto-Variable.ABC.ttf + +PROFILES: +default.txt + +SUBSETS: +* + +INSTANCES: +wght=drop,wdth=100 +wght=400,wdth=100.0 diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py index 2182643ab..dc3a9028e 100755 --- a/test/subset/generate-expected-outputs.py +++ b/test/subset/generate-expected-outputs.py @@ -27,15 +27,31 @@ def strip_check_sum (ttx_string): ttx_string, count=1) -def generate_expected_output(input_file, unicodes, profile_flags, output_directory, font_name): +def generate_expected_output(input_file, unicodes, profile_flags, instance_flags, output_directory, font_name): fonttools_path = os.path.join(tempfile.mkdtemp (), font_name) args = ["fonttools", "subset", input_file] args.extend(["--drop-tables+=DSIG", "--drop-tables-=sbix", "--unicodes=%s" % unicodes, "--output-file=%s" % fonttools_path]) + #TODO: remove the drop later as instancing support is added to GPOS/GDEF. + if instance_flags: + args.extend(["--drop-tables+=GPOS,GDEF"]) args.extend(profile_flags) check_call(args) + + if instance_flags: + instance_path = os.path.join(tempfile.mkdtemp (), font_name) + args = ["fonttools", "varLib.instancer", + "--no-overlap-flag", + "--no-recalc-bounds", + "--no-recalc-timestamp", + "--output=%s" % instance_path, + fonttools_path] + args.extend(instance_flags) + check_call(args) + fonttools_path = instance_path + with io.StringIO () as fp: with TTFont (fonttools_path) as font: font.saveXML (fp) @@ -50,7 +66,12 @@ def generate_expected_output(input_file, unicodes, profile_flags, output_directo "--drop-tables+=DSIG", "--drop-tables-=sbix"] args.extend(profile_flags) + #TODO: remove the drop later as instancing support is added to GPOS/GDEF. + if instance_flags: + args.extend(["--drop-tables+=GDEF,GPOS", + "--instance=%s" % ','.join(instance_flags)]) check_call(args) + with io.StringIO () as fp: with TTFont (harfbuzz_path) as font: font.saveXML (fp) @@ -84,4 +105,4 @@ for path in args: font_name = test.get_font_name() print("Creating subset %s/%s" % (output_directory, font_name)) generate_expected_output(test.font_path, unicodes, test.get_profile_flags(), - output_directory, font_name) + test.get_instance_flags(), output_directory, font_name) diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index 75f873855..eb70db9f8 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -55,6 +55,9 @@ def run_test (test, should_check_ots): "--drop-tables+=DSIG", "--drop-tables-=sbix"] cli_args.extend (test.get_profile_flags ()) + if test.get_instance_flags (): + cli_args.extend (["--drop-tables+=GPOS,GDEF", + "--instance=%s" % ','.join(test.get_instance_flags ())]) ret = subset_cmd (cli_args) if ret != "success": diff --git a/test/subset/subset_test_suite.py b/test/subset/subset_test_suite.py index a58d01703..5ef4de303 100644 --- a/test/subset/subset_test_suite.py +++ b/test/subset/subset_test_suite.py @@ -5,10 +5,11 @@ import os # A single test in a subset test suite. Identifies a font # a subsetting profile, and a subset to be cut. class Test: - def __init__(self, font_path, profile_path, subset): + def __init__(self, font_path, profile_path, subset, instance): self.font_path = font_path self.profile_path = profile_path self.subset = subset + self.instance = instance def unicodes(self): import re @@ -20,23 +21,38 @@ class Test: else: return ",".join("%X" % ord(c) for (i, c) in enumerate(self.subset)) + def instance_name(self): + if not self.instance: + return self.instance + else: + s = "." + self.instance.replace(':', '-') + return s + def get_profile_flags(self): with open (self.profile_path, mode="r", encoding="utf-8") as f: return f.read().splitlines() + def get_instance_flags(self): + if not self.instance: + return [] + else: + return self.instance.split(',') + def get_font_name(self): font_base_name = os.path.basename(self.font_path) font_base_name_parts = os.path.splitext(font_base_name) profile_name = os.path.splitext(os.path.basename(self.profile_path))[0] if self.unicodes() == "*": - return "%s.%s.retain-all-codepoint%s" % (font_base_name_parts[0], + return "%s.%s.retain-all-codepoint%s%s" % (font_base_name_parts[0], profile_name, + self.instance_name(), font_base_name_parts[1]) else: - return "%s.%s.%s%s" % (font_base_name_parts[0], + return "%s.%s.%s%s%s" % (font_base_name_parts[0], profile_name, self.unicodes(), + self.instance_name(), font_base_name_parts[1]) def get_font_extension(self): @@ -53,6 +69,7 @@ class SubsetTestSuite: self.fonts = [] self.profiles = [] self.subsets = [] + self.instances = [] self._parse(definition) def get_output_directory(self): @@ -73,7 +90,11 @@ class SubsetTestSuite: for profile in self.profiles: profile = os.path.join(self._base_path(), "profiles", profile) for subset in self.subsets: - yield Test(font, profile, subset) + if self.instances: + for instance in self.instances: + yield Test(font, profile, subset, instance) + else: + yield Test(font, profile, subset, "") def _base_path(self): return os.path.dirname(os.path.dirname(self.test_path)) @@ -82,7 +103,8 @@ class SubsetTestSuite: destinations = { "FONTS:": self.fonts, "PROFILES:": self.profiles, - "SUBSETS:": self.subsets + "SUBSETS:": self.subsets, + "INSTANCES:": self.instances } current_destination = None