Currently the only use of cairo_scaled_font_t is cairo_scaled_font_extents and cairo_scaled_font_glyph_extents. It would be more useful if there were the following functions: cairo_scaled_font_get_font_face cairo_scaled_font_get_font_matrix cairo_scaled_font_get_ctm cairo_scaled_font_get_font_options The idea is that a cairo_scaled_font has all needed information for setting up a font on a cairo context. By having getters, you can install a font matching a cairo_scaled_font. Another option is to actually provide a: cairo_set_scaled_font That sets font_face, font_matrix, and font_options (and ctm?!). Sorry if these are already discussed...
Created attachment 4253 [details] [review] Add 4 getter functions I don't much like the idea of having a function named cairo_set_scaled_font that would also muck with the CTM, nor would a function so-named likely make sense without setting the CTM. So let's not add that one. Instead, here's a patch to add the suggested 4 getter functions. That way any mucking with the CTM for the sake of using a particular scaled font will be explicit.
Without actually looking at the code (my laptop died, using public terminals), shouldn't get_font_face reference the font before returning? Of course it should be documented whichever way. Looks good otherwise.
The _get_ functions in cairo are non-referencing by convention. If you want a referencing version it is simple enough to get it with: font_face = cairo_font_face_reference (cairo_scaled_font_get_font_face (scaled_font)); -Carl
Fine. I'm just thinking that ref(get()) is inherently not thread safe even when cairo becomes thread safe itself...
When "cairo becomes thread-safe" ? As a library, cairo should be thread-safe already[*]. That is, it is safe to use cairo from multiple simultaneous threads. What we don't currently have is per-object locking that allows an individual cairo object to be safely used from multiple threads. I don't think that would even make sense to do, and there are no plans to do that at any point. [*] Modulo some win32 brain-damage that results in a broken library when doing static linking on win32.
Well, it does make sense to use a cairo_scaled_font from multiple threads IMO. And having to _ref after _get makes room for dangling pointers in the application that cannot be fixed in cairo later... Anyway, please apply the patch then.
Umm, and do not forget to add them to doc/public/cairo-sections.txt
cairo_scaled_font_t is immutable, so there is no thread safety problem with ref-after-get. Another thread can't change these fields while this thread is using the font.
Thread 1 get. Thread 2 destroy the last reference. Thread 1 ref the dangling pointer.
Thread 1 can't access the scaled font without holding a reference to it. After thread 1 gets, it must copy or ref the getted resource before dropping the reference it holds to the scaled font. So, as long as the scaled font is immutable (and it is) then there is no issue... the scaled font will reference the resource at least until after the thread establishes a reference.
Right, what I said doesn't exactly hold here. Basically you are saying that the obeject passed to the getter always has a reference to what the getter returns, so it cannot be destroyed before ref(). Guess that's the case in cairo.
This is committed now to cairo 1.1.1 (in CVS): 2006-01-20 Carl Worth <cworth@cworth.org> * src/cairo.h: * src/cairo-scaled-font.c: (cairo_scaled_font_get_font_face), (cairo_scaled_font_get_font_matrix), (cairo_scaled_font_get_ctm), (cairo_scaled_font_get_font_options): Add getter functions for cairo_scaled_font_t. I added some documentation as well. -Carl
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.