[cairo] Always keep text in foreground?

Benjamin Otte otte at redhat.com
Sun Aug 15 18:16:20 PDT 2010


On Sun, 2010-08-15 at 18:06 -0700, Daniel Goldman wrote:
> How do I always keep the text in the z-order foreground?
> 
The z-order in Cairo is always determined by the order in which the
drawing commands are executed. There is absolutely no way around it. So
if you draw the text before stroking a line, the text will be behind the
line.

> If not, is it possible (or advisable) to write the polygons to one context (I 
> guess), write the text to another context (or whatever), and then overlay the 
> text over the polygons? If this is feasible, could someone sketch out the key 
> functions to use.
> 
What you could do is create a a similar surface, render all the text to
the similar surface while stroking lines on the original surface, and
then finally cairo_paint()ing that surface on top. I would however
consider this ugly.

All layout engines I am aware of - Pango, HTML renderers like Webkit or
Mozilla, Gtk widgets, ... - all have a multi-layered approach, where
they iterate over the content multiple times so they get the z-order
right. To me this is a strong indication that this is indeed the normal
approach to handle his problem.

Benjamin



More information about the cairo mailing list