Skip to content

Commit

Permalink
Merge pull request #641 from jenskutilek/link-metrics-custom-param
Browse files Browse the repository at this point in the history
Implement "Link Metrics..." custom parameters
  • Loading branch information
simoncozens authored Apr 1, 2021
2 parents 528a4a5 + 99b812c commit 19b26b6
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 4 deletions.
17 changes: 16 additions & 1 deletion Lib/glyphsLib/builder/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,22 @@ def to_ufo_glyph(self, ufo_glyph, layer, glyph): # noqa: C901
ufo_glyph.lib[GLYPHLIB_PREFIX + "subCategory"] = subCategory

# load width before background, which is loaded with lib data
width = layer.width

# The width may be taken from another master via the customParameters
# 'Link Metrics With Master' or 'Link Metrics With First Master'.
master = self.font.masters[layer.associatedMasterId or layer.layerId]
metric_source = master.metricsSource.id
metric_layer = self.font.glyphs[glyph.name].layers[metric_source]
if metric_layer:
width = metric_layer.width
if layer.width != width:
logger.debug(
f"{layer.parent.name}: Applying width from master "
f"'{metric_source}': {layer.width} -> {width}"
)
else:
width = None

if width is None:
pass
elif category == "Mark" and subCategory == "Nonspacing" and width > 0:
Expand Down
8 changes: 6 additions & 2 deletions Lib/glyphsLib/builder/kerning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@


def to_ufo_kerning(self):
for master_id, kerning in self.font.kerning.items():
_to_ufo_kerning(self, self._sources[master_id].font, kerning)
for master in self.font.masters:
master_id = master.id
kerning_source = master.metricsSource.id # Maybe be a linked master
if kerning_source in self.font.kerning:
kerning = self.font.kerning[kerning_source]
_to_ufo_kerning(self, self._sources[master_id].font, kerning)


def _to_ufo_kerning(self, ufo, kerning_data):
Expand Down
28 changes: 27 additions & 1 deletion Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,32 @@ def shouldWriteValueForKey(self, key):
return self._name != self.name
return super().shouldWriteValueForKey(key)

@property
def metricsSource(self):
"""Returns the source master to be used for glyph and kerning metrics.
Normally this is the current master itself, but when linked metrics
custom parameters are being used, the master referred to in the custom
parameter is returned instead."""
if self.customParameters["Link Metrics With First Master"]:
return self.font.masters[0]
source_master_id = self.customParameters["Link Metrics With Master"]

# No custom parameters apply, go home
if not source_master_id:
return self

if source_master_id in self.font.masters:
return self.font.masters[source_master_id]

# Try by name
for source_master in self.font.masters:
if source_master.name == source_master_id:
return source_master

logger.warning(f"Source master for metrics not found: '{source_master_id}'")
return self

@property
def name(self):
name = self.customParameters["Master Name"]
Expand Down Expand Up @@ -3269,7 +3295,7 @@ def bounds(self):
return Rect(Point(left, bottom), Point(right - left, top - bottom))

def _find_node_by_indices(self, point):
""""Find the GSNode that is refered to by the given indices.
""" "Find the GSNode that is refered to by the given indices.
See GSNode::_indices()
"""
Expand Down
Loading

0 comments on commit 19b26b6

Please sign in to comment.