[subset] Add a test for CFF2 instancing.

Adds option to disable the fonttools comparison check in the test. This is needed since CFF2 instancing is not yet supported in fonttools.
This commit is contained in:
Garret Rieger 2023-02-22 20:23:34 +00:00
parent 33cc3121d4
commit ddd0f7f40b
7 changed files with 36 additions and 14 deletions

View File

@ -60,6 +60,7 @@ EXTRA_DIST += \
expected/full_instance \
expected/instance_feature_variations \
expected/instantiate_glyf \
expected/instantiate_cff2 \
expected/pin_all_at_default \
expected/instance_no_double_free \
expected/mvar_full_instance \

View File

@ -51,6 +51,7 @@ TESTS = \
tests/full_instance.tests \
tests/instance_feature_variations.tests \
tests/instantiate_glyf.tests \
tests/instantiate_cff2.tests \
tests/pin_all_at_default.tests \
tests/instance_no_double_free.tests \
tests/mvar_full_instance.tests \

View File

@ -0,0 +1,14 @@
FONTS:
AdobeVFPrototype.otf
PROFILES:
default.txt
SUBSETS:
*
INSTANCES:
wght=650,CNTR=50
OPTIONS:
no_fonttools

View File

@ -27,9 +27,9 @@ def strip_check_sum (ttx_string):
ttx_string, count=1)
def generate_expected_output(input_file, unicodes, profile_flags, instance_flags, output_directory, font_name):
def generate_expected_output(input_file, unicodes, profile_flags, instance_flags, output_directory, font_name, no_fonttools):
input_path = input_file
if instance_flags:
if not no_fonttools and instance_flags:
instance_path = os.path.join(tempfile.mkdtemp (), font_name)
args = ["fonttools", "varLib.instancer",
"--no-overlap-flag",
@ -50,12 +50,13 @@ def generate_expected_output(input_file, unicodes, profile_flags, instance_flags
"--unicodes=%s" % unicodes,
"--output-file=%s" % fonttools_path])
args.extend(profile_flags)
check_call(args)
if not no_fonttools:
check_call(args)
with io.StringIO () as fp:
with TTFont (fonttools_path) as font:
font.saveXML (fp)
fonttools_ttx = strip_check_sum (fp.getvalue ())
with io.StringIO () as fp:
with TTFont (fonttools_path) as font:
font.saveXML (fp)
fonttools_ttx = strip_check_sum (fp.getvalue ())
harfbuzz_path = os.path.join(tempfile.mkdtemp (), font_name)
args = [
@ -75,7 +76,7 @@ def generate_expected_output(input_file, unicodes, profile_flags, instance_flags
font.saveXML (fp)
harfbuzz_ttx = strip_check_sum (fp.getvalue ())
if harfbuzz_ttx != fonttools_ttx:
if not no_fonttools and harfbuzz_ttx != fonttools_ttx:
for line in unified_diff (fonttools_ttx.splitlines (1), harfbuzz_ttx.splitlines (1), fonttools_path, harfbuzz_path):
sys.stdout.write (line)
sys.stdout.flush ()
@ -101,6 +102,7 @@ for path in args:
for test in test_suite.tests():
unicodes = test.unicodes()
font_name = test.get_font_name()
no_fonttools = ("no_fonttools" in test.options)
print("Creating subset %s/%s" % (output_directory, font_name))
generate_expected_output(test.font_path, unicodes, test.get_profile_flags(),
test.get_instance_flags(), output_directory, font_name)
test.get_instance_flags(), output_directory, font_name, no_fonttools=no_fonttools)

View File

@ -52,6 +52,7 @@ tests = [
'32bit_var_store',
'pin_all_at_default',
'instantiate_glyf',
'instantiate_cff2',
'full_instance',
'instance_feature_variations',
'instance_no_double_free',

View File

@ -5,11 +5,12 @@ 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, instance):
def __init__(self, font_path, profile_path, subset, instance, options):
self.font_path = font_path
self.profile_path = profile_path
self.subset = subset
self.instance = instance
self.options = options
def unicodes(self):
import re
@ -70,6 +71,7 @@ class SubsetTestSuite:
self.profiles = []
self.subsets = []
self.instances = []
self.options = []
self._parse(definition)
def get_output_directory(self):
@ -90,11 +92,11 @@ class SubsetTestSuite:
for profile in self.profiles:
profile = os.path.join(self._base_path(), "profiles", profile)
for subset in self.subsets:
if self.instances:
if self.instances:
for instance in self.instances:
yield Test(font, profile, subset, instance)
yield Test(font, profile, subset, instance, options=self.options)
else:
yield Test(font, profile, subset, "")
yield Test(font, profile, subset, "", options=self.options)
def _base_path(self):
return os.path.dirname(os.path.dirname(self.test_path))
@ -104,7 +106,8 @@ class SubsetTestSuite:
"FONTS:": self.fonts,
"PROFILES:": self.profiles,
"SUBSETS:": self.subsets,
"INSTANCES:": self.instances
"INSTANCES:": self.instances,
"OPTIONS:": self.options,
}
current_destination = None