varLib: use DesignSpaceDocument.loadSourceFonts method to load masters

we still need to check if source have 'layerName' set before loading from path
since that attribute only makes sense for UFOs, not TTFonts.
This commit is contained in:
Cosimo Lupo 2019-05-10 16:34:18 +01:00
parent 44f74dc8bb
commit 338793d055
No known key found for this signature in database
GPG Key ID: 20D4A261E4A0E642

View File

@ -931,7 +931,7 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
return vf, model, master_ttfs
def _open_font(path, master_finder):
def _open_font(path, master_finder=lambda s: s):
# load TTFont masters from given 'path': this can be either a .TTX or an
# OpenType binary font; or if neither of these, try use the 'master_finder'
# callable to resolve the path to a valid .TTX or OpenType font binary.
@ -965,35 +965,17 @@ def load_masters(designspace, master_finder=lambda s: s):
Return list of master TTFont objects in the same order they are listed in the
DesignSpaceDocument.
"""
master_fonts = []
for master in designspace.sources:
# 1. If the caller already supplies a TTFont for a source, just take it.
if master.font:
font = master.font
master_fonts.append(font)
else:
# If a SourceDescriptor has a layer name, demand that the compiled TTFont
# be supplied by the caller. This spares us from modifying MasterFinder.
if master.layerName:
raise AttributeError(
"Designspace source '%s' specified a layer name but lacks the "
"required TTFont object in the 'font' attribute."
% (master.name or "<Unknown>")
# If a SourceDescriptor has a layer name, demand that the compiled TTFont
# be supplied by the caller. This spares us from modifying MasterFinder.
if master.layerName and master.font is None:
raise AttributeError(
"Designspace source '%s' specified a layer name but lacks the "
"required TTFont object in the 'font' attribute."
% (master.name or "<Unknown>")
)
else:
if master.path is None:
raise AttributeError(
"Designspace source '%s' has neither 'font' nor 'path' "
"attributes" % (master.name or "<Unknown>")
)
# 2. A SourceDescriptor's path might point an OpenType binary, a
# TTX file, or another source file (e.g. UFO), in which case we
# resolve the path using 'master_finder' function
master.font = font = _open_font(master.path, master_finder)
master_fonts.append(font)
return master_fonts
return designspace.loadSourceFonts(_open_font, master_finder=master_finder)
class MasterFinder(object):