[cairo] Recursive painting when using context's surface as source

Andrea Canciani ranma42 at gmail.com
Thu Feb 10 13:42:14 PST 2011


On Thu, Feb 10, 2011 at 10:32 PM, Zan Dobersek <zandobersek at gmail.com> wrote:
> Hi,
> I've created an example where a new cairo context is created for a surface.
> I then draw with that context, creating a small rectangle in the top left
> corner. What I do next causes the problems - I set the very same surface
> that I used for creating the context to be the source for drawing. I also
> translate by 20 pixels in both directions (right and downwards). This
> results in multiple rectangles to be drawn in a diagonal line from the top
> left to the bottom right corner.
> The desired result, however, would be only one extra rectangle to be drawn
> in the space below and to the right of the original rectangle.
> I can understand why this occurs, but I wonder if it is avoidable by setting
> e.g. a different operator? Or is this the wrong approach to what I am trying
> to achieve?

Using the destination of a drawing operation as its source has an undefined
behavior. Something like:

cairo_push_group();
your_drawing_operations_here();
cairo_pop_group_to_source();
cairo_paint();
cairo_translate();
cairo_paint();

might be what you're looking for (it works around the undefined behavior by
creating an intermediate surface).

Andrea


More information about the cairo mailing list