[instance] update scripts for testing instancing
This commit is contained in:
parent
be8e8e8c80
commit
f1a69ff1b9
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,12 @@
|
||||||
|
FONTS:
|
||||||
|
Roboto-Variable.ABC.ttf
|
||||||
|
|
||||||
|
PROFILES:
|
||||||
|
default.txt
|
||||||
|
|
||||||
|
SUBSETS:
|
||||||
|
*
|
||||||
|
|
||||||
|
INSTANCES:
|
||||||
|
wght=drop,wdth=100
|
||||||
|
wght=400,wdth=100.0
|
|
@ -27,15 +27,31 @@ def strip_check_sum (ttx_string):
|
||||||
ttx_string, count=1)
|
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)
|
fonttools_path = os.path.join(tempfile.mkdtemp (), font_name)
|
||||||
args = ["fonttools", "subset", input_file]
|
args = ["fonttools", "subset", input_file]
|
||||||
args.extend(["--drop-tables+=DSIG",
|
args.extend(["--drop-tables+=DSIG",
|
||||||
"--drop-tables-=sbix",
|
"--drop-tables-=sbix",
|
||||||
"--unicodes=%s" % unicodes,
|
"--unicodes=%s" % unicodes,
|
||||||
"--output-file=%s" % fonttools_path])
|
"--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)
|
args.extend(profile_flags)
|
||||||
check_call(args)
|
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 io.StringIO () as fp:
|
||||||
with TTFont (fonttools_path) as font:
|
with TTFont (fonttools_path) as font:
|
||||||
font.saveXML (fp)
|
font.saveXML (fp)
|
||||||
|
@ -50,7 +66,12 @@ def generate_expected_output(input_file, unicodes, profile_flags, output_directo
|
||||||
"--drop-tables+=DSIG",
|
"--drop-tables+=DSIG",
|
||||||
"--drop-tables-=sbix"]
|
"--drop-tables-=sbix"]
|
||||||
args.extend(profile_flags)
|
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)
|
check_call(args)
|
||||||
|
|
||||||
with io.StringIO () as fp:
|
with io.StringIO () as fp:
|
||||||
with TTFont (harfbuzz_path) as font:
|
with TTFont (harfbuzz_path) as font:
|
||||||
font.saveXML (fp)
|
font.saveXML (fp)
|
||||||
|
@ -84,4 +105,4 @@ for path in args:
|
||||||
font_name = test.get_font_name()
|
font_name = test.get_font_name()
|
||||||
print("Creating subset %s/%s" % (output_directory, font_name))
|
print("Creating subset %s/%s" % (output_directory, font_name))
|
||||||
generate_expected_output(test.font_path, unicodes, test.get_profile_flags(),
|
generate_expected_output(test.font_path, unicodes, test.get_profile_flags(),
|
||||||
output_directory, font_name)
|
test.get_instance_flags(), output_directory, font_name)
|
||||||
|
|
|
@ -55,6 +55,9 @@ def run_test (test, should_check_ots):
|
||||||
"--drop-tables+=DSIG",
|
"--drop-tables+=DSIG",
|
||||||
"--drop-tables-=sbix"]
|
"--drop-tables-=sbix"]
|
||||||
cli_args.extend (test.get_profile_flags ())
|
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)
|
ret = subset_cmd (cli_args)
|
||||||
|
|
||||||
if ret != "success":
|
if ret != "success":
|
||||||
|
|
|
@ -5,10 +5,11 @@ import os
|
||||||
# A single test in a subset test suite. Identifies a font
|
# A single test in a subset test suite. Identifies a font
|
||||||
# a subsetting profile, and a subset to be cut.
|
# a subsetting profile, and a subset to be cut.
|
||||||
class Test:
|
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.font_path = font_path
|
||||||
self.profile_path = profile_path
|
self.profile_path = profile_path
|
||||||
self.subset = subset
|
self.subset = subset
|
||||||
|
self.instance = instance
|
||||||
|
|
||||||
def unicodes(self):
|
def unicodes(self):
|
||||||
import re
|
import re
|
||||||
|
@ -20,23 +21,38 @@ class Test:
|
||||||
else:
|
else:
|
||||||
return ",".join("%X" % ord(c) for (i, c) in enumerate(self.subset))
|
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):
|
def get_profile_flags(self):
|
||||||
with open (self.profile_path, mode="r", encoding="utf-8") as f:
|
with open (self.profile_path, mode="r", encoding="utf-8") as f:
|
||||||
return f.read().splitlines()
|
return f.read().splitlines()
|
||||||
|
|
||||||
|
def get_instance_flags(self):
|
||||||
|
if not self.instance:
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
return self.instance.split(',')
|
||||||
|
|
||||||
def get_font_name(self):
|
def get_font_name(self):
|
||||||
font_base_name = os.path.basename(self.font_path)
|
font_base_name = os.path.basename(self.font_path)
|
||||||
font_base_name_parts = os.path.splitext(font_base_name)
|
font_base_name_parts = os.path.splitext(font_base_name)
|
||||||
profile_name = os.path.splitext(os.path.basename(self.profile_path))[0]
|
profile_name = os.path.splitext(os.path.basename(self.profile_path))[0]
|
||||||
|
|
||||||
if self.unicodes() == "*":
|
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,
|
profile_name,
|
||||||
|
self.instance_name(),
|
||||||
font_base_name_parts[1])
|
font_base_name_parts[1])
|
||||||
else:
|
else:
|
||||||
return "%s.%s.%s%s" % (font_base_name_parts[0],
|
return "%s.%s.%s%s%s" % (font_base_name_parts[0],
|
||||||
profile_name,
|
profile_name,
|
||||||
self.unicodes(),
|
self.unicodes(),
|
||||||
|
self.instance_name(),
|
||||||
font_base_name_parts[1])
|
font_base_name_parts[1])
|
||||||
|
|
||||||
def get_font_extension(self):
|
def get_font_extension(self):
|
||||||
|
@ -53,6 +69,7 @@ class SubsetTestSuite:
|
||||||
self.fonts = []
|
self.fonts = []
|
||||||
self.profiles = []
|
self.profiles = []
|
||||||
self.subsets = []
|
self.subsets = []
|
||||||
|
self.instances = []
|
||||||
self._parse(definition)
|
self._parse(definition)
|
||||||
|
|
||||||
def get_output_directory(self):
|
def get_output_directory(self):
|
||||||
|
@ -73,7 +90,11 @@ class SubsetTestSuite:
|
||||||
for profile in self.profiles:
|
for profile in self.profiles:
|
||||||
profile = os.path.join(self._base_path(), "profiles", profile)
|
profile = os.path.join(self._base_path(), "profiles", profile)
|
||||||
for subset in self.subsets:
|
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):
|
def _base_path(self):
|
||||||
return os.path.dirname(os.path.dirname(self.test_path))
|
return os.path.dirname(os.path.dirname(self.test_path))
|
||||||
|
@ -82,7 +103,8 @@ class SubsetTestSuite:
|
||||||
destinations = {
|
destinations = {
|
||||||
"FONTS:": self.fonts,
|
"FONTS:": self.fonts,
|
||||||
"PROFILES:": self.profiles,
|
"PROFILES:": self.profiles,
|
||||||
"SUBSETS:": self.subsets
|
"SUBSETS:": self.subsets,
|
||||||
|
"INSTANCES:": self.instances
|
||||||
}
|
}
|
||||||
|
|
||||||
current_destination = None
|
current_destination = None
|
||||||
|
|
Loading…
Reference in New Issue