next up previous contents index
Next: Setting Operating Parameters Up: Antialiasing Previous: Antialiasing   Contents   Index

General Description

When fonts are displayed on screen at low sizes, the shapes of characters often get damaged because of rounding errors--a pixel can generally present two states: painted or non-painted. But the human eye can be fooled in a way that it ``thinks'' sub-pixel accuracy is given on the screen. This is done by considering which pixels are filled with ink to what degree and giving the physical pixel an appropriate shade of gray. For example, a pixel whose area would be covered 50% would get a 50% gray shade. This technique is called antialiasing.

There are several ways to implement antialiasing. t1lib implements antialiasing by internally generating a bitmap larger than needed and then subsampling. Depending on the subsampling factor which may be 2 or 4, this principle yields glyphs with 5 or 17 shades of gray including black and white.

There are three functions for generating antialiased glyphs:

 GLYPH *T1_AASetChar( int FontID, char charcode, 
                      float size, T1_TMATRIX *transform)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$}

 GLYPH *T1_AASetString( int FontID, char *string, int len, 
                        long spaceoff, int modflag, 
                        float size, T1_TMATRIX *transform)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$}

 GLYPH* T1_AASetRect( int FontID, float size,
                      float width, float height,
                      T1_TMATRIX *transform)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} Note the ``AA'' in the functions names which stand for AntiAliasing. The usage is identical to the usage of the functions T1_SetChar(), T1_SetString() and T1_SetRect(). So see [*] for an explanation of the arguments and their interpretation.

When an antialiased glyph is requested, the supplied size-value is multiplied by the current subsampling factor. For now, let us assume it is 2. Then the respective function for generating non-antialiased glyphs is called with all other arguments unchanged. The result is a bitmap twice as high and twice as wide as the user requested. Now, a $2\times2$ mask is moved over this bitmap and the number of painted pixels in this mask is considered at each place. According to the number of painted pixels one of 5 different gray shades is assigned to the resulting pixel. Since the mask is moved with an increment of 2 pixels in horizontal and vertical direction, the bitmap is at the same time subsampled by 2. Thus, the resulting bitmap is just of the size the user requested and its pixels each contain one of 5 gray shades.

Conceptually, the same applies for subsampling with 4. In this case the mask is of size $4\times4$ and there will be 17 distinct gray shades including black and white. The computational effort is considerably larger so that 4 $\times $ subsampling should only be used for very small sizes.

When moving the mask over double-sized bitmap it is aligned properly with respect to the characters' baseline (zero height) rather than with the characters' top or bottom line. This principle ensures, that the most important visual guideline in running text, the baseline, is represented in a consistent manor. This is especially important if one is using a serif-font. Thanks to Raph Levien, the algorithm described above in a verbose manor has been replaced by a much faster lookup-algorithm in t1lib V. 0.4-beta.


next up previous contents index
Next: Setting Operating Parameters Up: Antialiasing Previous: Antialiasing   Contents   Index
2004-10-04