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)
GLYPH *T1_AASetString( int FontID, char *string, int len, long spaceoff, int modflag, float size, T1_TMATRIX *transform)
GLYPH* T1_AASetRect( int FontID, float size, float width, float height, T1_TMATRIX *transform)
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
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 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 and there will be 17 distinct gray shades including black
and white. The computational effort is considerably larger so that 4
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.