Summer 91 - SCORING POINTS WITH TRUETYPE
SCORING POINTS WITH TRUETYPE
KONSTANTIN OTHMER AND MIKE REED
TrueType, Apple's outline font technology, opens up a world of possibilities for
improved handling of text. For example, with outline fonts, users can resize text as
they've always been able to resize other objects in drawing programs--by grabbing
handles and dragging. This article shows how to program this and other exciting
transformations to text.
The Font Manager in System 7.0 can use TrueType outline fonts, in addition to
bitmapped fonts, to produce text on the screen and on a printer. In outline fonts, the
appearance of individual characters is defined by outlines, not bitmaps. The TrueType
font mechanism is also available as an INIT for System 6.0.7 users.
Your application can take advantage of the special capabilities provided by TrueType
fonts to transform text in decorative and useful ways. These transformations include
shrinking or stretching text to fit a given bounding box and creating patterned,
antialiased text. This article provides routines for accomplishing both of these kinds of
transformations. First, though, let's explore in more detail how TrueType fonts differ
from their predecessor, bitmapped fonts.
WHY TRUETYPE IS TRULY WONDERFUL
To understand why TrueType is truly wonderful, you first have to understand the
trouble with bitmapped fonts. With bitmapped fonts, to generate fonts of sizes for
which no bitmap exists, QuickDraw simply picks an available font size according to a
gnarly algorithm and stretches or shrinks the bits. Unfortunately, when a bitmap is
resized the resulting image is often far from pleasing.
This problem is easily understood: imagine you're shrinking a 1-bit image by a factor
of two in the vertical dimension. This means two pixels in the source image combine to
form one pixel in the result. If both source pixels are black or both are white, the
solution is easy. The problem comes when the two source pixels are different. In this
case, since most images on the Macintosh appear on a white background, QuickDraw
preserves black. Thus, if either source pixel is black, the result is black.
QuickDraw uses this same algorithm for larger shrinks. When an image is shrunk
vertically by a factor of eight, if any one of the eight source pixels is black, the
resulting pixel is black. Because there is more information in the source than can be
represented in the destination, the resulting image often looks ragged and is typically
too dark.
A similar problem is encountered when enlarging an image. QuickDraw enlarges
images by replicating pixels; thus, the result becomes blocky. There simply is not
enough information in the source image to provide a better scaled-up representation.
Figure 1 shows a 72-point B in the bitmapped Times® font resized by various
amounts.
Figure 1 Resizing a Bitmapped Character
This problem with resizing has further implications. Have you ever tried to resize
text in the same way you resize other objects in a drawing program like MacDraw®?
If you have, you've discovered that when you move the handles on the bounding box, the
text clipping and formatting change, but the text isn't resized. This inconsistency
between the way text and other objects are handled can be very confusing to users and
may deny them the function they really want: to stretch the text to fill the box. The
reason for this difficulty is--you guessed it! Although resizing an object such as a
rectangle produces excellent results, resizing a bitmapped font results in an image