[cairo] Fill not overlapping stroke?

David Trallero ditiem at gmail.com
Tue Jun 1 18:19:17 PDT 2010


> I suppose what I want is a way to just fill inside the stroke and not overlap it;
> or a way to pass fill and stroke at the same time.

If I understood you well, you are looking for something like this:

    cairo_push_group_with_content( cr, CAIRO_CONTENT_COLOR_ALPHA ) ;
      cairo_set_line_width( cr, 10.0 ) ;

      cairo_rectangle( cr, 0, 0, 200, 200 ) ;

      cairo_set_source_rgba( cr, 1.0, 0.0, 0.0, .8 ) ;
      cairo_fill_preserve( cr ) ;

      cairo_set_operator( cr, CAIRO_OPERATOR_DEST_OUT ) ;

      cairo_set_source_rgba( cr, 0.0, 0.0, 0.0, .5 ) ;
      cairo_stroke( cr ) ;

    cairo_pop_group_to_source( cr ) ;
    cairo_set_operator( cr, CAIRO_OPERATOR_DEST_OVER ) ;
    cairo_paint( cr );

Depends on your algorithm to paint, you may not need push/pop_group operation.
I attach the whole code and the generated png file so you can play with it. I am
not sure that is the best way...

Regards,
  David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check.png
Type: image/png
Size: 1642 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100602/7bb9b6c9/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo_blend2.cpp
Type: text/x-c++src
Size: 1602 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100602/7bb9b6c9/attachment.cpp>


More information about the cairo mailing list