[cairo] Rectange got clipped off

Carl Worth cworth at cworth.org
Tue Feb 20 10:37:42 PST 2007

On Tue, 20 Feb 2007 11:01:26 -0600, "ken carlino" wrote:
> 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?

Yes. You're only seeing half of the stroke on the left and top
sides. The other half is outside the bounds of the surface.

> and what is the default pixel width of each stroke?

2.0 by default.

If you switch to a line width of 1.0 with those same coordinates, then
the lines will get "fainter" or "blurry" rather than occupying any
fewer pixels. For a discussion on why, and how to avoid that, see:


One thing that page doesn't explain is that the easiest way to get
desired results with cairo is to use a piece of graph paper. Number
the grid lines for the coordinates that you will use, and imagine each
little square as having a pixel centered withing it. Like this:

 0   1   2
 |   |   |
 |   |   |
 |   |   |

Then you can draw the path by using the coordinates you specify, (such
as (0,0) for the beginning of your rectangle, then extending to the
right to (10,0), down to (10,20), back left to (0,20), and back to

Finally, with that path in place, you can draw the outline of the
stroked path by extending out one-half the line width perpendicular
from the path.

If you do this with the default line width of 2.0 you'll see that half
of the left and top edges of the stroke end up off the paper.

If you do it with a line width of 1.0 you'll see that you're still
missing half of each of those lines---and also none of the final lines
are on the graph paper lines. Instead you'll get a bunch of
half-filled pixels which will look blurry, not sharp.

So with a line width of 1.0, you can get sharp lines by putting the
path itself half-way between the grid lines, so that the stroked
outline lands precisely on the grid lines. That is:

	cairo_set_line_width (cr, 1.0);
	cairo_rectangle (cr, 0.5, 0.5, 10, 20);
	cairo_stroke (cr);

NOTE: You might actually want a width,height of 9,19 there. I don't
know exactly which pixels you are wanting to hit here.

I hope that helps,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070220/1c12ba95/attachment.pgp

More information about the cairo mailing list