[cairo] push pop and stroke

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Sun Dec 9 13:51:47 PST 2007


Donn wrote:
>         cr.push_group()
>         cr.set_line_width( 20 )
>         cr.save()
> Aiming for a 20 'pixel' stroke around the circle.
>         cr.set_source_rgb(1,1,0)
>         cr.arc(100, 200, 50, 0, 2 * pi)
>         cr.fill_preserve()
>         cr.set_source_rgb(0,0,0)
>         cr.restore()
> Stroked after the restore as per tutorial suggestion.
>         cr.stroke()
>         pat = cr.pop_group()

Now you have a pattern, which contains an ellipse with a 20 unit wide
stroke, measured in pattern units.

You can transform this pattern, but every such transformation will
affect all parts of the pattern equally. (In fact the pattern is
likely to be backed by an image surface at this point, with all
the drawing history forgotten.)

>         for x in range(0,100):
>             s = (100-x)/100.0
>             print s
>             cr.scale( s,s ) 

Hmm, here you're scaling outside of cr.save / cr.restore.

> It gets bigger each time
>             cr.save()
>             cr.translate(x*2,100)
>             cr.set_source(pat) 
>             cr.paint()
> Draws the circles okay, but each one has a proportional stroke - how would I 
> make them all draw a 20 px stroke?
>             cr.restore()

You have to draw individual circles - or at least stroke them individually.

HTH,

Bertram


More information about the cairo mailing list