Skip to content

Commit

Permalink
prefer instance-based axis mapping over master's only when non-identity
Browse files Browse the repository at this point in the history
in absence of explicit Axis Mappings or Axis Location, we infer wght/wdth user-spacelocations from the instances; however if the axis is un-mapped or resolves in an identity (no-op) mapping, there's no reason to prefer the instance-based mapping over the similarly identity/no-op mapping associated with the masters; actually it's possible that instances do not cover all the masters and thus by preferring the instances' mapping over the masters' we might produce incorrect axis min/max.
So, only use the inferred instance-based mapping when it does something interesting, otherwise keep using the master (identity) mapping.
  • Loading branch information
anthrotype committed Nov 13, 2023
1 parent 1450627 commit b54d99d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Lib/glyphsLib/builder/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def update_mapping_from_instances(
mapping[userLoc] = designLoc


def is_identity(mapping):
"""Return whether the mapping is an identity mapping."""
return all(userLoc == designLoc for userLoc, designLoc in mapping.items())


def to_designspace_axes(self):
if not self.font.masters:
return
Expand Down Expand Up @@ -241,8 +246,12 @@ def to_designspace_axes(self):
userLoc = designLoc = axis_def.get_design_loc(master)
master_mapping[userLoc] = designLoc

# Prefer the instance-based mapping
mapping = instance_mapping or master_mapping
# Prefer the instance-based mapping (but only if interesting)
mapping = (
instance_mapping
if (instance_mapping and not is_identity(instance_mapping))
else master_mapping
)

regularDesignLoc = axis_def.get_design_loc(regular_master)
# Glyphs masters don't have a user location, so we compute it by
Expand All @@ -251,7 +260,7 @@ def to_designspace_axes(self):
regularUserLoc = piecewiseLinearMap(regularDesignLoc, reverse_mapping)
# TODO make sure that the default is in mapping?

is_identity_map = all(uloc == dloc for uloc, dloc in mapping.items())
is_identity_map = is_identity(mapping)

# Virtual Masters can't have an Axis Location parameter; their coordinates
# can either be mapped via Axis Mappings, or implicitly by neighbouring
Expand Down

0 comments on commit b54d99d

Please sign in to comment.