[cairo] how do you draw an outline of a circle/ellipse

Uli Schlachter psychon at znc.in
Fri Nov 13 01:43:27 PST 2015


Hi,

since this wasn't yet said explicitly, I want to mention it:

Am 11.11.2015 um 09:32 schrieb Mark Olesen:
> I am unable to create an outline of a circle/ellipse.
> cairo_stroke below fills instead of creating an outline.
> Any ideas?
> 
> double width= 100;
> double height= 100;
> double x= 100;
> double y= 100;
> 
> cairo_save (cr);
> cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
> cairo_translate (cr, x + width / 2., y + height / 2.);
> cairo_scale (cr, width / 2., height / 2.);
> cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
> cairo_stroke (cr);
> cairo_restore (cr);

Swap the calls to cairo_stroke() and cairo_translate()

Alternatively:

cairo_save (cr);
cairo_translate (cr, x + width / 2., y + height / 2.);
cairo_scale (cr, width / 2., height / 2.);
cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
cairo_restore (cr);
cairo_save (cr);
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_stroke (cr);
cairo_restore (cr);

The "trick" is that save/restore does not save/restore the current path.

> 
> Following is the version of cairo I am using:
> lrwxrwxrwx 1 root root      21 Oct 31 05:03 /usr/lib/libcairo.so ->
> libcairo.so.2.11400.4
> lrwxrwxrwx 1 root root      21 Oct 31 05:03 /usr/lib/libcairo.so.2 ->
> libcairo.so.2.11400.4
> -rwxr-xr-x 1 root root 1236288 Oct 31 05:03 /usr/lib/libcairo.so.2.11400.4
> 
> If I get rid of scale, and put in a value for radius, such as 10, it will
> draw the outline. However, I will need cairo_scale to create an ellipse.
> 
> 
> Thanks in advance,
> Mark

Cheers,
Uli
-- 
Who needs a ~/.signature anyway?


More information about the cairo mailing list