I am using
@loicsander’s RoboFab pens, particularly the broad nibber as it produces better results at the moment.
I want to create a plugin that takes an open outline from the front window and draws it’s Broad Nib counterpart in the background.
I can get an
objectsGS.RGlyph but I don’t know how to use this for the
drawBackgroundForLayer_ in a .glyphsReporter? Kind of like show Offset preview but for Broad nib
you need to find a pen that produces a NSBezierPath. fonttools has a CocoaPen that does this.
March 19, 2016, 12:07pm
It looks like layer.paths.bezierPath creates a NSBezierPath.
Is it possible to get a GSPath from an NSBezierPath (so to say, the other way around)? I want to add an NSBezierPath to a layer.
That is possibel but not implemented. You could implement a path.draw(pen) methods that traverses the bezierpath and draws itself in the pen. Have a look at the NSBezierPath documentation from Apple.
Where did you get the bezierpath from?
March 19, 2016, 12:41pm
I create it rudimetally with the following bit:
path = NSBezierPath.bezierPath()
sysFont = NSFont.systemFontOfSize_(12)
glyph = sysFont.glyphWithName_("a")
path is the NSBezierPath object, which appears to be the same as a GSPath.bezierPath.
So you mean, next step would be to use the GSPen? If so, how to traverse trough the NSBezierPath? Cannot find this in the Apple docu.
I do not think it is possible easily, you would have to get your hands dirty and wade through the path elements. You can step across its path elements with the
NSBezierPath.elementAtIndex_() attributes. The latter will yield a
NSBezierPathElement object, which you could query for its attributes and points, and step by step, reconstruct a
GSPath with it.
March 23, 2016, 7:30am
That’s what I assumed.
NSBezierPath.elementAtIndex_()where the missing pieces. Good to know. Will postpone to write a Pen for that. Thank you so much guys.
@Mark, did you make something to turn a Robofab produced shape into a NSBezierPath? Like for example
from robofab.world import CurrentGlyph
g = CurrentGlyph()
pen = g.getPen()
I’m trying to make a plugin that will draw something in the background, but using this getPen() method?
May 15, 2016, 7:05pm
How about this? No RoboFab needed:
thisLayer = Glyphs.font.selectedLayers
thisLayer.paths = 
newPath = GSPath()
(it is just a shortcut, you could also initialize each node, set x, y, type and connection before passing it in the addNode_() method
and then just draw to the background layer instead of the layer. Otherwise, why using the NSBezierPath?
May 15, 2016, 7:11pm
OR: do you mean, you want to draw a shape/Path to the background of the view? Like the reporters are capable of doing? In that case, why bother with the getPen? This is for drawing paths to the glyph/layer. Something kind of different.
thanks Mark! I just couldn’t find the glyphs app way of doing it!
I also wanted to use Loic Sander’s broadnibbing pen for something else https://github.com/loicsander/RobofabPens
May 15, 2016, 8:10pm
I see. Then you are perhaps right to use the RoboFab pen. Unfortunately I’ll have to pass on the question and come over to the side of the curious ones. This is beyond my current knowledge.
You can use a NSBezierPath as a pen directly. So everywhere you can put in a pen, you can put in a NSBezierPath.
June 7, 2018, 3:11pm
@oneweioranother did you get Loic Sander’s RoboFabPens to work? Trying the same …
Especially interested in something like the JitterPen or SpikePen.
The latest cutting edge version has some improvements.