[cairo] Scaled fixed size fonts

Fred Kiefer fredkiefer at gmx.de
Sun Jan 5 11:48:16 PST 2014

In the GNUstep project we use cairo as our default drawing backend. One
user complained that with cairo some fonts get displayed worse than with
the direct xlib based backend. It turns out that on this computer only
the Adobe fonts are installed and this are fixed size fonts.
I investigated a bit in our code and later in the cairo code and this
burns down to the function cairo_scaled_font_create() returning not the
best suited fixed size font, but a scaled version of the standard 12
point font.

The reason is that _cairo_ft_font_face_get_implementation() in
cairo-ft-font.c reuses the same resolved font even when the font isn't
scalable and the matrix did change. My suggestion now is to extend the
tests in this function to first inspect the pattern whether it is
scalable. If it isn't, compare the pixel size of the cached resolved
font with the new pixel size (This code needs to be extracted from
_cairo_ft_resolve_pattern) and if that doesn't match within certain
limits (which might be the hard bit to define) the old resolved font
gets thrown away and replaced by a newly created one. Or we leave the
cached one alone and just create a new one?

This solution will use up more resource than the current one and if
there is no better matching fixed pixel font it will result in the same
display with a lot more overhead. Still for some cases it will result in
better drawn fonts. And for the most common case where scalable fonts
get used it will be almost no overhead.

Would cairo be willing to accept a patch in this direction? I am willing
to write on, but only if this effort isn't completely wasted.


More information about the cairo mailing list