views:

36

answers:

1

I am trying to smooth text rendering using anti-aliasing. But it's not anti-aliased.

See the picture http://tinypic.com/r/2h7dy1i/4

First line is a png image created using pango and cairo. Second line is just an html <span> tag. It's in firefox, Ubuntu with Gnome DE. The difference can be better understood if you compare "W" and "v" between two lines.

The code responsible to draw text can be found on http://pastie.org/1073683 Font options are set on line 17 and 20.

Could anyone please tell me how can I make those two lines look same?

+1  A: 
cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_GRAY);

You asked for it, you got it. To get a match you'd need CAIRO_ANTIALIAS_SUBPIXEL. This is however not appropriate when you draw text to an image that might be displayed on another machine. There's no guarantee that the monitor on that machine is an LCD panel with the RGB stripes in a predictable order. Or that it in landscape orientation. Or that it is displayed with the exact original size. When there's a mismatch, the text will look quite poor.

Hans Passant
I'll use this code to generate image in my server running Debian lenny. People will see this in their monitor. And I have no way to know which monitor they will use. So from your answer it seems to me, if VRGB is used the generated image will look antialiased in the VRGB compatible display. And it will look bad in other display. Am I right??
Shiplu
What you have is proper. Compare to this: http://meta.stackoverflow.com/questions/65398/disable-cleartype-subpixel-rendering-for-image-based-flair
Hans Passant
So, Firefox is also determines my display type first. Then uses compatible subpixel antialias option. If yes. how do I know which antialias option is firefox using? and how do I mimic the same behavior in my script so that At least in my pc I can see it antialiased properly.
Shiplu
Yes, firefox has no trouble rendering text with the subpixel interpolation, it runs on the machine that displays the text. Your web server cannot know, it is on the wrong end of the wire and it can't ask the browser. If you want the browser to render the text then you'll have to generate HTML, not an image.
Hans Passant
Thanks Hans for clearing everything. I have one more question. When I generate image its md5 doesn't change. no matter what subpixel method I use, It doesn't change the md5 of the image. So It seems that some how antialiasing mechanism is not getting executed by cairo
Shiplu