Questions regarding GSLayer.bounds / sidebearings

I stumbled upon a few things I don’t understand regarding the behaviour of GSLayer objects. Maybe you can enlighten me …

For context: I want to know a layer’s sidebearings with and without components. Therefore, I read out LSB & RSB, then copy the layer to remove all GSComponent shapes and then read out the LSB & RSB again. Similar to this:

lsbWithComp = layer.LSB
layerCopy = copy.copy(layer)
if layer.shapes:
    layer.shapes = [s for s in layer.shapes if not isinstance(s, GSComponent)]
lsbWithoutComp = layer.LSB

While doing this, I found a few things that I think are not desired behaviour:

#1 For some layers, LSB etc. have the wrong value – even before modifying anything. Two layers with the same contents (a component and a path) show the same LSB in the interface but when I read them out in Python, they are different (layer 1 LSB: 100; layer 2 LSB 0).

#2 When I delete the components programmatically, the sidebearings do not change.
Edit: This can be achieved with GSLayer.updateMetrics().

#3 When I read out layer.bounds as an alternative, it’s values do change. However, the values are

  1. slightly off (e.g. 0.002177422795121231 instead of 0.0)
  2. not the values one would expect: for the “m” shown above, origin.x is 0 which is indeed the origin of the component – but the paths inside the component only start at x = 100.

Is it me? Any suggestions? Of course one could iterate over all paths and find the min/max of their bounds – but shouldn’t my solution work as well?


Can you send me the file and the script that shows those problems?

When you meant the bounds of the copy of the layer, it might be wrong as it can’t access the shape of the components as it has no access to the font object.

It seems that I can’t recreate problem #1, because I did use updateMetrics() on the file already. I guess the problem appeared after copying (cmd + c, cmd + v) the contents of one layer (1 component, 1 path) into the other master layer. Could it be that after copying the metrics were not updated?

Yes, the bounds are incorrect after copying the layer. It makes total sense after reading your explanation.