[cairo] shading, take 2

Thomas Hunger info at teh-web.de
Wed Mar 3 07:21:27 PST 2004

Based on the ideas discussed here I refactored cairo a bit to implement 
Each backend has now a create_pattern callback which takes a cairo_pattern_t 
and the dimensions of the expected image. It may then either fill it or 
return NULL which starts a software shader (again, only linear so far, radial 
is in work, others would be nice, suggestions welcome) which returns the 
wanted image.
since solid color and bitmaps are patterns, too, I plugged them into the 
This function now replaces the ensure_source function which was used by cairo 
Patterns may have an etxra transformation matrix set which maps to different 

set_pattern: sets the surface matrix before surface is composited  (1)
set_pattern_linear|radial: transforms the control points

colors are controlled via 

cairo_pattern_add_color_stop (cairo_t *cr, double offset, double r, double g, 
double b, double a);

which should work for linear shaders. Like in svg offset has to be a value 
between 0 and 1.

In svg different  models are supported when the offset goes behind 1: pad, 
mirror and repeat. currently the linear shader only pads, but the other 
functions are in work.

The surface matrix is now part of the pattern state (see (1)), the functions 
cairo_surface_set_matrix, repeat, filter have moved to the private api. this 
breaks at least one cairo-demo so far (knockout)

Since shader and maybe the user want to know which rectangular area is 
covered by a fill or stroke operation the following functions have moved into 
the public api:

cairo_stroke_extents (cairo_t *cr, pixman_box16_t *extents);
cairo_fill_extents (cairo_t *cr, pixman_box16_t *extents);

This implements one part of functionality proposed by Carl Worth in this mail:

This is only a quick overview, not all work is done yet, but I would be happy 
about comments. The names of the functions can easily be changed if you are 
unhappy with them (I did not waste much time to make them up).

some screenshots and a tarball can be found here:


P.S. is there acutally transparency in svg? I searched but could not find 

More information about the cairo mailing list