[varLib] Add models.allSame() and use it

Part of https://github.com/googlei18n/fontmake/issues/88
Part of https://github.com/fonttools/fonttools/issues/1355
This commit is contained in:
Behdad Esfahbod 2018-11-08 11:35:15 -05:00
parent fba530a548
commit b95967dd07
2 changed files with 9 additions and 3 deletions

View File

@ -299,7 +299,7 @@ def _add_gvar(font, masterModel, master_ttfs, tolerance=0.5, optimize=True):
allCoords = [d[0] for d in allData]
allControls = [d[1] for d in allData]
control = allControls[0]
if (any(c != control for c in allControls)):
if not models.allSame(allControls):
log.warning("glyph %s has incompatible masters; skipping" % glyph)
continue
del allControls
@ -399,8 +399,7 @@ def _merge_TTHinting(font, masterModel, master_ttfs, tolerance=0.5):
# There is no cvt table to make a cvar table from, we're done here.
return
num_cvt0 = len(nonNone_cvs[0])
if (any(len(c) != num_cvt0 for c in nonNone_cvs)):
if not models.allSame(len(c) for c in nonNone_cvs):
log.warning("Masters have incompatible cvt tables, hinting is discarded.")
_remove_TTHinting(font)
return

View File

@ -11,6 +11,13 @@ __all__ = ['nonNone', 'subList',
def nonNone(lst):
return [l for l in lst if l is not None]
def allSame(lst):
if not lst:
return True
it = iter(lst)
first = next(it)
return all(first == item for item in it)
def subList(truth, lst):
assert len(truth) == len(lst)
return [l for l,t in zip(lst,truth) if t]