[cairo] Is Cairo able to fit my needs?

Innova-Studios - Juergen Ladstaetter info at innova-studios.com
Thu Oct 4 09:54:45 PDT 2007


Hi Baz,

I tried your suggestion with CAIRO_FILL_RULE_EVEN_ODD and
CAIRO_FILL_RULE_WINDING. Two black squares overlapping each other, each in a
single path:

    cairo_t *cr = cairo_create(surface);
   
	// Clear background
	cairo_set_source_rgb( cr, 1, 1, 1 );
	cairo_paint( cr );
	// paint code here

	cairo_new_sub_path( cr);
	cairo_line_to( cr, 0, 0 );
	cairo_line_to( cr, 0, 1000 );
	cairo_line_to( cr, 1000, 1000 );
	cairo_line_to( cr, 1000, 0 );
	cairo_line_to( cr, 0, 0 );
	cairo_set_source_rgba( cr, 0, 0, 0, 1);

	cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
	cairo_fill (cr);
	cairo_close_path( cr );

	cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);

	cairo_new_sub_path( cr);
	cairo_line_to( cr, 200, 200 );
	cairo_line_to( cr, 200, 400 );
	cairo_line_to( cr, 400, 400 );
	cairo_line_to( cr, 400, 200 );
	cairo_line_to( cr, 200, 200 );
	cairo_set_source_rgba( cr, 0, 0, 0, 1);

	cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
	cairo_fill (cr);
	cairo_close_path( cr );



    cairo_destroy( cr );
    cairo_surface_destroy( surface );

Merely between EVEN_ODD and WINDING there is no difference! The squares are
both black and at the point where the squares overlap, its also black - so
its not really the output that postscript should give :(

Or have I done anything wrong?

Kind regards, juergen

-----Ursprüngliche Nachricht-----
Von: Baz [mailto:brian.ewins at gmail.com] 
Gesendet: Donnerstag, 04. Oktober 2007 17:03
An: info at innova-studios.com
Cc: cairo at cairographics.org
Betreff: Re: [cairo] Is Cairo able to fit my needs?

On 04/10/2007, Jürgen <info at innova-studios.com> wrote:
> Hi there carl,
>
> when cairo doesnt have bitwise logical operators, how is cairo then able
> to display postscript images? i have several postscript images on my
> harddisk that use chained objects. that means you have e.g. a black square
> and inside of it another smaller black square. when you chain them it
> looks like a white square in a black square. (i can draw you an image to
> make it visible to you if you want me to)
>
> kind regards juergen

By 'chained objects' do you mean 'paths'?  Postscript doesn't let you
take arbitrary objects and composite them using bitwise operators - it
uses the 'painter model' where each object is simply layered on top of
previous objects with opaque paint.

However, the eofill operator in postscript can be used to get the
effect you described there, if those are two square sub-paths. I'm
guessing that's what those postscript files are doing - and Cairo can
do that too:
http://cairographics.org/manual/cairo-cairo-t.html#cairo-set-fill-rule

Cheers,
Baz



More information about the cairo mailing list