GlyphsApp.drawingTools.drawPath()

I’m trying to draw a path in a plugin in a cross-platform way (Glyphs and RoboFont).

Shouldn’t this work?

from GlyphsApp.drawingTools import *
NSColor.greenColor().colorWithAlphaComponent_(0.3).set()

newPath()
moveTo((0, 0))
lineTo((100, 0))
lineTo((100, 100))
closePath()
drawPath()

I get

File "GlyphsApp/GlyphsApp/drawingTools.py", line 79, in drawPath
AttributeError: 'NoneType' object has no attribute 'fill'

It seems drawPath() should draw the “current path” when no path is explicitly passed to it, but why doesn’t it work?

It was missing a global currentPath.

Thank you! The drawing works now, but the path drawn does not have the stroke/stroke width/fill properties I am setting.

The drawPath() command draws the black things. They should be drawn as the thin light blue lines.

This is the NibSimulator Plugin from GitHub - jenskutilek/nibLib: Nib simulation library for font editors.

If you want to test: You need to “Show Nib Simulator” from the View Menu, and bring up the settings via contextual menu “Nib Settings…”. The nib simulation will apply to the path in the layer background.

I can’t get it to run. Too many dependencies.

No worries. I solved the drawing of those parts in a different way, using NSBezierPath directly.

But I like to fix it anyway. Can you send me a few lines that show the problem?

Here’s some code you can run in Skedge.

from GlyphsApp.drawingTools import *
NSColor.greenColor().colorWithAlphaComponent_(0.3).set()

save()
p = NSBezierPath.alloc().init()
p.moveToPoint_((0, 0))
p.lineToPoint_((0, 100))
p.lineToPoint_((100, 100))
p.closePath()
p.stroke()
p.fill()


#fill(0.2, 0.3, 0.8)
newPath()
moveTo((0, 0))
lineTo((100, 0))
lineTo((100, 100))
closePath()
drawPath()
restore()

Bildschirmfoto 2023-06-12 um 09.41.46

The second path (lower right triangle) will be drawn in black, unless you set the fill color using the fill() command. It will not pick up the color set by NSColor.set() at the beginning, which I expect it should?

No, drawPath() will only fill the outline when there is a currentColor and that is set to black by default. Otherwise you couldn’t stroke a path without filling it. Or at least that is how I understand it.
I added the option to do fill(NSColor.greenColor). Otherwise I would not mix Cocoa drawing methods and drawingTools stuff.