Minor reorganization

This commit is contained in:
Nikolaus Waxweiler 2018-12-19 18:39:47 +00:00
parent 67d1f3598a
commit 31c15b7c0e

View File

@ -755,26 +755,23 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
else: # Assume a path
basedir = os.path.dirname(designspace)
for master in ds.masters:
# 1. 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:
if not master.font:
for master_index, master in enumerate(ds.masters):
# 1. If the caller already supplies a TTFont for a source, just take it.
if master.font:
font = master.font
master_fonts.append(font)
master_ttfs.append(None) # No file path for in-memory object.
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 "
"then required TTFont object in the 'font' attribute."
% getattr(master, "name", "<Unknown>")
)
master_fonts.append(master.font)
master_ttfs.append(None) # No file path for in-memory object.
else:
# 2. If the caller already supplies a TTFont for a source, just take it.
if master.font:
font = master.font
master_fonts.append(font)
master_ttfs.append(None) # No file path for in-memory object.
else:
# 3. A SourceDescriptor's filename might point to a UFO or an OpenType
# 2. A SourceDescriptor's filename might point to a UFO or an OpenType
# binary. Find out the hard way.
master_path = os.path.join(basedir, master.filename)
try:
@ -782,17 +779,17 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
master_fonts.append(font)
master_ttfs.append(master_path)
except (IOError, TTLibError):
# 4. Probably no OpenType binary, fall back to the master finder.
# 3. Probably no OpenType binary, fall back to the master finder.
master_path = master_finder(master_path)
font = TTFont(master_path)
master_fonts.append(font)
master_ttfs.append(master_path)
# Copy the master source TTFont object to work on it.
if master is master_source:
buffer = io.BytesIO()
font.save(buffer)
buffer.seek(0)
vf = TTFont(buffer)
# Copy the master source TTFont object to work on it.
if master_index == ds.base_idx:
buffer = io.BytesIO()
font.save(buffer)
buffer.seek(0)
vf = TTFont(buffer)
# TODO append masters as named-instances as well; needs .designspace change.
fvar = _add_fvar(vf, ds.axes, ds.instances)
@ -832,6 +829,7 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
if tag in vf:
del vf[tag]
# TODO: Only return vf for 4.0+, the rest is unused.
return vf, model, master_ttfs