Bug 5496 - Add getters for cairo_scaled_font_t
Summary: Add getters for cairo_scaled_font_t
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.1.1
Hardware: x86 (IA32) All
: high enhancement
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-04 18:11 UTC by Behdad Esfahbod
Modified: 2006-01-20 15:22 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Add 4 getter functions (3.12 KB, patch)
2006-01-06 11:22 UTC, Carl Worth
Details | Splinter Review

Description Behdad Esfahbod 2006-01-04 18:11:17 UTC
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...
Comment 1 Carl Worth 2006-01-06 11:22:08 UTC
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.
Comment 2 Behdad Esfahbod 2006-01-07 23:49:16 UTC
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.
Comment 3 Carl Worth 2006-01-10 07:22:43 UTC
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
Comment 4 Behdad Esfahbod 2006-01-10 21:46:36 UTC
Fine.  I'm just thinking that ref(get()) is inherently not thread safe even when
cairo becomes thread safe itself...
Comment 5 Carl Worth 2006-01-11 03:14:31 UTC
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.
Comment 6 Behdad Esfahbod 2006-01-14 20:46:42 UTC
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.
Comment 7 Behdad Esfahbod 2006-01-14 20:51:06 UTC
Umm, and do not forget to add them to doc/public/cairo-sections.txt
Comment 8 Owen Taylor 2006-01-15 01:55:48 UTC
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.
Comment 9 Behdad Esfahbod 2006-01-16 18:27:42 UTC
Thread 1 get.
Thread 2 destroy the last reference.
Thread 1 ref the dangling pointer.
Comment 10 Owen Taylor 2006-01-17 00:32:28 UTC
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.
Comment 11 Behdad Esfahbod 2006-01-17 07:54:50 UTC
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.
Comment 12 Carl Worth 2006-01-21 10:22:14 UTC
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.