From 7d947c9fd8d6237dd529ced102ac69e8f548550c Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 15 Jan 2019 16:16:40 +0000 Subject: [PATCH 1/3] [varLib] use magic 0x8000 to ignore post.underline* for MVAR https://github.com/googlei18n/ufo2ft/issues/308#issuecomment-454079704 https://github.com/googlei18n/ufo2ft/pull/310 --- Lib/fontTools/varLib/__init__.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index 3efb2548c..e75b80bc8 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -512,13 +512,31 @@ 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 in master: + if ( + tag in specialTags + and getattr(master[tableTag], itemName) == specialTags[tag] + ): + tables.append(None) + else: + tables.append(master[tableTag]) + else: + tables.append(None) lastTableTag = tableTag if tables is None: continue From 93e791ab246ef7954b2b41a52cc096eb827c3cbf Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 15 Jan 2019 18:19:19 +0000 Subject: [PATCH 2/3] [varLib] use magic -0x8000 to ignore post.underline* for MVAR googlei18n/ufo2ft#308 (comment) googlei18n/ufo2ft#310 --- Lib/fontTools/varLib/__init__.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index e75b80bc8..313b1a398 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -516,10 +516,10 @@ def _add_MVAR(font, masterModel, master_ttfs, axisTags): # 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) + # 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} + 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 @@ -527,16 +527,13 @@ def _add_MVAR(font, masterModel, master_ttfs, axisTags): fontTable = font[tableTag] tables = [] for master in master_ttfs: - if tableTag in master: - if ( - tag in specialTags - and getattr(master[tableTag], itemName) == specialTags[tag] - ): - tables.append(None) - else: - tables.append(master[tableTag]) - else: + 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 From 7740d1736c9c787972d72ec9f9c6d37a31ceaca4 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 15 Jan 2019 19:31:20 +0000 Subject: [PATCH 3/3] varLib_test: add test for sparse masters --- Tests/varLib/data/SparseMasters.designspace | 23 + .../SparseMasters-Bold.ttx | 419 +++++++++++ .../SparseMasters-Medium.ttx | 125 ++++ .../SparseMasters-Regular.ttx | 419 +++++++++++ .../data/test_results/SparseMasters.ttx | 660 ++++++++++++++++++ Tests/varLib/varLib_test.py | 9 + 6 files changed, 1655 insertions(+) create mode 100644 Tests/varLib/data/SparseMasters.designspace create mode 100644 Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Bold.ttx create mode 100644 Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Medium.ttx create mode 100644 Tests/varLib/data/master_ttx_interpolatable_ttf/SparseMasters-Regular.ttx create mode 100644 Tests/varLib/data/test_results/SparseMasters.ttx 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()