From 08c30e9fde5eee0ea5c8b6068cb6b14513e6eebc Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Apr 2018 12:35:30 +0200 Subject: [PATCH 1/3] [varLib] make STAT v1.2, reuse fvar nameIDs Fixes https://github.com/googlei18n/fontmake/issues/417 --- Lib/fontTools/varLib/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index 5b11286e0..f30b10d97 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -169,22 +169,26 @@ def _add_avar(font, axes): return avar def _add_stat(font, axes): + # for now we just get the axis tags and nameIDs from the fvar, + # so we can reuse the same nameIDs which were defined in there. + # TODO make use of 'axes' once it adds style attributes info: + # https://github.com/LettError/designSpaceDocument/issues/8 if "STAT" in font: return nameTable = font['name'] + fvarTable = font['fvar'] STAT = font["STAT"] = newTable('STAT') stat = STAT.table = ot.STAT() - stat.Version = 0x00010000 + stat.Version = 0x00010002 axisRecords = [] - for i,a in enumerate(axes.values()): + for i, a in enumerate(fvarTable.axes): axis = ot.AxisRecord() - axis.AxisTag = Tag(a.tag) - # Meh. Reuse fvar nameID! - axis.AxisNameID = nameTable.addName(tounicode(a.labelname['en'])) + axis.AxisTag = Tag(a.axisTag) + axis.AxisNameID = a.axisNameID axis.AxisOrdering = i axisRecords.append(axis) @@ -195,6 +199,10 @@ def _add_stat(font, axes): stat.DesignAxisCount = len(axisRecords) stat.DesignAxisRecord = axisRecordArray + # for the elided fallback name, we default to the base style name. + # TODO make this user-configurable via designspace document + stat.ElidedFallbackNameID = 2 + # TODO Move to glyf or gvar table proper def _GetCoordinates(font, glyphName): """font, glyphName --> glyph coordinates as expected by "gvar" table From f688d4bb86493588dcf6e035ea31d781f8e3e8f9 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Apr 2018 12:37:10 +0200 Subject: [PATCH 2/3] [Tests/varLib] adjust STAT expected test data --- Tests/varLib/data/test_results/BuildMain.ttx | 19 ++++--------------- Tests/varLib/data/test_results/Mutator.ttx | 12 ------------ 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Tests/varLib/data/test_results/BuildMain.ttx b/Tests/varLib/data/test_results/BuildMain.ttx index f30351e5f..33ebbd4a7 100644 --- a/Tests/varLib/data/test_results/BuildMain.ttx +++ b/Tests/varLib/data/test_results/BuildMain.ttx @@ -494,12 +494,6 @@ TestFamily-BlackHighContrast - - Weight - - - Contrast - Test Family @@ -578,12 +572,6 @@ TestFamily-BlackHighContrast - - Weight - - - Contrast - @@ -794,22 +782,23 @@ - + - + - + + diff --git a/Tests/varLib/data/test_results/Mutator.ttx b/Tests/varLib/data/test_results/Mutator.ttx index 9818654d1..878e05c15 100644 --- a/Tests/varLib/data/test_results/Mutator.ttx +++ b/Tests/varLib/data/test_results/Mutator.ttx @@ -494,12 +494,6 @@ TestFamily-BlackHighContrast - - Weight - - - Contrast - Test Family @@ -578,12 +572,6 @@ TestFamily-BlackHighContrast - - Weight - - - Contrast - From ffc7dfc23d907996e56473e46994fcd9a29142a5 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Apr 2018 12:55:51 +0200 Subject: [PATCH 3/3] [varLib] don't need to read nameTable in _add_stat for now at least... --- Lib/fontTools/varLib/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index f30b10d97..974f5d0fd 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -177,7 +177,6 @@ def _add_stat(font, axes): if "STAT" in font: return - nameTable = font['name'] fvarTable = font['fvar'] STAT = font["STAT"] = newTable('STAT')