googlefonts / glyphsLib

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

userData not cloned when node is cloned #1006

Open simoncozens opened 1 month ago

simoncozens commented 1 month ago

test-userdata.zip contains a Glyphs file with a node like this:

(1310,800,c,{
co.uk.corvelsoftware.Dotter = {
forced = 1;
};
})

Except when read with glyphsLib:

font = load("test.glyphs")
print(font.glyphs["G"].layers[0].paths[0].nodes[15].userData)

I get this:

({'forced': 1})
anthrotype commented 1 month ago

so the outer dict with "co.uk.corvelsoftware.Dotter" key that contains the {'forced': 1} as its item is gone?

simoncozens commented 1 month ago

Exactly. I'll take a look as to why.

simoncozens commented 1 month ago

Actually it might just be a repr problem with the UserDataProxy, and something else is wrong in my code; the dictionary is correct in _userData...

simoncozens commented 1 month ago

Urgh, OK, it is a repr problem, the dictionary is fine and there was an issue somewhere else in my code which this did not help me to debug...

simoncozens commented 1 month ago

OK, so the actual issue is userData is not copied when a node is cloned:

In [5]: layer.shapes[0].nodes[15].userData
Out[5]: ({'forced': 1})

In [6]: layer.shapes[0].nodes[15].clone().userData
Out[6]: ()