googlefonts / glyphsLib

A bridge from Glyphs source files (.glyphs) to UFOs
Apache License 2.0
182 stars 51 forks source link

Layer with alternate and intermiate attributes throws an error #1050

Open khaledhosny opened 3 days ago

khaledhosny commented 3 days ago

I have a virtual master that goes from 0 to 100 to make some glyphs wider. Some of these glyphs the narrow and the wider form are incompatible, so I need to use an alternate layer. See for for background.

I have the following layer setup:

Image

It works in Glyphs, but with fontmake I get the following glyphsLib error:

INFO:fontmake.font_project:Building master UFOs and designspace from Glyphs source
INFO:glyphsLib.parser:Parsing .glyphs file
INFO:glyphsLib.builder:Running 'propagate_all_anchors' transformation
Traceback (most recent call last):
  File "/venv/bin/fontmake", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/venv/lib/python3.12/site-packages/fontmake/__main__.py", line 708, in main
    project.run_from_glyphs(inputs.glyphs_path, **args)
  File "/venv/lib/python3.12/site-packages/fontmake/font_project.py", line 910, in run_from_glyphs
    designspace = self.build_master_ufos(
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/fontTools/misc/loggingTools.py", line 375, in wrapper
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/fontmake/font_project.py", line 246, in build_master_ufos
    designspace = glyphsLib.to_designspace(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/glyphsLib/builder/__init__.py", line 161, in to_designspace
    return builder.designspace
           ^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/glyphsLib/builder/builders.py", line 344, in designspace
    self.to_designspace_bracket_layers()  # .bracket_layers
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/glyphsLib/builder/bracket_layers.py", line 67, in to_designspace_bracket_layers
    copy_bracket_layers_to_ufo_glyphs(self, bracket_layer_map)
  File "/venv/lib/python3.12/site-packages/glyphsLib/builder/bracket_layers.py", line 108, in copy_bracket_layers_to_ufo_glyphs
    ufo_glyph = ufo_layer.newGlyph(ufo_glyph_name)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/ufoLib2/objects/layer.py", line 336, in newGlyph
    raise KeyError(f"glyph named '{name}' already exists")
KeyError: "glyph named 'behDotless_alef-ar.BRACKET.varAlt01' already exists"

Test file: TestVirtualMasterAlternateLayer.zip

schriftgestalt commented 3 days ago

I had a look at the code. It differentiates too much between brace and bracket layers. I might be better to decompose bracket layers on the GSFont side. That way the to_ufo part will be much simpler and could handle such cases much better (there can be color bracket layers and such …).

schriftgestalt commented 3 days ago

I found a reasonable (I hope) fix.