How to set a different ViewPort for GSEditViewController


in a plugin I’d like to manipulate what’s in the visible section of an editor tab. I’ve tried something along the lines of

Glyphs.fonts[0].currentTab.viewPort = NSRect(1000, 1000)

to try set a different viewPort, but that doesn’t work.

Any suggestions on how to do that?

You want to move the visible part? As if you had dragged it with the hand tool and/or rescaled?

Or do you want to resize the window?

This can be done like this:

rect = NSMakeRect(-100, -500, 1000, 1000)

and I added that to the wrapper so from version 1109 on, you can do this:

rect = NSMakeRect(-100, -500, 1000, 1000)
Glyphs.fonts[0].currentTab.viewPort = rect

Thanks, that’s what I was looking for.

Using the zoomViewToRect I managed to dig up some other info in the forums and almost got this working like I want, albeit with rather empirical values for the scaling.

I don’t entirely understand how the zoomViewToRect works, though, and why in the below code I sometimes need to trigger the scrollRectToVisible to jump to the right spot in the editor tab.

Basically, when I double click a glyph in the preview bar, I’d like to automatically jump the view to that glyph and scale it to cover most of the edit tab. I’ve got the glyph change hooked up alright, and this works, mostly. Only sometimes glyphs in the same “row” (?) seem to not trigger a rescale and recenter. Also, I reckon the scaling factors are not very clean and just seem to work well enough for me.

tab = Glyphs.fonts[0].currentTab
layer = tab.layers[tab.layersCursor]
scale = tab.scale
shrink = 1.75 # magic number to vertically scale the glyph down enough

rect = NSMakeRect(
    tab.selectedLayerOrigin.y - (layer.bounds.size.height * tab.scale / 2), # magic number to center the glyph vertically
    layer.width * tab.scale * shrink, 
    layer.bounds.size.height * tab.scale * shrink)

view = Glyphs.fonts[0].currentTab.graphicView()

Is there something better to use than layer.bounds.size.height for getting the glyph’s height?
Any ideas why does this not take effect when glyphs are very close to each other (like 2 or 3 glyphs apart, but off screen at enough zoom)?
Is there a Glyph-way of giving the user an option to store the scale factor and store it between restarts? I.E. setting a constant?

The zoomViewToRect did nothing if the zoom factor doesn’t change. I fixed that. So in the next update it will work as expected.

1 Like