Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Text /
Chapter 4 - Font Manager / Using the Font Manager


Using Width Tables

When the Font Manager responds to a request to make a font available, the font resource is loaded into memory and the Font Manager allocates memory for various tables that are needed to use the font. To make font usage more efficient, the Font Manager maintains a cache of the tables for the most recently used fonts, so that it does not have to reread the resources and rebuild the tables more often than necessary. The Font Manager can cache the tables for up to 12 fonts. For outline fonts, the cached information includes the width tables and any bitmaps that have been created from the outlines.

The global width table contains the widths of all the glyphs of one font. If you are measuring text to be displayed on the screen, you can use the QuickDraw procedure MeasureText to determine glyph widths; however, if you are printing text and need to determine glyph widths, you have to use widths from the global width table. The OutlineMetrics function returns the individual widths of glyphs for an outline font and the FontMetrics procedure returns the width of the largest glyph in a bitmapped font. You can also directly access the global width table, which is defined by the WidthTable data type. This data type is described in the section "The Global Width Table" beginning on page 4-39.

To use the global width table, you can get a handle to it from the FontMetrics procedure, or you can use the handle stored in the global variable WidthTabHandle. The global variable WidthPtr contains a pointer to the global width table; however, this variable is reliable only immediately after a call to FMSwapFont. Like all pointers to data in handles, WidthPtr may become invalid after a call to the Memory Manager. In general, use the WidthTabHandle global variable instead of the WidthPtr global variable.

The global variable WidthListHand is a handle to a list of up to 12 handles to recently used width tables. You can scan this list and look for width tables that match the font family ID, size, and style of the font you wish to measure. If you reach a width-table handle that contains -1 in the tabFont, fID, and aFID fields, that width table is invalid. When you reach a handle that is equal to NIL, you have reached the end of the list.

IMPORTANT
Do not use the values from the global width table if your application is running on a computer on which non-Roman script systems are installed. You can check to see if a non-Roman script system is present by calling the GetScriptManagerVariable function with a selector of smEnabled; if the function returns a value greater than 0, at least one non-Roman script system is present and you need to call MeasureText to measure text that is displayed on the screen. Measuring text from a non-Roman script system for printing is handled by the printer driver.
If your application directly manipulates data in a font resource (for example, if your application edits fonts), you may need to flush the Font Manager's cache, so that the cached information reflects any changes that your application makes. The FlushFonts function, which is described on page 4-62, erases all of the Font Manager's caches. The Font Manager then rebuilds the cache as new fonts are called into use again.

Normally, fonts are purgeable, which means that the space used for each font's resource information can be released from memory. You can temporarily prevent a font from being purged by locking it with a call to the SetFontLock procedure. A subsequent call to SetFontLock unlocks the font, allowing the Font Manager to purge it from memory. The SetFontLock procedure is described on page 4-61.

If you are calculating the amount of extra width that is added to a glyph as a result of adding a font style, you can choose how you want the Font Manager to determine the extra pixels needed. It can find the information in the style property field of the font family resource or from the style extra field in the Font Manager's internal tables. If the value of the global variable FDevDisable is 0, the Font Manager uses the style extra value from its internal tables; if FDevDisable is any other value, the Font Manager uses the value from the style property field, which is described on page 4-88.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996