[cairo] Non-antialiased rendering in image surface

M Joonas Pihlaja jpihlaja at cc.helsinki.fi
Sat Jun 26 11:37:56 PDT 2010

On Sat, 26 Jun 2010, cu wrote:

> I see. That's unfortunate. I use non-antialiased rendering for certain
> objects when it's important that their edges match perfectly (without a
> thin line that seems to appear when fill is made in antialiased mode).

Non-antialiased line rendering by cairo looks rather gnarly for 
anything but vertical and horizontal lines, so please don't get your 
hopes up.  For pure vertical and horizontal lines you can get equally 
sharp edges by using an identity user-to-device transform, a line 
width of 1.0, and stroke input coordinates which are exactly at pixel 
centres.  The technique is explained in more detail here: 

The principles behind http://cairographics.org/FAQ/#sharp_lines are at 
play even in non-antialiased rendering, so you'll want to mind them 
even then.  Ignoring the advice about using half-pixel centres as your 
line coordinates puts you at the mercy of rounding rules at the very 
edges of stroked lines, so your line may be shifted by one pixel 
left/right/top/bottom next time cairo or pixman is updated, or 
*shudder* your width=1.0 line might even turn out as a width=2.0 line!
So while using non-antialiased rendering might seem like it's more 
robust as to the sharpness of lines, it's not really any better than 
being mindful of your input coordinates and transforms, and might in 
fact be a little worse.



More information about the cairo mailing list