Setting color to the default layer

I’m creating Arabic fonts where some glyphs are colored (e.g. marks). The color applies to the entire glyph so COLR record for that glyph will be one layer that is the same as the uncolored glyph. Currently I have to duplicate such glyphs to set the color on the color layers, which is is not ideal as I now need to make sure the layers are always in sync and the fonts ends with needlessly duplicated glyphs.

Is there a way to set color on the base layer instead of duplicating it?

This is possible. Just the UI didn’t let you (I fixed that) assign a palette to the master layers.
But you can do that with a script:

Layer.attributes["colorPalette"] = 0

Will make the master layer use the first palette (adjust the number if needed).

1 Like

Thanks!

I’m using this now and it works great. However, the exported font still creates glyphname.layer0 glyphs for use in the COLR table, but that is unnecessary of course as it is just a duplicate of the base glyph.

That is tricky. The problem is that all color layers need to be next to each other as the COLR table can only specify a range per color glyph. So if there is only one color the COLR table could point to the default glyph but the color layers are processed one by one and added one by one. So I need to add a check that, if the master is a color layer and there are no more, then don’t duplicate the glyph.

Yes, that is exactly the case here.