GSEditViewController question!

Hi there!

I am curious if there is a way to find the specific coordinate values for a glyph that has been entered in a GSEditViewController.

For instance, if I type the word ‘Hamburger’ into a tab in Glyphs, is there a way to retrieve via python the coordinate value for where the ‘r’ in Hamburger is positioned, in that tab?

So that, I could, for instance, draw a shape with NSrect, at that position?


pos = controller.graphicView().cachedPositionAtIndex_(idx)
layer = controller.graphicView().cachedGlyphAtIndex_(idx)

One additional question if you have a moment! Is it possible to render text, in a particular system-installed font, within the graphicView, as a UI element? Similar to drawing an NSBezierPath, but with text? Thank you!

Yes there is. Are you thinking about (1) a particular installed font, (2) the font currently in the works in Glyphs, or (3) one of the System Fonts? In any event, I would start looking at the NSFont documentation.

You want to use that font for writing on the Edit View canvas with a Reporter plug-in?

If you want to use installed/system font, you can use this example:

(you can replace this method with foreground method in plugin reporter template to see what it does)

	def foreground(self, layer):
		currentZoom = self.getScale()
		text_to_display = 'my awesome Menlo font test'
		fontName = "Menlo"
		position = (0,0)
		color = NSColor.redColor() # good default is NSColor.textColor(), here I used red to make it more visible

		# here I'm createing NSFont object, with given font name and size
		font = AppKit.NSFont.fontWithName_size_(fontName, 30 / currentZoom)
		# abourt if font was not found
		if font is None:
		# draw text at given position, with specified color and font
		fontAttributes = {
			AppKit.NSForegroundColorAttributeName: color,
			AppKit.NSFontAttributeName: font
		txt = AppKit.NSAttributedString.alloc().initWithString_attributes_(
		txt.drawAtPoint_alignment_(AppKit.NSPoint(*position), 0)

I hope it helps a bit,

Very helpful, thank you very much! Thanks to you too @mekkablue!

1 Like