[cairo] Bug with cairo_push_group

Kristof Van Landschoot kristof at coin-c.com
Wed Jul 2 07:47:32 PDT 2008


Hi all,

After some simplifying of our code I've been able to isolate what I
think must be a bug in Cairo.  In following piece of code, the piece
of text shown ("white text") is not shown in the color it should be
shown in, transparent white, but rather in some kind of blue.  This is
due to the image being shown in the first step with an alfa
transparency.  Leave out the image and the random color text becomes
white as it should be.

We are using cairo 1.6.4.  What is happening here?  Is this a known bug?

Thanks,
Kristof

======== source code =======
	// general setup
	cairo_surface_t *lSurface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,2000,2000);
	unsigned char *lSurfaceBuffer = cairo_image_surface_get_data(lSurface);
	memset(lSurfaceBuffer,255,2000*2000*4);
	cairo_t *lCairoState = cairo_create(lSurface);

	// load a font
	FT_Library library; /* handle to library */;
	FT_Face face; /* handle to face object */;
	FT_Error error = FT_Init_FreeType( &library );
	error = FT_New_Face( library, "Arial.ttf", 0, &face );
	cairo_font_face_t *lCairoFace = cairo_ft_font_face_create_for_ft_face(face,0);

	// step 1: show a (dummy) image transparently.  This is
	cairo_push_group(lCairoState);
	unsigned char *lImageBuffer = (unsigned char *)malloc(1043*624*4);
	for (int i = 0; i < 1043*624*4; i++) lImageBuffer[i] = 0x80;
	cairo_surface_t *lImageSurface =
cairo_image_surface_create_for_data(lImageBuffer,CAIRO_FORMAT_ARGB32,1043,624,4172);
	cairo_pattern_t *lImagePattern =
cairo_pattern_create_for_surface(lImageSurface);
	cairo_set_source(lCairoState,lImagePattern);
	cairo_rectangle(lCairoState,0,0,300,200);
	cairo_fill(lCairoState);
	cairo_pop_group_to_source(lCairoState);
	cairo_paint_with_alpha(lCairoState,0.6);

	// step 2: try to show some white text, but shows up as random color
text because of step 1
	cairo_move_to(lCairoState,140,105);
	cairo_set_source_rgba(lCairoState,1,1,1,0.6);
	cairo_set_font_face(lCairoState,lCairoFace);
	cairo_set_font_size(lCairoState,32);
	cairo_show_text(lCairoState,"white text");


More information about the cairo mailing list