instancer: set mac overlap glyf flags when fully instancing

like varLib.mutator does
This commit is contained in:
Cosimo Lupo 2019-05-08 16:24:17 +01:00
parent 5a530880c0
commit 5871a754de
No known key found for this signature in database
GPG Key ID: 20D4A261E4A0E642
2 changed files with 47 additions and 4 deletions

View File

@ -16,7 +16,7 @@ from fontTools.misc.fixedTools import floatToFixedToFloat, otRound
from fontTools.varLib.models import supportScalar, normalizeValue, piecewiseLinearMap
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.TupleVariation import TupleVariation
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates
from fontTools.ttLib.tables import _g_l_y_f
from fontTools import varLib
from fontTools.varLib import builder
from fontTools.varLib.mvar import MVAR_ENTRIES
@ -82,7 +82,7 @@ def instantiateGvarGlyph(varfont, glyphname, location, optimize=True):
)
if defaultDeltas:
coordinates += GlyphCoordinates(defaultDeltas)
coordinates += _g_l_y_f.GlyphCoordinates(defaultDeltas)
# this will also set the hmtx/vmtx advance widths and sidebearings from
# the four phantom points and glyph bounding boxes
glyf.setCoordinates(glyphname, coordinates, varfont)
@ -585,6 +585,19 @@ def pruningUnusedNames(varfont):
del varfont["ltag"]
def setMacOverlapFlags(glyfTable):
flagOverlapCompound = _g_l_y_f.OVERLAP_COMPOUND
flagOverlapSimple = _g_l_y_f.flagOverlapSimple
for glyphName in glyfTable.keys():
glyph = glyfTable[glyphName]
# Set OVERLAP_COMPOUND bit for compound glyphs
if glyph.isComposite():
glyph.components[0].flags |= flagOverlapCompound
# Set OVERLAP_SIMPLE bit for simple glyphs
elif glyph.numberOfContours > 0:
glyph.flags[0] |= flagOverlapSimple
def normalize(value, triple, avar_mapping):
value = normalizeValue(value, triple)
if avar_mapping:
@ -632,7 +645,9 @@ def sanityCheckVariableTables(varfont):
raise NotImplementedError("Instancing CFF2 variable fonts is not supported yet")
def instantiateVariableFont(varfont, axis_limits, inplace=False, optimize=True):
def instantiateVariableFont(
varfont, axis_limits, inplace=False, optimize=True, overlap=True
):
sanityCheckVariableTables(varfont)
if not inplace:
@ -673,6 +688,10 @@ def instantiateVariableFont(varfont, axis_limits, inplace=False, optimize=True):
instantiateFvar(varfont, axis_limits)
if "fvar" not in varfont:
if "glyf" in varfont and overlap:
setMacOverlapFlags(varfont["glyf"])
return varfont

View File

@ -3,7 +3,7 @@ from fontTools.misc.py23 import *
from fontTools import ttLib
from fontTools import designspaceLib
from fontTools.feaLib.builder import addOpenTypeFeaturesFromString
from fontTools.ttLib.tables import _f_v_a_r
from fontTools.ttLib.tables import _f_v_a_r, _g_l_y_f
from fontTools.ttLib.tables import otTables
from fontTools.ttLib.tables.TupleVariation import TupleVariation
from fontTools import varLib
@ -990,3 +990,27 @@ def test_pruningUnusedNames(varfont):
assert not any(n for n in varfont["name"].names if n.nameID in varNameIDs)
assert "ltag" not in varfont
def test_setMacOverlapFlags():
flagOverlapCompound = _g_l_y_f.OVERLAP_COMPOUND
flagOverlapSimple = _g_l_y_f.flagOverlapSimple
glyf = ttLib.newTable("glyf")
glyf.glyphOrder = ["a", "b", "c"]
a = _g_l_y_f.Glyph()
a.numberOfContours = 1
a.flags = [0]
b = _g_l_y_f.Glyph()
b.numberOfContours = -1
comp = _g_l_y_f.GlyphComponent()
comp.flags = 0
b.components = [comp]
c = _g_l_y_f.Glyph()
c.numberOfContours = 0
glyf.glyphs = {"a": a, "b": b, "c": c}
instancer.setMacOverlapFlags(glyf)
assert a.flags[0] & flagOverlapSimple != 0
assert b.components[0].flags & flagOverlapCompound != 0