Skip to content

Support color fonts that use the foreground color

While working on windows color fonts I learned that SVG and COLR fonts can use the current text foreground color when painting glyph images. FreeType already supports this feature for COLR fonts using the FT_Palette_Set_Foreground_Color() function.

I found a COLR font that makes use of this feature in this bug report. This is the output from Firefox for the test case in the bug report (I changed the foreground color to make it more obvious).

The text color is green. The parentheses are non-color glyphs and rendered in the text color. The Arabic character is a color glyph with most of the glyph rendered in the foreground color and the two dots are rendered in red.

Firefox

I wrote some code that rendered this test case in cairo. Using the following drawing operations:

    cairo_move_to (cr, 100, 100);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_show_text(cr, "(\xd9\x82)");
    cairo_move_to (cr, 100, 200);
    cairo_set_source_rgba (cr, 0, 0, 1, 0.5);
    cairo_show_text(cr, "(\xd9\x82)");

I get this output from cairo master. The foreground of the Arabic character is rendered in black even though the foreground color is not black.

without-foreground-color

With this MR the output is:

with-foreground-color

I'd like to create a test case for this but I need to find a way to create a small color font to include with the test suite and write boilerplate for each font backend to load a font from a file. That is a job for another day.

I intend to update user fonts to support using the foreground color in the render function. That will have a test case and will be able to test all the non FT font backend parts of this change.

Merge request reports