[cairo] Recording surface as source
Salvati Sylvain
sylvain.salvati at labri.fr
Fri Feb 1 00:21:55 PST 2013
Dear Cairo list,
I am new to cairo and I do not quite understand the behavior of
recording surface. I tried to draw on a recording surface then obtain
the rectangle of its bounding box (x,y,w,h) and then to dump the result
onto a pdf surface of width w and height h by translating what is on
the recording surface with the vector (-x,-y). As it happens only the
objects of the recording surface that have some part within the
intersection of the rectangles (x,y,w,h) and (0,0,w,h) are drawn on the
pdf. Is this a normal behavior or is this some bug? If if is the
former how am I supposed to dump the whole content of the recording
surface onto a pdf surface? Here follows some small code that displays
the problem:
#include <cairo.h>
#include <cairo-pdf.h>
#include <stdio.h>
int main (int argc, char *argv[]){
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA,NULL);
cr = cairo_create (surface);
//filling red square
cairo_set_source_rgb(cr,1,0,0);
cairo_translate(cr,25,25);
cairo_rectangle (cr, 0, 0, 25, 25);
cairo_fill(cr);
//filling blue square
cairo_set_source_rgb(cr,0,0,1);
cairo_translate(cr,25,25);
cairo_rectangle (cr, 0, 0, 25, 25);
cairo_fill(cr);
cairo_destroy(cr);
//Dumping onto a pdf surface
double x,y,w,h;
cairo_recording_surface_ink_extents(surface,&x,&y,&w,&h);
cairo_surface_t* destination = cairo_pdf_surface_create("test.pdf",w,h);
cr = cairo_create(destination);
cairo_set_source_surface(cr, surface, -x, -y);
cairo_paint(cr);
//only the red square is painted while I would expect the blue one to
be painted too
cairo_destroy(cr);
cairo_surface_destroy(destination);
cairo_surface_destroy(surface);
return 0;
}
Sylvain.
More information about the cairo
mailing list