diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index 3efb2548c..313b1a398 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -512,13 +512,28 @@ def _add_MVAR(font, masterModel, master_ttfs, axisTags): lastTableTag = None fontTable = None tables = None + # HACK: we need to special-case post.underlineThickness and .underlinePosition + # and unilaterally/arbitrarily define a sentinel value to distinguish the case + # when a post table is present in a given master simply because that's where + # the glyph names in TrueType must be stored, but the underline values are not + # meant to be used for building MVAR's deltas. The value of -0x8000 (-36768) + # the minimum FWord (int16) value, was chosen for its unlikelyhood to appear + # in real-world underline position/thickness values. + specialTags = {"unds": -0x8000, "undo": -0x8000} for tag, (tableTag, itemName) in sorted(MVAR_ENTRIES.items(), key=lambda kv: kv[1]): if tableTag != lastTableTag: tables = fontTable = None if tableTag in font: fontTable = font[tableTag] - tables = [master[tableTag] if tableTag in master else None - for master in master_ttfs] + tables = [] + for master in master_ttfs: + if tableTag not in master or ( + tag in specialTags + and getattr(master[tableTag], itemName) == specialTags[tag] + ): + tables.append(None) + else: + tables.append(master[tableTag]) lastTableTag = tableTag if tables is None: continue diff --git a/Tests/varLib/data/SparseMasters.designspace b/Tests/varLib/data/SparseMasters.designspace new file mode 100644 index 000000000..327fb43b9 --- /dev/null +++ b/Tests/varLib/data/SparseMasters.designspace @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Bold.ttx b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Bold.ttx new file mode 100644 index 000000000..55d686e3d --- /dev/null +++ b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Bold.ttx @@ -0,0 +1,419 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layer Font + + + Bold + + + 0.000;NONE;LayerFont-Bold + + + Layer Font Bold + + + Version 0.000 + + + LayerFont-Bold + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Medium.ttx b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Medium.ttx new file mode 100644 index 000000000..eb3c74547 --- /dev/null +++ b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Medium.ttx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Regular.ttx b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Regular.ttx new file mode 100644 index 000000000..e013e0b7e --- /dev/null +++ b/Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Regular.ttx @@ -0,0 +1,419 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layer Font + + + Regular + + + 0.000;NONE;LayerFont-Regular + + + Layer Font Regular + + + Version 0.000 + + + LayerFont-Regular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/SparseMasters.ttx b/Tests/varLib/data/test_results/SparseMasters.ttx new file mode 100644 index 000000000..99a80bfb5 --- /dev/null +++ b/Tests/varLib/data/test_results/SparseMasters.ttx @@ -0,0 +1,660 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Weight + + + Layer Font + + + Regular + + + 0.000;NONE;LayerFont-Regular + + + Layer Font Regular + + + Version 0.000 + + + LayerFont-Regular + + + Weight + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wght + 0x0 + 350.0 + 350.0 + 625.0 + 256 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/varLib_test.py b/Tests/varLib/varLib_test.py index 16747fd7a..831d8b832 100644 --- a/Tests/varLib/varLib_test.py +++ b/Tests/varLib/varLib_test.py @@ -352,6 +352,15 @@ class BuildTest(unittest.TestCase): tables = [table_tag for table_tag in varfont.keys() if table_tag != "head"] self.expect_ttx(varfont, expected_ttx_path, tables) + def test_varlib_build_sparse_masters(self): + ds_path = self.get_test_input("SparseMasters.designspace") + expected_ttx_path = self.get_test_output("SparseMasters.ttx") + + varfont, _, _ = build(ds_path) + varfont = reload_font(varfont) + tables = [table_tag for table_tag in varfont.keys() if table_tag != "head"] + self.expect_ttx(varfont, expected_ttx_path, tables) + def test_load_masters_layerName_without_required_font(): ds = DesignSpaceDocument()