googlefonts/glyphsLib

Problems with color components

simoncozens opened this issue · 4 comments

This glyphs file: BadColor.glyphs.gz has two masters, each with two color layers. I would expect these layers to be exported as ".color0" and ".color1". However, the names of some (not all!) component glyphs used in these masters are incorrect:

$ glyphs2ufo BadColor.glyphs
$ cat BadColor-Thin.ufo/glyphs.color.1/A_acute.glif
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="Aacute" format="2">
  <advance width="500"/>
  <unicode hex="00C1"/>
  <anchor x="685" y="10" name="ogonek"/>
  <anchor x="355" y="708" name="top"/>
  <outline>
    <component base="A.color1"/>
    <component base="acutecomb.color2" xOffset="370" yOffset="208"/>
  </outline>

There is no color2, so the font does not compile.

the issue must be somewhere here:

for index, component in enumerate(layer.components):
component_name = component.name
if layer._is_color_palette_layer():
# Glyphs handles components for color layers in a special way. If
# the component glyph has color layers of its own, the component
# use the first color layer with the same color index, otherwise it
# fallback to the default layer. We try to do that here as well.
font = layer.parent.parent
component_glyph = font.glyphs[component_name]
color_layers = [
l for l in component_glyph.layers if l._is_color_palette_layer()
]
for i, l in enumerate(color_layers):
if l._color_palette_index() == layer._color_palette_index():
if l.layerId != l.associatedMasterId:
# If it is not a master layer, we rename it in
# _to_ufo_color_palette_layers(), so we reference the
# same name here.
component_name += f".color{i}"
break

Yep, that looks suspicious. I will try to fix.

thanks. I tried to understand what was going on but failed so far, happy to pass it to you

Fixed by #974