[cairo] Always keep text in foreground?

Maarten Bosmans mkbosmans at gmail.com
Mon Aug 16 11:04:23 PDT 2010

2010/8/16 Daniel Goldman <dagoldman at yahoo.com>:
> Thanks for the replies. I ended up reading the data file twice, stroking and
> filling the polygons first pass, and applying the labels the second pass, as
> shown in a simplified form by Arjen. It was somewhat inconvenient, but not a
> big deal. I already knew that was a possible solution.
> It's a big data file, which I would rather not read twice. But it's still
> fast enough. It would even be possible to split the data file into two data
> files: one with the points, the other with the labels. But I'll only do that
> if ever a speed problem.

You can always do the drawing of the text to a second surface and
combine them afterwards, like Benjamin suggested. The second surface
for the text can be created with:
text_surface = cairo_surface_create_similar(poly_surface,

This way you only have to go over your dataset once.

> The reason I posted was to understand cairo better, to clarify if cairo has
> the luxury of automatically keeping the text in the foreground. I appreciate
> Benjamin explaining why this is not the case. I can live without the luxury.
> Daniel


More information about the cairo mailing list