[cairo] Polygon fill styles?

Ian Britten britten at caris.com
Wed Aug 20 12:43:08 PDT 2008

Kalle Vahlman wrote:

> The idea is that you first create a small surface (preferrably with
> create_similar() from the surface you want to draw to) and draw
> whatever it is you want to repeat to it. Then you use
> cairo_pattern_create_for_surface() to create a pattern of the surface.
> To get it repeated, you simply set the extend mode for the pattern
> with cairo_pattern_set_extend() to CAIRO_EXTEND_REPEAT.
> Then you draw your polygon, but instead of setting the source to a
> color like normal solid fills, you set the previously created pattern
> as the source with cairo_set_source().

Is the colour (and alpha) in the pattern, or still in my context?

I'm used to the idea of the pattern (mask) being like 1-bit data,
with the actual colour only coming into play later, when it's
applied to a bitmap.  As such, I would normally just make the
pattern (mask) once, cache it, and reuse it whenever needed again.
However, each time it is reused, it might be with a different

Can I still take this approach with Cairo?  Cairo introduces a
lot of new capabilities, and as I'm roughing in code to draw
the linework of the pattern to the temporary surface, I realized
that colour (And lineweight! ;) ) and everything else is suddenly
available, and I'm not sure who is going to be defining what.

If the colour is actually in the pattern (Which admittedly, would
be powerful in many cases!), wouldn't this imply I won't be able
to cache the patterns, and will have to basically reconstruct
them for every colour?  Maybe I'm just being paranoid, but I'm
wondering on the performance impact...

[ In some cases, we'll "classify" our data, so that fill patterns
represent one attribute of a polygon, and colour represents
another.  As such, every polygon might have a different colour,
defeating any attempt to cache the patterns by colour, in case
anyone was about to suggest that :( ]

Thanks for any info!

More information about the cairo mailing list