[cairo] Text alignment question / cairo thread safety

Milosz Derezynski internalerror at gmail.com
Sat Feb 21 13:00:17 PST 2009


Hello Everyone,

I'm working on a new font preview widget / font selection dropdown for the
text toolbar in Inkscape. My architecture is very pluggable so it's easy to
swap in a preview renderer which uses a particular
backend to render. So far I've written a preview renderer using pango-cairo
and it works well, but I use threading to generate previews to avoid
stalling the UI, and it turns out pango is not
thread safe which makes it impossible to use my code in an app that uses
Gtk+ as text is rendered with pango everywhere.

Now I wanted to write a preview renderer using cairo's text API, and I have
2 questions:

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?

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?
I found a lot in the API docs and a few examples but I can't get it quite
fully right. It would be nice if someone could give me a minor code example
on how to do this, it would be very appreciated.

A video of the current widget for those interested in this work on Inkscape
can be found here: http://futurepast.free.fr/out.ogv, and
a wiki page detailing this work in cooperation with LinuxFund can be found
here: http://wiki.inkscape.org/wiki/index.php/LinuxFund2009_1

Thanks in advance,
M.

-- 
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20090221/6a889873/attachment.html 


More information about the cairo mailing list