If you are writing a reporter plugin which does a lot of work, you may want to restrict the operation of the reporter to just the visible part of the glyph on the screen. If the user has zoomed in to just a portion of the glyph, you can ignore the parts of the glyph which are not being displayed.
The following routine will give you an NSRect
which expresses the visible bounds of the glyph:
from Quartz.CoreGraphics import CGRectIntersection
def visibleRectangle():
thisEdit = Glyphs.font.currentTab
origin = thisEdit.selectedLayerOrigin
scale = thisEdit.graphicView().scale()
bounds = thisEdit.graphicView().visibleRect()
bounds.origin.x -= origin.x
bounds.origin.y -= origin.y
bounds.origin.x /= scale
bounds.origin.y /= scale
bounds.size.width /= scale
bounds.size.height /= scale
return CGRectIntersection(bounds, Glyphs.font.selectedLayers[0].bounds)