Font rasterization

From Wikipedia, the free encyclopedia

Font rasterization is the process of converting text from a vector description (as found in scalable fonts such as TrueType fonts) to a raster or bitmap description. This often involves some anti-aliasing on screen text to make it smoother and easier to read. It may also involve "hinting", that is, the use of information precomputed for a particular font size.

[edit] Types of rasterization

Aliasing, greyscale anti-aliasing and ClearType anti-aliasing.
Aliasing, greyscale anti-aliasing and ClearType anti-aliasing.

In modern operating systems, rasterization is normally provided by a shared library common to many applications. Such a shared library may be built in to the operating system or the desktop environment, or it may be added at some later time. In principle, each application may use a different font rasterization library, but in practice most systems attempt to standardize on a single library.

In older systems and in some embedded systems, fonts are represented as bitmaps pre-drawn at specific sizes. However, most modern systems use fonts represented as mathematical primitives, allowing arbitrary scalability.

Simple rasterization without antialiasing
Simple rasterization without antialiasing

The simplest form of rasterization is simple line-drawing with no antialiasing of any sort. This is the fastest method (that is, it requires the least computation to place on screen). This approach has the disadvantage that glyphs may lose their definition when rendered at small sizes. Therefore, many fonts contain "hints" which aid the system's rasterizer in deciding where to render pixels for particularly troublesome areas in the glyphs, or sets of hand-tweaked bitmaps to be used at specific pixel sizes.

Rasterization with antialiasing without hinting.
Rasterization with antialiasing without hinting.
Rasterization with antialiasing with hinting. Here pixels are forced to fall into integral pixel coordinates whenever possible
Rasterization with antialiasing with hinting. Here pixels are forced to fall into integral pixel coordinates whenever possible

A more complicated approach is to use standard anti-aliasing techniques from computer graphics. This can be thought of as determining, for each pixel, how much of that pixel is occupied by the letter, and drawing that pixel with that degree of opacity. For example, when drawing a black letter on a white background, if a pixel ideally should be half filled (perhaps by a diagonal line from corner to corner) it would be drawn in 50% gray. Simple application of this procedure can lead to somewhat blurry glyphs: for example, if the letter includes a vertical line which should be one pixel wide but falls exactly between two pixels, it will appear on screen a two-pixel-wide gray line. This blurriness is a tradeoff of clarity for accuracy. However, modern systems often force lines to fall within integral pixel coordinates, which makes the glyphs look sharper, but instead makes the lines slightly wider or thinner than they would have looked on a printed sheet of paper.

Rasterization with subpixel rendering for an RGB flat panel display
Rasterization with subpixel rendering for an RGB flat panel display

Most computer displays have pixels made up of multiple subpixels (typically one each for red, green, and blue, which are combined to produce the full range of colours). In some cases, particularly with flat panel displays, it is possible to exploit this by rendering at the subpixel resolution rather than using whole pixels, which can increase the effective resolution of the screen. This is generally known as subpixel rendering; Microsoft's proprietary implementation goes by the name ClearType.

Detail of subpixel rendering, showing positions of individual color pixels
Detail of subpixel rendering, showing positions of individual color pixels

[edit] Currently used rasterization systems

Windows uses a combination of font-level hinting and antialiasing. Since Windows XP, it has also supported subpixel rendering. The Windows rasterizer is an example of one that prioritizes clarity; by forcing text into integral coordinate positions (and not even antialiasing certain fonts at certain sizes), it becomes easier to read on the screen, but often bears little resemblance to the font as printed.

Mac OS X's Quartz is distinguished by the use of floating-point positioning; it does not force glyphs into exact pixel locations, instead using various antialiasing techniques, including subpixel rendering, to position characters and lines more accurately. The result is that the on-screen display looks extremely similar to printed output, but can occasionally be difficult to read at smaller point sizes.

RISC OS uses its own font rendering system, with features such as scaffolding and hinting, sub-pixel anti-aliasing and background blending [1].

Most other systems use the FreeType library, which falls somewhere between Microsoft's and Apple's implementations; it supports hinting and anti-aliasing, and optionally performs subpixel rendering. Due to problems with patent licensing, many binary distributions of it do not support hinting non-Free fonts with the same quality as the Windows and OS X rasterizers, although the functionality is present and easily enabled. The Free fonts included with most Linux distributions look better with FreeType's "auto-hinting" mode, which is high-quality and not encumbered by patents.

D-Type Font Engine is an independent, proprietary and portable font rasterization library. It provides anti-aliasing, subpixel precision, automatic hinting, bitmap filtering and other techniques that can improve the appearance and legibility of text on screen. According to the authors, the display quality of D-Type Font Engine can be configured to match or exceed the quality of Windows and Mac OS X font rasterizers while using only non-hinted TrueType, OpenType or Type 1 fonts.