Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/fontTools/varLib/featureVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def addFeatureVariations(font, conditionalSubstitutions, featureTag="rvrn"):

addFeatureVariationsRaw(font, font["GSUB"].table, conditionsAndLookups, featureTags)

# Update OS/2.usMaxContext in case the font didn't have features before, but
# does now, if the OS/2 table exists. The table may be required, but
# fontTools needs to be able to deal with non-standard fonts. Since feature
# variations are always 1:1 mappings, we can set the value to at least 1
# instead of recomputing it with `otlLib.maxContextCalc.maxCtxFont()`.
if (os2 := font.get("OS/2")) is not None:
os2.usMaxContext = max(1, os2.usMaxContext)


def _existingVariableFeatures(table):
existingFeatureVarsTags = set()
Expand Down
4 changes: 4 additions & 0 deletions Tests/varLib/featureVars_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def makeVariableFont(glyphOrder, axes):
axis.minimum, axis.default, axis.maximum = minimum, default, maximum
ds_axes[axisTag] = axis
varLib._add_fvar(font, ds_axes, instances=())
os2 = font["OS/2"] = newTable("OS/2")
os2.usMaxContext = 0
return font


Expand All @@ -35,7 +37,9 @@ def varfont():
def test_addFeatureVariations(varfont):
assert "GSUB" not in varfont

assert varfont["OS/2"].usMaxContext == 0
addFeatureVariations(varfont, [([{"wght": (0.5, 1.0)}], {"A": "A.alt"})])
assert varfont["OS/2"].usMaxContext == 1

assert "GSUB" in varfont
gsub = varfont["GSUB"].table
Expand Down
Loading