Skip to content

Commit

Permalink
consistently name UFO and DS source layer for the same brace glyphs
Browse files Browse the repository at this point in the history
Fixes #925
  • Loading branch information
anthrotype committed Jul 12, 2023
1 parent aa6912f commit 4f2de54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
11 changes: 2 additions & 9 deletions Lib/glyphsLib/builder/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ def to_ufo_layer(self, glyph, layer):
# Give color layers better names
if layer._is_color_palette_layer():
layer_name = f"color.{layer._color_palette_index()}"
elif "coordinates" in layer.attributes:
# For Glyphs 3's intermediate (formerly 'brace') layers we must generate the
# name from the attributes (as it's shown in Glyphs.app UI) and discard
# the layer's actual 'name' as found in the source file, which is usually just
# the unique date-time when a layer was first created.
# Using the generated name ensures that all the intermediate glyph instances
# at a given location end up in the same UFO source layer, see:
# https://github.com/googlefonts/glyphsLib/issues/851
layer_name = f"{{{', '.join(str(v) for v in layer.attributes['coordinates'])}}}"
elif layer._is_brace_layer():
layer_name = layer._brace_layer_name()

if layer.associatedMasterId == layer.layerId:
ufo_layer = ufo_font.layers.defaultLayer
Expand Down
2 changes: 1 addition & 1 deletion Lib/glyphsLib/builder/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _to_designspace_source_layer(self):
for glyph in self.font.glyphs:
for layer in glyph.layers:
if layer._is_brace_layer():
key = (layer.name, tuple(layer._brace_coordinates()))
key = (layer._brace_layer_name(), tuple(layer._brace_coordinates()))
layer_to_master_ids[key].add(layer.associatedMasterId)
layer_to_glyph_names[key].append(glyph.name)

Expand Down
15 changes: 15 additions & 0 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3993,6 +3993,21 @@ def _brace_coordinates(self):
coordinates = name[name.index("{") + 1 : name.index("}")]
return [float(c) for c in coordinates.split(",")]

def _brace_layer_name(self):
# For Glyphs 3's intermediate (formerly 'brace') layers we must generate the
# name from the attributes (as it's shown in Glyphs.app UI) and discard
# the layer's actual 'name' as found in the source file, which is usually just
# the unique date-time when a layer was first created.
# Using the generated name ensures that all the intermediate glyph instances
# at a given location end up in the same UFO source layer, see:
# https://github.com/googlefonts/glyphsLib/issues/851
# TODO: Figure out a better API for layer.name vs layer.nameUI() mess...
if "coordinates" in self.attributes:
# Glyphs 3
return f"{{{', '.join(str(v) for v in self.attributes['coordinates'])}}}"
# Glyphs 2
return self.name

COLOR_PALETTE_LAYER_RE = re.compile(r"^Color (?P<index>\*|\d+)$")

def _is_color_palette_layer(self):
Expand Down

0 comments on commit 4f2de54

Please sign in to comment.