[cairo] Polygon fill styles?

Travis Griggs tgriggs at cincom.com
Thu Aug 21 09:42:14 PDT 2008

On Aug 21, 2008, at 8:56 AM, Kalle Vahlman wrote:

> 2008/8/20 Ian Britten <britten at caris.com>:
>> 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().
>> Instead?
>> 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
>> colour.
>> Can I still take this approach with Cairo?
> Ah right, then cairo_mask() should be what you need. But now I
> wandered already to an area of cairo I haven't really used so I'll let
> you experiment how it behaves ;)
> Unless someone else wants to jump in to help :)

Not much else to say...

1) make your pattern (set its extend as appropriate)
2) set_source...() (color, coloralpha)
3) cairo_mask(cr, pattern)

if you just want to make a surface in step 1, then you can use  



"A drawing operator that paints the current source using the alpha  
channel of pattern as a mask. (Opaque areas of pattern are painted  
with the source, transparent areas are not painted.)"

If you understand the basic metaphor here (copy pixel specification  
from source to target of cr, filtered by masking operations), you  
understand the basic underpinning of all the rest of the drawing  
operators. All of them can degenerate (logically) to this one.

Travis Griggs
"I choose. Therefore, I Am"

More information about the cairo mailing list