Is font face reference counting broken?

Andreas Falkenhahn andreas at falkenhahn.com
Wed May 15 17:39:58 UTC 2024


On 15.05.2024 at 16:34 Uli Schlachter wrote:

> There is only cairo_debug_reset_static_data(), but that can only be 
> called if no objects are alive anymore.

Thanks, this seems to do the trick. 

> You can use cairo_font_face_set_user_data() to register a callback for
> when the font face is destroyed. Then, in that callback you can delete
> the temporary file.

This sounds like a good idea but I don't think it will work in my case.
I've tried it and the destroy callback does NOT get called at all. Ironically,
the destroy callback IS called when using cairo_debug_reset_static_data()
first but of course if I have to cairo_debug_reset_static_data() anyway
where's the point in using cairo_font_face_set_user_data() on top of it?

FWIW, I'm not surprised that the destroy callback doesn't get called. I
was wondering how this was supposed to work anyway because Cairo has no
master cleanup function or anything that programs are expected to call to
kill off Cairo so how should such destroy callbacks get called anyway? The
only way I could think of would be through some kind of atexit() handlers
but that would be very awkward design-wise and I don't think Cairo does any
of that stuff so I think it's obvious that the destroy callback won't get called
because there's just nobody who could call it since my program exits right
after cairo_font_face_destroy() and Cairo doesn't have a master shut down
function that could call the destroy callbacks, does it?

> Also, I am not an expert in font stuff, but why do you need a temporary
> file? Where is the font file coming from and is there perhaps a way to
> load it directly from memory?

I'm using MicroTeX and MicroTeX's Cairo backend doesn't support loading
fonts from memory buffers. That's pretty much my reason for using files...

-- 
Best regards,
 Andreas Falkenhahn                            mailto:andreas at falkenhahn.com



More information about the cairo mailing list