logo - blitzware
blitzware.com - new technology review

Inside ClearType in Windows Longhorn

By Maxim Shemanarev

Some time ago programmer and author Ian Griffiths wrote in his blog about the main problem with ClearType in Windows XP. It turns out that while ClearType is great for rendering small glyphs, large ones look a lot more jagged, especially in cases like the top and bottom of an upper-case "O." In contrast, Ian admires the new ClearType algorithm in Longhorn because that very O looks smooth.

Steve Gibson (the programmer most famous for his "ShieldsUP!" security checking site) has done some research about how it works in general. After I carefully studied Steve's method I came to the conclusion that the secret is in anti-aliasing. The ClearType technology is essentially anti-aliasing too (LCD subpixel), but it works well only for vertical or nearly vertical edges. At the same time, classical gray scale anti-aliasing does not depend on the edge direction. So, if we combine both gray scale and LCD subpixel anti-aliasing techniques, we can obtain results very similar to what we see in Longhorn.

I'm presenting here source code in C++ for achieving Longhorn-like results in typeface rendering. (For examples of the results, see http://antigrain.com/stuff/lcd_font.png , and http://antigrain.com/stuff/lcd_font_zoom.png for a zoomed-in version.) The code is written for WinAPI and doesn't depend on any other libraries or tools. To obtain gray scale Anti-Aliased glyphs, I used the WinAPI function GetGlyphOutline() , with 65 levels of gray. That seems enough to try out the idea. The glyphs are rendered with triple X-axis resolution and then alpha-blended with the canvas considering color triplets in LCD displays.

The bulk of this article consists of two listings. Listing One gives all rendering classes and functions, while Listing Two contains an example of the WM_PAINT event processing.