[cairo] Rectange got clipped off

Emmanuel Pacaud emmanuel.pacaud at lapp.in2p3.fr
Tue Feb 20 09:11:59 PST 2007


On mar, 2007-02-20 at 11:01 -0600, ken carlino wrote:
> Hi,
> 
> I use the following code to draw Rectange in cairo
> 
>   cairo_rectangle(cr, x, y , w, h);
>   cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
>   cairo_stroke(cr);
> 
> But for some reason, if I draw (0, 0, 10, 20) when the surface is 100X 100.
> The top/left lines of the rectangle are 'thinner' than the
> bottom/right lines of the rectangle.
> 
> Is there a reason for that? and what is the default pixel width of each stroke?

See the cairo FAQ, first entry:

http://cairographics.org/FAQ

In short, strokes are centered on coordinates. If you want to draw a
stroked rectangle wich is included in [x,y] [x+w, y+h] and with a
linewidth l, the right call is:

cairo_rectangle (cr, x + l / 2.0, y + l / 2.0, w - l, h - l);

	Emmanuel.




More information about the cairo mailing list