From 08c30e9fde5eee0ea5c8b6068cb6b14513e6eebc Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Apr 2018 12:35:30 +0200 Subject: [PATCH] [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