New little script: Fit Zoom

Made a little script Fit Zoom that fits/centers on screen the current text (if Text/Hand tool selected) or the current layer (if other tools selected).

In other words, it turns 1 (random zoom/position) into 2 (fit text) or 3 (fit current layer):

However, in Glyphs 3 it works weirdly and jumps all over the place; I can’t figure out why. Any suggestions/hints are appreciated :slight_smile:

Do you mean it works in Glyphs 2?

Works well in Glyphs 2, but in Glyphs 3 viewport position calculates weirdly – haven’t figured out why yet. Are there any changes on how vp position should be set?

I don’t have time to fully debug your code, but the tab.scale = 1 at the beginning seems to be not right. The setting of the viewport will set the scale already. You need to scale the rect that you put into to the viewport.

Not sure if I’m overthinking it, but without setting scale to 1 it doesn’t zoom in when needed, only out. And if I apply tab.scale to calculations later, it’s not right either. Viewport is somehow too mysterious to me :smiley:

No, it will zoom in both directions.