[cairo] drawing with a mask

Dan Ventura dventura7 at gmail.com
Wed Feb 18 12:36:52 PST 2009


I'm sure this is a dumb question, but apparently, I don't understand some
(possibly fundamental) aspect of how cairo does stuff (disclaimer: I'm a
machine learning person and not a graphics person).  Based on the
documentation, I would think that the following code would produce a 200x200
BROWN square with a smaller 40x40 GREEN square centered in it.  Instead, I
get just a 200x200 BROWN square (i.e. the mask lets no green paint through).


        finalsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200,
200);

        finalcr = cairo_create (finalsurface);

cairo_scale (finalcr, 200, 200);

        color=makecolor(BROWN);               //returns a cairo_pattern_t

cairo_set_source(finalcr,color);

cairo_paint(finalcr);

color=makecolor(GREEN);

cairo_set_source(finalcr,color);

        masksurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200,
200);

        maskcr = cairo_create (masksurface);

        cairo_scale (maskcr, 200, 200);

        cairo_set_source_rgba(maskcr, 0, 0, 0, 0);

        cairo_paint(maskcr);                         //make most of mask
transparent

        cairo_set_source_rgba(maskcr, 1, 1, 1, 1);

        cairo_rectangle(maskcr, .4, .4, .2, .2);

        cairo_fill(maskcr);                          //make small square in
mask opaque

cairo_mask_surface(finalcr,masksurface,0,0);




More information about the cairo mailing list