As of Glyphs 3.3 (3327), there is now an API for any plugin to draw in the foreground and background of glyph cells in Font View. This allows you to draw additional icons, background colors, or other decoration to indicate various aspects of the glyph or layer. For example, you can change the background color when the glyph has a certain tag. There is currently no Python wrapper, but you can use the Objective-C API from Python.
A plugin registers an object (like self
) to draw in the foreground and/or the background of glyph cells like so:
GSCallbackHandler.addCallback_forOperation_(self, "DrawFontView")
Plugins written in Objective-C or Swift can use the GSDrawFontViewCallbackName
constant instead of the "DrawFontView"
string.
The object needs to have at least one of the following two methods:
@objc.signature(b'v@:@{CGRect={CGPoint=dd}{CGSize=dd}}')
def drawFontViewBackgroundForLayer_inFrame_(self, layer, frame):
# code drawing for layer in `frame` behind glyph outline
@objc.signature(b'v@:@{CGRect={CGPoint=dd}{CGSize=dd}}')
def drawFontViewForegroundForLayer_inFrame_(self, layer, frame):
# code drawing for layer in `frame` in front of glyph outline
A basic implementation that just draws a yellow background would be:
@objc.signature(b'v@:@{CGRect={CGPoint=dd}{CGSize=dd}}')
def drawFontViewBackgroundForLayer_inFrame_(self, layer, frame):
NSColor.yellowColor().setFill()
NSRectFill(frame)
You can find the example code here:
Reporter plugins can do the same, but they don’t need to register themselves using GSCallbackHandler
. Instead, adding the methods suffices for a reporter to draw in Font View.