[cairo] Drawing diagonal lines with antialiasing off

Jason Dorje Short jdorje at users.sf.net
Tue Sep 27 20:47:27 PDT 2005


Bill Spitzak wrote:
> I still feel this is going to be one of the big annoyances in Cairo and 
> will have to be addressed. The fact that the original poster thought 
> "turn off antialiasing" was how they got thin lines indicates that a lot 
> of people have no idea what is going on or how to fix it, and that their 
> attempted solutions are going to make Cairo output look like crap. 
> Trying to explain it is hopeless, it just confuses and annoys them, and 
> makes a barrier to getting started with Cairo. Some scheme must be come 
> up with so that Cairo defaults to a behavior that matches virtually 
> every other graphics system in the world.
> 
> The solution is that a line width of 0.0 is a special case: Cairo draws 
> "thin" but constant-width lines, of 1 pixel on present-day screens. The 
> lines are positioned so that horizontal and vertical ones are opaque and 
> will cover the antialised edges of any rectangle drawn using the same 
> coordinates. Diagonal lines are still antialiased and no guarantee is 
> made about them except they will join horizontal and vertical lines. 
> Line caps are ignored. The value actually has to be zero, a very tiny 
> non-zero value will draw an invisibly-faint antialiased line, and 
> negative line widths should act like the absolute value, except they 
> flip any asymetrical line caps.

Xlib has a fixed definition of how a line is drawn, which is based on 
integer coordinates (I've read this definition before but now I can't 
find it).  Cairo has a different definition that uses floating-point 
coordinates.

Obviously the definitions differ for width-1 lines, but I don't think a 
special case for 0 is a workable solution; it's just a hack and will 
give wrong behavior in some cases (a width0 line should be width 0, 
after all).  It's an insufficient workaround because this off-by-0.5 
error will occur for any line of odd width.  The only possible 
workaround I can think of is to provide a separate function, or a 
wrapper, that accepts integer coordinates in the XLib format and 
converts them to cairo coordinates before calling the cairo function.

-jason


More information about the cairo mailing list