diff --git a/Lib/fontTools/varLib/mutator.py b/Lib/fontTools/varLib/mutator.py index 79a6f3d1b..dd6dd5ee5 100644 --- a/Lib/fontTools/varLib/mutator.py +++ b/Lib/fontTools/varLib/mutator.py @@ -9,7 +9,7 @@ from fontTools.misc.fixedTools import floatToFixedToFloat, otRound, floatToFixed from fontTools.pens.boundsPen import BoundsPen from fontTools.ttLib import TTFont, newTable from fontTools.ttLib.tables import ttProgram -from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates +from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates, flagOverlapSimple, OVERLAP_COMPOUND from fontTools.varLib import _GetCoordinates, _SetCoordinates from fontTools.varLib.models import ( supportScalar, @@ -145,7 +145,7 @@ def interpolate_cff2_metrics(varfont, topDict, glyphOrder, loc): hmtx[gname] = tuple(entry) -def instantiateVariableFont(varfont, location, inplace=False): +def instantiateVariableFont(varfont, location, inplace=False, overlap=True): """ Generate a static instance from a variable TTFont and a dictionary defining the desired location along the variable font's axes. The location values must be specified as user-space coordinates, e.g.: @@ -154,6 +154,10 @@ def instantiateVariableFont(varfont, location, inplace=False): By default, a new TTFont object is returned. If ``inplace`` is True, the input varfont is modified and reduced to a static font. + + When the overlap parameter is defined as True, + OVERLAP_SIMPLE and OVERLAP_COMPOUND bits are set to 1. See + https://docs.microsoft.com/en-us/typography/opentype/spec/glyf """ if not inplace: # make a copy to leave input varfont unmodified @@ -308,6 +312,15 @@ def instantiateVariableFont(varfont, location, inplace=False): addidef = any(op.startswith("GETVARIATION") for op in instructions) if addidef: break + if overlap: + for glyph_name in glyf.keys(): + glyph = glyf[glyph_name] + # Set OVERLAP_COMPOUND bit for compound glyphs + if glyph.isComposite(): + glyph.components[0].flags |= OVERLAP_COMPOUND + # Set OVERLAP_SIMPLE bit for simple glyphs + elif glyph.numberOfContours > 0: + glyph.flags[0] |= flagOverlapSimple if addidef: log.info("Adding IDEF to fpgm table for GETVARIATION opcode") asm = [] diff --git a/Tests/varLib/data/test_results/Mutator.ttx b/Tests/varLib/data/test_results/Mutator.ttx index a106d213b..fac0997a6 100644 --- a/Tests/varLib/data/test_results/Mutator.ttx +++ b/Tests/varLib/data/test_results/Mutator.ttx @@ -154,7 +154,7 @@ - + @@ -190,7 +190,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -334,7 +334,7 @@ - + @@ -370,7 +370,7 @@ - + diff --git a/Tests/varLib/data/test_results/Mutator_Getvar-instance.ttx b/Tests/varLib/data/test_results/Mutator_Getvar-instance.ttx index a20f0e4fa..28e0766a7 100755 --- a/Tests/varLib/data/test_results/Mutator_Getvar-instance.ttx +++ b/Tests/varLib/data/test_results/Mutator_Getvar-instance.ttx @@ -168,7 +168,7 @@ - + @@ -200,7 +200,7 @@ - + @@ -229,7 +229,7 @@ - + diff --git a/Tests/varLib/data/test_results/Mutator_IUP-instance.ttx b/Tests/varLib/data/test_results/Mutator_IUP-instance.ttx index 1800479b1..1f7b651f0 100755 --- a/Tests/varLib/data/test_results/Mutator_IUP-instance.ttx +++ b/Tests/varLib/data/test_results/Mutator_IUP-instance.ttx @@ -157,7 +157,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -214,7 +214,7 @@ - +