Skip to content

Commit

Permalink
[designspaceLib/avar2] Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Jun 1, 2023
1 parent 77c0071 commit c4393bc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1,404 deletions.
6 changes: 3 additions & 3 deletions Doc/source/designspaceLib/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ Version 5.1
-----------

The format was extended to support arbitrary mapping between input and output
axes. The ``<axes>`` elements now can have a ``<mappings>`` element that
specifies such mappings, which when present carries data that is used to
compile to an ``avar`` version 2 table.
designspace locations. The ``<axes>`` elements now can have a ``<mappings>``
element that specifies such mappings, which when present carries data that is
used to compile to an ``avar`` version 2 table.

Version 5.0
-----------
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/designspaceLib/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def maybeExpandDesignLocation(object):

# TODO Trim out-of-range values? :-(
subDoc.axisMappings = mappings = []
subDocAxes = [axis.name for axis in subDoc.axes]
subDocAxes = {axis.name for axis in subDoc.axes}
for mapping in doc.axisMappings:
if not all(axis in subDocAxes for axis in mapping.inputLocation.keys()):
continue

Check warning on line 234 in Lib/fontTools/designspaceLib/split.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/designspaceLib/split.py#L234

Added line #L234 was not covered by tests
Expand Down
18 changes: 10 additions & 8 deletions Lib/fontTools/varLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def _add_avar(font, axes, mappings, axisTags):
}
for mapping in mappings
]
assert len(inputLocations) == len(outputLocations)

# If base-master is missing, insert it at zero location.
if not any(all(v == 0 for k, v in loc.items()) for loc in inputLocations):
Expand All @@ -241,21 +242,21 @@ def _add_avar(font, axes, mappings, axisTags):
storeBuilder = varStore.OnlineVarStoreBuilder(axisTags)
storeBuilder.setModel(model)
varIdxes = {}
for t in axisTags:
for tag in axisTags:
masterValues = []
for vo, vi in zip(outputLocations, inputLocations):
if t not in vo:
if tag not in vo:
masterValues.append(0)
continue
if t not in vi and t not in hiddenAxes:
if tag not in vi and tag not in hiddenAxes:
log.warning(

Check warning on line 252 in Lib/fontTools/varLib/__init__.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/__init__.py#L252

Added line #L252 was not covered by tests
"No input location specified for non-hidden axis '%s' in axis mapping %s",
t,
"No input location specified for non-hidden axis '%s' in axis mapping %s; axis default value assumed.",
tag,
vi,
)
v = vo[t] - vi.get(t, 0)
v = vo[tag] - vi.get(tag, 0)
masterValues.append(fl2fi(v, 14))
varIdxes[t] = storeBuilder.storeMasters(masterValues)[1]
varIdxes[tag] = storeBuilder.storeMasters(masterValues)[1]

store = storeBuilder.finish()
optimized = store.optimize()
Expand Down Expand Up @@ -908,7 +909,8 @@ def load_designspace(designspace):
log.info("Axes:\n%s", pformat([axis.asdict() for axis in axes.values()]))

axisMappings = ds.axisMappings
log.info("Mapping:\n%s", pformat(axisMappings))
if axisMappings:
log.info("Mappings:\n%s", pformat(axisMappings))

# Check all master and instance locations are valid and fill in defaults
for obj in masters + instances:
Expand Down

0 comments on commit c4393bc

Please sign in to comment.