[cairo] Recording surface as source. Bug? Cairo 1.12.11/1.12.12 // Sample code

Edward Zimmermann Edward.Zimmermann at cib.de
Fri Feb 1 02:04:49 PST 2013


Some simple code to demonstrate our findings:


If TEST1 and TEST2 NOT defined --> Does what we expect
If only TEST1 is defined ---> Does what we expect
If only TEST2 is defined ---> Does what we expect
If both TEST1 and TEST2 are defined --> PNG is empty!


#define TEST1  1
#define TEST2  1


void testBW2()
{
        cairo_matrix_t rot = {0,-1,1,0,0,40};

        cairo_rectangle_t r0rect = {0,0,40,40};
        cairo_surface_t* r0 = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &r0rect);
    cairo_t* c0 = cairo_create(r0);
        cairo_set_source_rgba(c0,1,0,0,1);
        cairo_rectangle(c0,0,0,20,20);
        cairo_fill(c0);
        cairo_set_source_rgba(c0,0,1,0,1);
        cairo_rectangle(c0,20,0,20,20);
        cairo_fill(c0);
        cairo_set_source_rgba(c0,0,0,1,1);
        cairo_rectangle(c0,0,20,20,20);
        cairo_fill(c0);
        cairo_set_source_rgba(c0,1,1,0,1);
        cairo_rectangle(c0,20,20,20,20);
        cairo_fill(c0);

        cairo_rectangle_t r1rect = {0,0,40,40};
        cairo_surface_t* r1 = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &r1rect);
        cairo_t* c1 = cairo_create(r1);
#if TEST1
        cairo_transform(c1, &rot);
#endif
        cairo_set_source_surface(c1, r0, 0, 0);
        cairo_paint(c1);

        cairo_rectangle_t r2rect = {0,0,40,40};
        cairo_surface_t* r2 = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &r2rect);
    cairo_t* c2 = cairo_create(r2);
#if TEST2
        cairo_transform(c2, &rot);
#endif
        cairo_set_source_surface(c2, r1, 0, 0);
        cairo_paint(c2);

        cairo_surface_t* image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 40, 40);
    cairo_t* ci = cairo_create(image);
        cairo_set_source_surface(ci, r2, 0, 0);
        cairo_paint(ci);
        cairo_surface_write_to_png(image,"dummy.png");
}


More information about the cairo mailing list