[cairo] thin antialiased lines

control H control.h at gmail.com
Mon Jul 16 07:17:16 PDT 2007


> There _are_ known techniques for drawing very nice non-antialiased
> lines, (much better than what GDK does I believe). The key idea is to
> use a specially-created polygon for the pen called a Pen
> Polygon. This a technique developed by John Hobby for his Ph.D. and
> then also described much more succinctly here:
>
>         [Hobby89] John D. Hobby, Rasterizing Curves of Constant Width,
>         JACM 36(2), 1
>
>         http://cm.bell-labs.com/who/hobby/87_2-04.pdf

Interesting, thanks for the link. I understand from your remark of
adding the non AA mode for rendering under duress, that it's not
likely to be implemented soon, if at all. Unless I can force you to...
and do it under duress again. Just kidding.


> So, augmenting cairo to do this well is really as simple as writing a
> single function that accepts a desired line width and computes a Pen
> Polygon, (several Pen Polygons for small, common sizes could even be
> pre-computed and just returned from a table).

I'm afraid for me as an end user of cairo, it's not that simple... :(
I'll see if I can find something in the mailing list archives.

More and more programs are adding support for cairo based output, and
have the same "problem" of too thick or blurry lines. One example is
the statistical package R (www.r-project.org). Plotting a normal
distribution looks very nice, while plotting a survival curve (which
basically consists of more or less horizontal lines) looks blurry.
What would you suggest to fix this? If I understand correctly from
googling around some hours, will auto snapping fix this? And will this
auto snapping be implemented in future? If yes, then there's no need
for me anymore to disable AA.

> > [Is there a way] to draw small anti aliased lines of 1
> > pixel thick and in the correct color?
>
> I'd encourage you to think deeply about what you're actually asking
> for here. The anti-aliasing that cairo does involves computing
> coverage for partially-covered pixels. So the results you are getting
> now _are_ in the correct color. When a line has a width of 0.5 and is
> black, you shouldn't expect to get a pixel darker than "half black"
> ever.

Yes I know, when I wrote it I wasn't thinking deeply, so actually I
already guessed it would be a bit of a contradictio in terminus. My
idea was just to intensify all pixels a bit, and I hoped the result
would still be "anti aliased" but with more intensive colors.

Anyway, thanks for the explanatory replies I received.


More information about the cairo mailing list