[cairo] Issue with Cairo Font Cache

Jian Ye jiany at cdpcom.com
Wed Mar 18 09:32:57 PDT 2015

In our application, we allow multiple documents to be open at the same 
time, and user can open/close many documents during one run of the 

I set up each document to use one FT_Library object, one Cairo surface 
and one cairo_t object.  The reason is that FT requires each thread 
should have its own FT_Library object, and I want each document to have 
its own thread.

Then we discovered an issue with Cairo Font Cache and usage of Cairo+FT 
in general. We have two documents that have different fonts that draw 
text at the same location and with the same scaling. When user closes 
one doc and open another one, the text may display incorrectly.  I found 
that in those cases the 2 FT_Face objects in the two documents have the 
same pointer address. It can happen because when a doc is closed, I 
released its FT_Face objects. After tracing into the Cairo code, I 
suspect Cairo font cache failed to distinguish fonts by using their hash 
values. With other information (ctm, options) being the same , the hash 
calculation relies heavily on the font pointer addresses.

Is it true that I can not determine the life time of a FT_Face object 
when using Cairo?  In my case, even though I de-ref the 
cairo_font_face_t and cairo_scaled_font_t carefully, when a document is 
closed, the reference counts on the font objects are not zero. Although 
my following FT_Done_Face(face) calls does not cause a crash, the 
Cairo's font cache is already in bad state. I don't see a way around this.

Is it possible that Cairo add an interface function that allow user to 
tell the font cache to remove font objects in a future release?

The interface may look like:
     unsigned int cairo_cache_release_font (cairo_font_face_t          
     unsigned int cairo_cache_release_scaled_font (cairo_scaled_font_t 
Both functions return the reference count on  the font after the release.


Jian Ye

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150318/d1e3981b/attachment.html>

More information about the cairo mailing list