[cairo] Text alignment question / cairo thread safety
Carl Worth
cworth at cworth.org
Mon Feb 23 15:12:01 PST 2009
On Sat, 2009-02-21 at 22:00 +0100, Milosz Derezynski wrote:
> 1) Is cairo for all intents and purposes, and the text API in
> particular (i'm speaking of the "toy" API here as I don't need
> anything else, at least yet) thread safe?
We intend for it to be thread-safe, yes. (There can always be bugs of
course, but Chris "ickle" Wilson has been doing some very good work to
test that we have locks in place where necessary. I can't say
authoritatively how exhaustive his testing is, but I know that it's a
lot better than things were before testing was done----which is to say,
his testing found lots of bugs, which he promptly fixed.)
And by "thread-safe", I mean that things should work as long as you
don't cause multiple threads to access a single cairo object
simultaneously without your own locks. If each of your threads have
independent cairo objects, then things should work, (cairo does have
some shared data like font caches, and it does its own locking for
these).
> 2) How can I properly calculate the size of a surface needed to fit in
> a particular string of text, and how do I calculate the rendering
> position so that all actual text pixels will fit into the extents of
> the surface?
We've talked a bit about this in IRC, and I think you're on your way
now. You were correctly calling cairo_text_extents to measure the text,
but then missing the way to correctly use the resulting x_bearing and
y_bearing to place the text within the surface of just the right size
that you had created.
If someone wanted to write up a little code to show how to use text
extents in this way, that might be quite nice to add to cairo's
documentation. The resulting graphic might just be text within a box,
but it could even go so far as to be marked up something like:
http://www.freetype.org/freetype2/docs/glyphs/Image3.png
but with cairo-specific naming. And obviously the code next to the
graphics should make it plain to see how to get the sign right when
using the x/y_bearing values in particular.
-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.cairographics.org/archives/cairo/attachments/20090223/848a8763/attachment.pgp
More information about the cairo
mailing list