Glyph User Data Inaccessible when saving as UFO (Bug)

Hi,

I noticed that User Data saved to a glyph object becomes inaccessible when the using the UFO file format.

Steps to reproduce:

  1. Create a new Glyphs file with one master.
  2. File > Save as UFO.
  3. Run the below Macro to add user data to the font (1) and to the “A” glyph (2).
    Glyphs.font.userData["TestingFont"] = "Hello, Font" # (1)    
    Glyphs.font.glyphs["A"].userData["TestingGlyph"] = "Hello, Glyph" # (2)
    
    print("Font User Data:", Glyphs.font.userData)
    print("Glyph 'A' User Data:", Glyphs.font.glyphs["A"].userData)
    
    Returns:
    Font User Data: {
        TestingFont = "Hello, Font";
    }
    Glyph 'A' User Data: {
        TestingGlyph = "Hello, Glyph";
    }
    
  4. Save & close the UFO. The lib.plist and A_.glif look like the below
    New Font.ufo/lib.plist
    ...
    <key>com.schriftgestaltung.font.userData</key>
    <dict>
        <key>TestingFont</key>
        <string>Hello, Font</string>
    </dict>
    ...
    
    New Font.ufo/glyphs/A_.glif
    
    <?xml version="1.0" encoding="UTF-8"?>
    <glyph name="A" format="2">
        <advance width="600"/>
        <unicode hex="0041"/>
        <outline>
        </outline>
        <lib>
            <dict>
                <key>TestingGlyph</key>
                <string>Hello, Glyph</string>
                <key>com.schriftgestaltung.Glyphs.lastChange</key>
                <string>2021-08-02 20:01:39 +0000</string>
            </dict>
        </lib>
    </glyph>
    
  5. Re-open the UFO in Glyphs.
  6. Run the below macro to report the User Data
    print("Font User Data:", Glyphs.font.userData)
    print("Glyph 'A' User Data:", Glyphs.font.glyphs["A"].userData)
    
    Returns:
    Font User Data: {
        "UFO.lib" =     {
            TestingFont = "Hello, Font";
        };
        UFOFormat = 3;
    }
    Glyph 'A' User Data: None
    

I would expect the User Data object for Glyph A to look similar to the Font’s User Data object, but instead it returns None.

Is there any way to read the User Data out of a UFO glyph? This seems like a bug to me.

Thanks!

I’ll have a look.

Thanks, Georg!

This is more tricky than I thought.

What happens is that all glyph.userData will end up in the layer. I could change it that it is stored in its own key to be able to better round trip.

But you should probably better use the ´layer.userData` directly.

1 Like

I believe this was sparked by Kern On not working with a UFO round-trip.

Kern On stores some of its data in the glyphs’ userData. RMX also does that, btw.

I believe data should be stored where it makes most sense, and storing data that belongs to a glyph shouldn’t be stored in the layers. That would be a rather ugly hack. What if the user re-orders the masters or deletes a master? It would be unacceptable if that breaks the system.

If a hack is necessary to store the glyph userData in a UFO then that’s where the hack should take place, not before.

1 Like

I fixed its that the glyph specific data would round-trip properly.

2 Likes

Great, Thanks!