[pygtk] Cairo Line Width

Tim Evans t.evans at aranz.com
Fri Sep 26 12:32:29 WST 2008


Jeffrey Drake wrote:
> In my code below, I set a line width of 1 and then when I go to draw a
> grid, what appears is an antialiased line of still width of 2. I need a
> single pixel, not the ugly 2 width beast as shown before.
> 
> The problem is when drawing the horizontal grid below.
> 
> Any ideas on how to fix this?

Add (or subtract) 0.5 to the x and y of your line endpoints.

In cairo, the top left pixel is a rectangle from (0,0) to (1,1).  The 
top left corner is (0,0) and the bottom right corner is (1,1).  If you 
have a 1-pixel wide line from (10,10) to (100,10) only half of that 
1-pixel is in the 10th row, the other half being in the 9th row.  Cairo 
renders this by antialiasing, so you get a 2-pixel side 50% gray line 
rather than the 1-pixel black line you were expecting.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list