Set/Fill the color of stroke/path

Hi there,

I’m going to write a new GeneralPlugin plugin that need to set the color of some strokes as “highlight”.

It doesn’t mean that I want to create the colored font, I just want some strokes be highlighted that I can clearfiy recognize what I’ve selected.

The preview of Show Glyphs in Their Label Color plugin is close to what I imagine:

I’ve try the code below in macro window followed by API docs:

Layer = Glyphs.font.selectedLayers[0]
specificPath = Layer.paths[:5]

for path in specificPath:
    NSColor.redColor().set()
    path.bezierPath.fill()

Glyphs.redraw()

But the Editview/Preview doesn’t change anything. The stroke still fill in black.

How to set the color of each stroke in preview mode?

Does the drawing feature only avaliable in Reporter type plugin?

Thank you.

You need to write a Reporter Plugin. Then put your drawing code in one of the available drawing callbacks. You can’t “just draw”. You can tell the system that the view needs to be redrawn and then the system asked you (in a “drawRect_” callback) to draw whatever you like. The edit view will ask all active Reporter plugins to draw.

For learning, I would recommend the Skedge plugin by Mark Frömberg (freely available in the plugin manager). There, you can test your code live without having to write a reporter plugin and loading it every time you want to test it again.

Yes, I was about to recommend Skedge too, which will actually enable to “just draw”. See it as a drafting tool to play around until you get your result (at least roughly) and then take the code from Skedge and stick it into one of the drawing methods (e.g. drawForeground, drawBackground) of a reporter plugin.

Your code looks like the right direction, in Skedge it might already work. You don’t need the Glyphs.redraw() (not in Skedge and not in a Reporter plugin).

If you want to show the outlines, use stroke() instead of fill(). For that you can also set the lineWidth (e.g. setLineWidth_(2/scale))

In the repo of Skedge are some primitive examples.

Some minor, general tips:

You could change your specificPath to specificPaths, which won’t change a thing code wise, but it is good practice to make your variables show what they are (in this case a list of paths, not one path). Just a tip :slight_smile:

Layer with a capital L is already the current layer in most scenarios. It might be that it is not the shortcut for it in Skedge (or maybe even a plugin(?)), but I recommend to use layer instead to avoid confusion with built in objects. (same with Font for example)

Thank you all,

I just wanna check that whether the foreground or backdroubd drawing function is only avalible in Reporter (*.glyphsReporter) type plugin or it can be access in other general plugins (*.glyphsPlugin).

It seems like I can only use Reporter plugin. I’ll give it a try.

You can add callbacks for this drawing functions from any plugin or script.

But why don’t you just do a Reporter?