[cairo] Calling push_group on unbounded cairo recording surface
Daniel Kłobuszewski
daniel.klobuszewski at ibs.org.pl
Mon Oct 8 03:58:38 PDT 2012
Hello,
I have an unbounded cairo recording surface, on which I want to draw.
Unforntunately, when I start to use cairo_push_group, my whole drawing
is gone (ie. cairo_recording_surface_ink_extents gives me only 0s).
While actual usage in my app is quite complicated, I managed to narrow
the problem to this:
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
void dump_to_file(cairo_surface_t* src)
{
double imgw = 50, imgh = 50;
cairo_surface_t* dst = cairo_pdf_surface_create("test.pdf", imgw,
imgh);
cairo_t* c = cairo_create(dst);
double x,y,w,h;
cairo_recording_surface_ink_extents(src,&x,&y,&w,&h);
cairo_scale(c, imgw/w, imgh/h);
cairo_set_source_surface(c, src, -x, -y);
cairo_paint(c);
cairo_destroy(c);
cairo_surface_destroy(dst);
}
void draw(cairo_t *ctx)
{
cairo_set_source_rgb(ctx, 0, 0.8, 0);
cairo_set_line_width(ctx, 1);
cairo_move_to(ctx, 5,5);
cairo_line_to(ctx, 10, 10);
cairo_stroke(ctx);
}
int main(int argc, char**argv)
{
cairo_surface_t* s =
cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr);
cairo_t* ctx = cairo_create(s);
//cairo_push_group(ctx);
draw(ctx);
//cairo_pop_group_to_source(ctx);
//cairo_paint(ctx);
dump_to_file(s);
cairo_destroy(ctx);
cairo_surface_destroy(s);
return 0;
}
Above code works until I uncomment lines around the call to draw(...).
But if I provide (big enough) bounding rectangle instead of nullptr,
then uncommenting push/pop lines makes no difference. So I can either
have a stack of bounded surfaces or single unbounded surface. How do I
get a stack of unbounded surfaces? Is there a bug in cairo (I am using
version 2.12.2 at the moment), or is it a bug in my understanding?
Kind regards,
Daniel
More information about the cairo
mailing list