[varLib] Move code around

This commit is contained in:
Behdad Esfahbod 2017-04-12 16:08:01 -07:00
parent 51fd216c62
commit e73cc7ae34

View File

@ -368,15 +368,6 @@ def build(designspace_filename, master_finder=lambda s:s):
raise VarLibError("no sources found in .designspace") raise VarLibError("no sources found in .designspace")
instances = ds.get('instances', []) instances = ds.get('instances', [])
base_idx = None
for i,m in enumerate(masters):
if 'info' in m and m['info']['copy']:
assert base_idx is None
base_idx = i
assert base_idx is not None, "Cannot find 'base' master; Add <info> element to one of the masters in the .designspace document."
log.info("Index of base master: %s", base_idx)
log.info("Building variable font") log.info("Building variable font")
log.info("Loading master fonts") log.info("Loading master fonts")
basedir = os.path.dirname(designspace_filename) basedir = os.path.dirname(designspace_filename)
@ -412,6 +403,12 @@ def build(designspace_filename, master_finder=lambda s:s):
axis_names = set(master_locs[0].keys()) axis_names = set(master_locs[0].keys())
assert all(axis_names == set(m.keys()) for m in master_locs) assert all(axis_names == set(m.keys()) for m in master_locs)
base_idx = None
for i,m in enumerate(masters):
if 'info' in m and m['info']['copy']:
assert base_idx is None
base_idx = i
# Set up axes # Set up axes
axes_dict = {} axes_dict = {}
if axes is not None: if axes is not None:
@ -423,6 +420,7 @@ def build(designspace_filename, master_finder=lambda s:s):
name = axis['name'] name = axis['name']
axes_dict[name] = (lower, default, upper) axes_dict[name] = (lower, default, upper)
else: else:
for name in axis_names: for name in axis_names:
default = master_locs[base_idx][name] default = master_locs[base_idx][name]
lower = min(m[name] for m in master_locs) lower = min(m[name] for m in master_locs)
@ -433,6 +431,9 @@ def build(designspace_filename, master_finder=lambda s:s):
log.info("Axes:\n%s", pformat(axes_dict)) log.info("Axes:\n%s", pformat(axes_dict))
assert all(name in axis_map for name in axes_dict.keys()) assert all(name in axis_map for name in axes_dict.keys())
assert base_idx is not None, "Cannot find 'base' master; Either add <axes> element to .designspace document, or add <info> element to one of the sources in the .designspace document."
log.info("Index of base master: %s", base_idx)
log.info("Master locations:\n%s", pformat(master_locs)) log.info("Master locations:\n%s", pformat(master_locs))
# We can use the base font straight, but it's faster to load it again since # We can use the base font straight, but it's faster to load it again since