[cairo] Text alignment question / cairo thread safety
Behdad Esfahbod
behdad at behdad.org
Mon Feb 23 23:28:03 PST 2009
Carl Worth wrote:
> 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).
A small note that cairo_font_face_t and cairo_scaled_font_t do their own
locking and the user need not worry about locking them. Indeed, we hand out
the same object multiple times from the constructor. Doesn't make sense to
expect users to have to care about that.
behdad
>> 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
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
More information about the cairo
mailing list