Get (and set) glyph color

How can I get (and set) the glyph color via scripting?

I’m trying (from Glyphs.app Python Scripting API Documentation) the following code and it doesn’t work:

glyph = Glyphs.font['dollar']
# use glyph color to draw the outline
glyph.colorObject.set()
print(glyph)
# Get RGB (and alpha) values (as float numbers 0..1, multiply with 256 if necessary)
R, G, B, A = glyph.colorObject.colorUsingColorSpace_(NSColorSpace.genericRGBColorSpace()).getRed_green_blue_alpha_(None, None, None, None)

print(R, G, B)

Thanks!

Try glyph.color = 5.

Or do you mean something else?

With glyph.color, you can set the 12 predefined color indexes from 0 (red) to 11 (black):

image

You can also set any NSColor directly:

from AppKit import NSColor
c = NSColor.orangeColor()
glyph = Glyphs.font.selectedLayers[0].parent
glyph.colorObject = c

Update: I see you also want to get. Here is a snippet that works for me:

glyph = Glyphs.font.selectedLayers[0].parent
c = glyph.colorObject
print(c.redComponent(), c.greenComponent(), c.blueComponent(), c.alphaComponent())

I think

glyph.colorObject.set()

should work. All that “R G B” stuff is not needed.

It works, I can set the color values outside Glyphs and Glyphs will recognize it (for filterting marked glyphs). Thanks!

BTW, it would be nice to be able to filter glyph colors by custom values too…

glyph.colorObject.set() also works. Great.

Not sure how that should work. What would you filter for?

Any color that it’s in the font but it’s not one of the twelve Glyphs’ pre-defined colors.

Do you mean filter for all glyphs that have a color or for specific RGB values?

The later us abut difficult as there is not UI for colors in the filter UI. And exactly matching colors might be tricky because if the different representations and profiles.

I mean to be able to have together all the glyphs with an existing mark color in the font (which could be any, but existing).

I can do a part via scripting:

  • Select one glyph with the color you want to have filter
  • get the color
  • check other glyphs with this color and select them
    Then there should be a way to have a smart filter which shows selected glyphs.

Is this possible? To have a smart filter with only selected glyphs? That would be enough.

That would be a list filter.