[varLib.interpolatable] Speed up working on variable fonts
Only check each glyph at its own "master" locations instead of at all master locations across the font. Incomplete. Fixes https://github.com/fonttools/fontbakery/discussions/4301
This commit is contained in:
parent
98242634c4
commit
636295a7ee
@ -11,7 +11,7 @@ from fontTools.pens.pointPen import SegmentToPointPen
|
|||||||
from fontTools.pens.recordingPen import RecordingPen
|
from fontTools.pens.recordingPen import RecordingPen
|
||||||
from fontTools.pens.statisticsPen import StatisticsPen
|
from fontTools.pens.statisticsPen import StatisticsPen
|
||||||
from fontTools.pens.momentsPen import OpenContourError
|
from fontTools.pens.momentsPen import OpenContourError
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, defaultdict
|
||||||
import math
|
import math
|
||||||
import itertools
|
import itertools
|
||||||
import sys
|
import sys
|
||||||
@ -444,30 +444,34 @@ def main(args=None):
|
|||||||
if "gvar" in font:
|
if "gvar" in font:
|
||||||
# Is variable font
|
# Is variable font
|
||||||
gvar = font["gvar"]
|
gvar = font["gvar"]
|
||||||
# Gather all "master" locations
|
# Gather all glyphs at their "master" locations
|
||||||
locs = set()
|
ttGlyphSets = {}
|
||||||
for variations in gvar.variations.values():
|
glyphsets = defaultdict(dict)
|
||||||
|
|
||||||
|
for glyphname, variations in gvar.variations.items():
|
||||||
for var in variations:
|
for var in variations:
|
||||||
|
locDict = {}
|
||||||
loc = []
|
loc = []
|
||||||
for tag, val in sorted(var.axes.items()):
|
for tag, val in sorted(var.axes.items()):
|
||||||
|
locDict[tag] = val[1]
|
||||||
loc.append((tag, val[1]))
|
loc.append((tag, val[1]))
|
||||||
locs.add(tuple(loc))
|
|
||||||
# Rebuild locs as dictionaries
|
|
||||||
new_locs = [{}]
|
|
||||||
names.append("()")
|
|
||||||
for loc in sorted(locs, key=lambda v: (len(v), v)):
|
|
||||||
names.append(str(loc))
|
|
||||||
l = {}
|
|
||||||
for tag, val in loc:
|
|
||||||
l[tag] = val
|
|
||||||
new_locs.append(l)
|
|
||||||
locs = new_locs
|
|
||||||
del new_locs
|
|
||||||
# locs is all master locations now
|
|
||||||
|
|
||||||
for loc in locs:
|
locTuple = tuple(loc)
|
||||||
fonts.append(font.getGlyphSet(location=loc, normalized=True))
|
if locTuple not in ttGlyphSets:
|
||||||
|
ttGlyphSets[locTuple] = font.getGlyphSet(
|
||||||
|
location=locDict, normalized=True
|
||||||
|
)
|
||||||
|
|
||||||
|
glyphsets[locTuple][glyphname] = ttGlyphSets[locTuple][
|
||||||
|
glyphname
|
||||||
|
]
|
||||||
|
|
||||||
|
names = ["()"]
|
||||||
|
fonts = [font.getGlyphSet()]
|
||||||
|
for locTuple in sorted(glyphsets.keys(), key=lambda v: (len(v), v)):
|
||||||
|
names.append(str(locTuple))
|
||||||
|
fonts.append(glyphsets[locTuple])
|
||||||
|
args.ignore_missing = True
|
||||||
args.inputs = []
|
args.inputs = []
|
||||||
|
|
||||||
for filename in args.inputs:
|
for filename in args.inputs:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user