undo the more invasive changes, and only keep the change for #1808; maybe we'll add a test later

This commit is contained in:
justvanrossum 2020-01-29 12:24:03 +01:00
parent 92e03c72b2
commit 950314a5a5

View File

@ -821,7 +821,7 @@ def set_default_weight_width_slant(font, location):
font["post"].italicAngle = italicAngle
def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True, close_source_fonts=True):
def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
"""
Build variation font from a designspace file.
@ -840,64 +840,59 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True, clos
log.info("Loading master fonts")
master_fonts = load_masters(designspace, master_finder)
try:
# TODO: 'master_ttfs' is unused except for return value, remove later
master_ttfs = []
for master in master_fonts:
try:
master_ttfs.append(master.reader.file.name)
except AttributeError:
master_ttfs.append(None) # in-memory fonts have no path
# TODO: 'master_ttfs' is unused except for return value, remove later
master_ttfs = []
for master in master_fonts:
try:
master_ttfs.append(master.reader.file.name)
except AttributeError:
master_ttfs.append(None) # in-memory fonts have no path
# Copy the base master to work from it
vf = deepcopy(master_fonts[ds.base_idx])
# Copy the base master to work from it
vf = deepcopy(master_fonts[ds.base_idx])
# TODO append masters as named-instances as well; needs .designspace change.
fvar = _add_fvar(vf, ds.axes, ds.instances)
if 'STAT' not in exclude:
_add_stat(vf, ds.axes)
if 'avar' not in exclude:
_add_avar(vf, ds.axes)
# TODO append masters as named-instances as well; needs .designspace change.
fvar = _add_fvar(vf, ds.axes, ds.instances)
if 'STAT' not in exclude:
_add_stat(vf, ds.axes)
if 'avar' not in exclude:
_add_avar(vf, ds.axes)
# Map from axis names to axis tags...
normalized_master_locs = [
{ds.axes[k].tag: v for k,v in loc.items()} for loc in ds.normalized_master_locs
]
# From here on, we use fvar axes only
axisTags = [axis.axisTag for axis in fvar.axes]
# Map from axis names to axis tags...
normalized_master_locs = [
{ds.axes[k].tag: v for k,v in loc.items()} for loc in ds.normalized_master_locs
]
# From here on, we use fvar axes only
axisTags = [axis.axisTag for axis in fvar.axes]
# Assume single-model for now.
model = models.VariationModel(normalized_master_locs, axisOrder=axisTags)
assert 0 == model.mapping[ds.base_idx]
# Assume single-model for now.
model = models.VariationModel(normalized_master_locs, axisOrder=axisTags)
assert 0 == model.mapping[ds.base_idx]
log.info("Building variations tables")
if 'MVAR' not in exclude:
_add_MVAR(vf, model, master_fonts, axisTags)
if 'HVAR' not in exclude:
_add_HVAR(vf, model, master_fonts, axisTags)
if 'VVAR' not in exclude and 'vmtx' in vf:
_add_VVAR(vf, model, master_fonts, axisTags)
if 'GDEF' not in exclude or 'GPOS' not in exclude:
_merge_OTL(vf, model, master_fonts, axisTags)
if 'gvar' not in exclude and 'glyf' in vf:
_add_gvar(vf, model, master_fonts, optimize=optimize)
if 'cvar' not in exclude and 'glyf' in vf:
_merge_TTHinting(vf, model, master_fonts)
if 'GSUB' not in exclude and ds.rules:
_add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, ds.rulesProcessingLast)
if 'CFF2' not in exclude and 'CFF ' in vf:
_add_CFF2(vf, model, master_fonts)
if "post" in vf:
# set 'post' to format 2 to keep the glyph names dropped from CFF2
post = vf["post"]
if post.formatType != 2.0:
post.formatType = 2.0
post.extraNames = []
post.mapping = {}
finally:
if close_source_fonts:
for master in master_fonts:
master.close()
log.info("Building variations tables")
if 'MVAR' not in exclude:
_add_MVAR(vf, model, master_fonts, axisTags)
if 'HVAR' not in exclude:
_add_HVAR(vf, model, master_fonts, axisTags)
if 'VVAR' not in exclude and 'vmtx' in vf:
_add_VVAR(vf, model, master_fonts, axisTags)
if 'GDEF' not in exclude or 'GPOS' not in exclude:
_merge_OTL(vf, model, master_fonts, axisTags)
if 'gvar' not in exclude and 'glyf' in vf:
_add_gvar(vf, model, master_fonts, optimize=optimize)
if 'cvar' not in exclude and 'glyf' in vf:
_merge_TTHinting(vf, model, master_fonts)
if 'GSUB' not in exclude and ds.rules:
_add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, ds.rulesProcessingLast)
if 'CFF2' not in exclude and 'CFF ' in vf:
_add_CFF2(vf, model, master_fonts)
if "post" in vf:
# set 'post' to format 2 to keep the glyph names dropped from CFF2
post = vf["post"]
if post.formatType != 2.0:
post.formatType = 2.0
post.extraNames = []
post.mapping = {}
set_default_weight_width_slant(
vf, location={axis.axisTag: axis.defaultValue for axis in vf["fvar"].axes}
@ -927,7 +922,7 @@ def _open_font(path, master_finder=lambda s: s):
font = TTFont()
font.importXML(master_path)
elif tp in ("TTF", "OTF", "WOFF", "WOFF2"):
font = TTFont(master_path, lazy=True)
font = TTFont(master_path)
else:
raise VarLibError("Invalid master path: %r" % master_path)
return font