From cf4a24182ee1c32f791464675ceb2b51816d0f1b Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 16 Mar 2023 18:29:17 +0000 Subject: [PATCH] [varLib] don't skip buildVFStatTable from DSv5 with 'STAT' info Fixes https://github.com/fonttools/fonttools/issues/3045 --- Lib/fontTools/varLib/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index ecfb8ca03..86fa8d704 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -988,6 +988,22 @@ def build_many( Always returns a Dict[str, TTFont] keyed by VariableFontDescriptor.name """ res = {} + # varLib.build (used further below) by default only builds an incomplete 'STAT' + # with an empty AxisValueArray--unless the VF inherited 'STAT' from its base master. + # Designspace version 5 can also be used to define 'STAT' labels or customize + # axes ordering, etc. To avoid overwriting a pre-existing 'STAT' or redoing the + # same work twice, here we check if designspace contains any 'STAT' info before + # proceeding to call buildVFStatTable for each VF. + # https://github.com/fonttools/fonttools/pull/3024 + # https://github.com/fonttools/fonttools/issues/3045 + doBuildStatFromDSv5 = ( + "STAT" not in exclude + and designspace.formatTuple >= (5, 0) + and ( + any(a.axisLabels or a.axisOrdering is not None for a in designspace.axes) + or designspace.locationLabels + ) + ) for _location, subDoc in splitInterpolable(designspace): for name, vfDoc in splitVariableFonts(subDoc): if skip_vf(name): @@ -1000,7 +1016,7 @@ def build_many( optimize=optimize, colr_layer_reuse=colr_layer_reuse, )[0] - if "STAT" not in vf and "STAT" not in exclude: + if doBuildStatFromDSv5: buildVFStatTable(vf, designspace, name) res[name] = vf return res