[cairo] Polygon fill styles?

Ian Britten britten at caris.com
Fri Aug 22 06:27:21 PDT 2008


Travis Griggs wrote:
>>> 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)

I'm trying to adapt my (Now-working! :) ) pattern stuff to use a
mask instead, and have a couple of questions, mostly about the
colour/alpha usage, I suspect.
[ See my example from the other day, if you want full code ]

Basically, I'm:
- Making my temporary surface/context (Using CONTENT_COLOR_ALPHA)
- Drawing my linework to it (Using set_source_rgba(1.0,1.0,1.0,1.0))
   -> I'm assuming this identifies the 'on' pixels, like '1's in a
      1-bit mask.
- Making my (surface) pattern, from my temporary surface (Using
   EXTEND_REPEAT)
- Configuring the transformation on the pattern
- Setting the mask (pattern) onto my destination context
- Setting the colour on my destination context
   (eg:  set_source_rgba(0.5, 0.5, 0.5, 0.5); )
   -> I'm assuming this applies the desired colour, and since the
      colour in the mask should basically be irrelevant (ie: 1-bit)
- fill

My understanding is this should draw the transparent grey colour
I set, to the parts that I stroked in my pattern (mask).  However,
all I get is a solid grey polygon.  (The PDF is much bigger than
it is if I omit the mask, so there's _something_ going to the file)

I'm not used to working with a 32-bit mask like this (Usually just
1-bit), and have obviously messed up something.  I've flailed at
various combinations (eg: CONTENT_COLOR, using black instead of
white, etc), but to no success.  If anyone sees what it might be,
I'd appreciate any pointers!
[ I can post a complete (cairomm) sample, if it'd help ]

Many thanks for any help!
Ian



More information about the cairo mailing list