How to change glyph layer color from black to Foreground in color font

I am working on a color font in which each glyph is consist of multiple layers, Actually it is an Arabic Quran font, I am applying intonation (Tajweed) rules by coloring different parts of glyphs in different layers. Almost I had completed the font but unfortunately I had applied all glyph base color as black instead of foreground color (based on user choice) Now I want to change black color into foreground color. (so that the user can change the base color of his choice but the colored part remains same, it will also be helpful in using the font in night mode) I had tried it to do manually one by one each glyph, but it takes a lot of time because there are almost 150000 glyphs in my font. so I want to find out a way how can I set this in a single command. I want automation to complete my job in time. is there is any scripts that will solve my problem?  I am using Font Creator 13 software and using CPAL and COLR tbales. 
Please guide me. Thanks alot..


  • waiting for expert opinion
  • Peter Constable
    In the font's CPAL table, the value 0xFFFF is used to indicate the app-determined foreground colour. @Erwin Denissen would be able to tell how to set that in Font Creator.
  • Jens Kutilek
    As far as I know, Font Creator operates directly on the TrueType font and doesn't use a dedicated font source format. So you could operate directly on the font file with some other tools. The easiest would probably be the Python FontTools with a small Python script like this:
    from fontTools.ttLib import TTFont
    f = TTFont("TwemojiMozilla.ttf")
    colr = f["COLR"]
    for name, layers in colr.ColorLayers.items():
        print(f"Color glyph: {name}")
        for layer in layers:
            print(f"    Layer glyph: {} with color ID {layer.colorID}")
            if layer.colorID == COLOR_INDEX_TO_MODIFY:
                layer.colorID = 0xffff  # The special index that maps to the foreground color
                print("    ... modified")"TwemojiMozilla_modified.ttf")
    If you have a font with 150000 glyphs, you probably want to remove the print statements ;)
  • Peter Constable
    >If you have a font with 150000 glyphs

    Well, wouldn't that be cool! OpenType 2.0!
  • Jens Kutilek
    Ha, I didn't even notice that the number is impossible :)