[cairo] Filling everything but the shape

Gerdus van Zyl gerdusvanzyl at gmail.com
Mon May 26 08:29:55 PDT 2008


Could you please post the relevent code you are using? The "fill a
transparent arc on the mask" part sounds incorrect, you need to clear it
using CAIRO_OPERATOR_CLEAR.
example python code:
------
import cairo

canvas = cairo.ImageSurface(cairo.FORMAT_ARGB32,320,240)
ctx = cairo.Context(canvas)

#fill with blue
ctx.set_source_rgb(0,0,1)
ctx.paint()

#Construct Mask
maskSurface = cairo.ImageSurface(cairo.FORMAT_ARGB32,320,240)
ctxM = cairo.Context(maskSurface)
ctxM.set_source_rgba(1,1,1,1)
ctxM.paint()

#knock out rectangle
ctxM.rectangle(50,50,100,100)
ctxM.set_source_rgba(0,0,0,1)
ctxM.set_operator(cairo.OPERATOR_CLEAR)
ctxM.fill()

maskPattern = cairo.SurfacePattern(maskSurface)

debug = False
if debug:
    #show mask
    ctx.set_source(maskPattern)
    ctx.paint()
else:
    #use mask
    ctx.set_source_rgb(0,1,0)
    ctx.mask(maskPattern)

canvas.write_to_png("out.png")
------

On Mon, May 26, 2008 at 12:36 PM, Ricky Wood <rickywoodster at yahoo.co.uk>
wrote:

> I'm new to cairo and probably missing some obvious concept, please can
> someone enlighten me with this problem:
>
> Basically, I have a surface with some shapes already drawn onto it.  I now
> want to paint every part of the surface a single colour except a circle,
> i.e. leave the contents of the surface, where the circle lies, undisturbed.
>
> The approach I took was:
>
> - create a mask
> - paint the mask totally opaque
> - fill a transparent arc on the mask
> - set the colour on the source
> - cairo_mask
>
> I thought the source colour would be transferred to the destination,
> leaving the circle masked.
>
> Where have I gone wrong, or is there a better approach?
>
> TIA.
>
> ------------------------------
> Sent from Yahoo! Mail<http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52418/*http://uk.docs.yahoo.com/nowyoucan.html>.
>
> A Smarter Email.
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080526/db09a5a7/attachment.html 


More information about the cairo mailing list