Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: QuickDraw is deprecated in Mac OS X version 10.5 and later. Use Core Text instead for Mac OS X v10.5 and later, as described in Core Text Programming Guide. For applications that must run on Mac OS X v10.4 and earlier, use Apple Type Services (ATS), as described in Apple Type Services for Fonts Programming Guide.

How the Font Manager Works

The Font Manager works in conjunction with QuickDraw. QuickDraw treats the glyphs that make up text as small images that make up a larger, coherent image. It uses size information, such as height and width, the same way it users similar information when arranging an image that does not contain text. The Font Manager, by contrast, keeps track of detailed font information such as the glyphs’ character codes, whether fonts are fixed-width or proportional, and which fonts are related to each other by name. When QuickDraw draws text in a particular font, it sends a request for that font to the Font Manager. The Font Manager finds the font or the closest match to it that is available, and provides QuickDraw with the necessary information to lay out text and implement the appropriate stylistic variations.

In this section:

How QuickDraw Requests a Font
How the Font Manager Responds to a Font Request
How the Font Manager Scales Fonts
How the Font Manager Calculates Glyph Widths
How the Font Manager Tracks Changes to the Font Database


How QuickDraw Requests a Font

When your application calls a QuickDraw function, QuickDraw gets information from the Font Manager about the font specified in the current graphics port and the individual glyphs of that font. The Font Manager performs any necessary calculations and returns the requested information to QuickDraw.

QuickDraw makes its request for font information using a font input structure. This structure contains the font family reference, the size, the style, and the scaling factors of the font request.

QuickDraw makes a font request by filling in a font input structure (FMInput) and calling the function FMSwapFont. If your application needs to make a font request in the same way that QuickDraw does, you can call FMSwapFont. The FMSwapFont function has been optimized to return as quickly as possible if the request is for a recently requested font. Building the global width tables, which is described in “How the Font Manager Calculates Glyph Widths”, is one of the more time-consuming tasks in this process, which is why the Font Manager maintains a cache of width tables.

The Font Manager looks for the font family of the requested font and from that determines information about which font it can use to meet the request.

How the Font Manager Responds to a Font Request

The Font Manager returns information to QuickDraw in a font output structure (FMOutput). This structure contains a handle to the font resource that the FMInput structure requested, information on how different stylistic variations affect the display of the font’s glyphs, and the scaling factors.

When the Font Manager gets a request for a font in a font input structure, it attempts to find a font family resource for the requested font family. If the font family resource is available, the Font Manager looks in the font family resource for the font family reference of the appropriate font resource to match the request. If a font family resource is not available, the Font Manager takes additional steps until it finds a suitable substitute.

When responding to a font request, the Font Manager first looks for a font family resource of the specified size. It then looks for the stylistic variation that was requested. It does this by assigning weights to the various styles and then choosing the font whose style weight most closely matches the weight of the requested style.

If the Font Manager cannot find the exact font style that QuickDraw has requested, it uses the closest font style that it does find for that font and QuickDraw then applies the correct style to that font. For example, if an italic version of the requested font cannot be found, the Font Manager returns the plain version of the font and QuickDraw slants the characters as it draws them. The QuickDraw styles include the valuesbold, italic, underline, outline, shadow, condense, and extend.

With the additional complication of having both bitmapped and outline fonts available, this process can sometimes produce results other than those that you expect. The Font Manager can be set to favor either outline or bitmapped fonts when both are available to meet a request. (For information on how to do this, see “Favoring Outline or Bitmapped Fonts”). The following scenario is one example of how the font that is selected can be a surprise:

  1. You have specified that bitmapped fonts are to be preferred over outline fonts when both are available in a specific size.

  2. The system software on which your application is running has the bitmap font Times 12 and the outline fonts Times, Times Italic, and Times Bold.

  3. The user requests Times Bold 12.

  4. The Font Manager chooses the bitmapped version of Times 12 and QuickDraw algorithmically smears it to create the bold effect.

There is not much that you can do about such situations except to be aware that setting the Font Manager to prefer one kind of font over another has implications beyond what you might expect.

How the Font Manager Scales Fonts

Font scaling is the process of changing a glyph from one size or shape to another. The Font Manager and QuickDraw can scale bitmapped and outline fonts in three ways: changing a glyph’s point size, modifying the glyph (but not its point size) for display on a different device, and altering the shape of the glyph.

For bitmapped fonts, the Font Manager does not actually perform scaling of the glyph bitmaps. Instead the Font Manager finds an appropriate font and computes the horizontal and vertical scaling factors that QuickDraw must apply to scale the bitmaps. QuickDraw performs all modifications of bitmapped glyph fonts.

The simplest form of scaling occurs when the Font Manager returns scaling factors for QuickDraw to change a glyph from one point size to another on the same display device. If the glyph is bitmapped and the requested font size is not available, there are certain rules the Font Manager follows to create a new bitmapped glyph from an existing one (see “The Scaling Process for a Bitmapped Font”). If the glyph is from an outline font, the Font Manager uses the outline for that glyph to create a bitmap (see “The Scaling Process for an Outline Font”).

“Figure 2-11” shows how the Font Manager and QuickDraw scale a bitmapped font and an outline font from 9 points to 40 points for screen display. The sizes of the bitmapped fonts available to the Font Manager to create all 32 sizes were 9, 10, 12, 14, 18, and 24.


Figure 1-11  A comparison of scaled bitmapped and outline fonts

A comparison of scaled bitmapped and outline fonts

The Font Manager produces better results by scaling glyphs from outline fonts, because it changes the font’s original outline to the new size or shape, and then creates the bitmap. Outlines give better results than bitmaps when scaled, because the outlines are intended for use at all point sizes, whereas bitmaps are not.

The Font Manager also determines that a glyph must be scaled when moving it from one device to another device with a different resolution: for instance, from the screen to a printer. A bitmap that is 72 pixels high on a 72-dpi screen measures one inch, but on a 144-dpi printer it measures a half inch. In order to print a figure the same size as the original screen bitmap, QuickDraw needs a bitmap twice the size of the original. If there are no bitmaps available in twice the point size of the bitmap that appears on the screen, the Font Manager returns the proper scaling factors, and QuickDraw scales the original bitmap to twice its original size in order to draw it on the printer.

With some QuickDraw calls, your application can also use the Font Manager to explicitly scale a glyph by stretching or shrinking it. For example, you can use the Font Manager to scale a glyph that is normally 12 points to one that is 12 points high but stretched to the width of the entire page of text. Your application tells the Font Manager how to scale a glyph using font scaling factors, which are represented as proportions or fractions that indicate how the Font Manager should scale the glyph in the vertical and horizontal directions. The ratio given by the font scaling factors determines whether the glyph grows or shrinks. If the ratio is greater than one, the glyph increases in size, and if it is less than one, the glyph decreases in size. If the font scaling factors are 1-to-1 for both horizontal and vertical scaling, the glyph does not change size.

In some circumstances, the Font Manager finds a font and returns different scaling factors to QuickDraw. The scaling factors in a QuickDraw font request tell the Font Manager how much QuickDraw wants to scale the font, and the scaling factors returned by the Font Manager tell QuickDraw how much to actually scale the glyphs before drawing them.

In “Figure 2-12,” the font scaling factors are 2/1 in the horizontal direction and 1/1 in the vertical direction. The glyph stays the same height, but grows twice as large in width.


Figure 1-12  A glyph stretched horizontally

A glyph stretched horizontally

In “Figure 2-13,” the font scaling factors are 2/1 in the vertical direction and 1/1 in the horizontal direction. The glyph stays the same width, but grows to twice its original height.


Figure 1-13  A glyph stretched vertically

A glyph stretched vertically

In “Figure 2-14,” the scaling factors are 1/1 in the vertical direction and 1/2 in the horizontal direction. The glyph stays the same height but retains only half its width.


Figure 1-14  A glyph condensed horizontally

A glyph condensed horizontally

If the font scaling factors are 2/1 in both directions and the font is an outline font, then the Font Manager computes the size of the glyph as twice the specified size and QuickDraw draws the glyph. With bitmapped fonts, QuickDraw first looks for a bitmap at twice the size of the original before redrawing the glyph at the new point size.

The Scaling Process for a Bitmapped Font

Although the Font Manager does not scale the glyph bitmaps of a bitmapped font, it does compute the scaling factors that QuickDraw uses to perform the scaling. The Font Manager computes scaling factors other than 1/1 when the exact point size requested is not available. Font scaling is the default behavior; however you can disable it, as described below. When the Font Manager cannot find the proper bitmapped font that QuickDraw has requested and font scaling is enabled, it uses the following procedure:

  1. The Font Manager looks for a font of the same font family that is twice the size of the font requested. If it finds that font, the Font Manager computes and returns to QuickDraw factors to scale it down to the requested size.

  2. The Font Manager looks for a font of the same font family that is half the size of the font requested. If it finds that font, the Font Manager computes and returns to QuickDraw factors to scale it up to the requested size.

  3. The Font Manager looks for a font of the same font family that is the next larger size of the font requested. If it finds that font, the Font Manager computes and returns to QuickDraw factors to scale it down to the requested size.

  4. The Font Manager looks for a font of the same font family that is the next smaller size of the font requested. If it finds that font, the Font Manager computes and returns to QuickDraw factors to scale it down to the requested size.

  5. If the Font Manager cannot find any size of that font family, it returns the application font, system font, or a substitute font, as described in “How the Font Manager Responds to a Font Request”. The Font Manager computes and returns to QuickDraw the factors to scale that font to the requested size.

You can disable the scaling of bitmapped fonts in your applications by calling the function SetFScaleDisable. When the Font Manager cannot find the proper bitmapped font that QuickDraw has requested and font scaling is disabled, the Font Manager looks for a different font to substitute instead of scaling.

With scaling disabled, the Font Manager looks for a font with characters with the correct width, which may mean that their height is smaller than the requested size. The Font Manger returns this font and returns the scaling factors of 1/1, so that QuickDraw does not scale the bitmaps. QuickDraw draws the smaller font, the widths of which produce the spacing of the requested font. This is faster than font scaling and accurately mirrors the word spacing and line breaks that the document will have when printed, especially if fractional character widths are used. Disabling and enabling of font scaling are described in “Using Fractional Glyph Widths and Font Scaling.”

The Scaling Process for an Outline Font

The Font Manager always scales an outline font in order to produce a bitmapped glyph in the requested size, regardless of whether font scaling for bitmapped fonts is enabled or disabled. An outline font is considered to be the model for all possible point sizes, so the Font Manager is not scaling it from one “real” size to a “created” size, the way it does for a bitmapped font. It is drawing the outline in the requested point size, so that it can then create the bitmapped glyph.

How the Font Manager Calculates Glyph Widths

Integer glyph widths are measurements of a glyph’s width that are in whole pixels. Fractional glyph widths are measurements that can include fractions of a pixel. For instance, instead of a glyph measuring exactly 5 pixels across, it may be 5.5 pixels across. Fractional glyph widths allow the sizes of glyphs as stored by the Font Manager to be closer in proportion to the original glyphs of the font than integer widths allow. Fractional widths also make it possible for high-resolution printers to print with better spacing.

You can enable or disable the use of fractional glyph widths in your application, as described in “Using Fractional Glyph Widths and Font Scaling.” As a default, fractional widths are disabled to retain compatibility with older applications.

When using fractional glyph widths, the Font Manager stores the locations of glyphs more accurately than any actual screen can display. Since screen glyphs are made up of whole pixels, QuickDraw cannot draw a glyph that is 5.5 pixels wide. The placement of glyphs on the screen matches the eventual placement of glyphs on a page printed by the high-resolution printer more closely, but the spacing between glyphs and words is uneven as QuickDraw rounds off the fractional parts. The extent of the distortion that is visible on the screen depends on the font point size relative to the resolution of the screen.

The Font Manager communicates fractional glyph widths to QuickDraw through the global width table, a data structure that is allocated by the system. The Font Manager fills in this table by accessing data from one of several places:

The Font Manager looks for width data in the following sequence:

  1. For a bitmapped font, it first looks for a font glyph-width table in the font data structure, which is the record used to represent in memory the data in a bitmapped font resource. For an outline font, it first looks for data in the horizontal metrics table. The width table for bitmapped fonts is described in the section “The Bitmapped Font ('NFNT') Resource” while the width table for outline fonts is described in “The Horizontal Device Metrics Table.” Both sections are in Inside Macintosh: Text located on the Apple developer documentation website.

  2. It the Font Manger does not find this table, it looks in the font family data structure for a family glyph-width table. The font family record is used to represent in memory the data in a font family resource. This is described in “The Family Glyph-Width Table” in Inside Macintosh: Text located on the Apple developer documentation website.

  3. If the Font Manager does not find a family glyph-width table, it derives the global character widths from the integer width contained in the width/offset table in the bitmapped font record as described in “The Bitmapped Font ('NFNT') Resource” in Inside Macintosh: Text located on the Apple developer documentation website.s

Note: If you need to use different widths than those returned by the global width table, you should change the values in the global width table only. You should never change any values in the font resources themselves.

To use fractional glyph widths effectively, your application must get accurate widths when laying out text. Your application should obtain glyph widths either from the QuickDraw function MeasureText or by looking in the global width table. You can get a handle to the global width table by calling the function FontMetrics.

How the Font Manager Tracks Changes to the Font Database

The Font Manager uses a database to keep track of available fonts and provides a simple mechanism to track changes to the font database. Any operation that adds, deletes, or modifies one or more font family or font objects triggers an update of a global generation count. Each font family and font object modified during a transaction is tagged with a copy of the generation count.

You can use Font Manager accessor functions (FMGetGeneration, FMGetFontGeneration, FMGetFontFamilyGeneration) to get the current value of the generation count and the generation tag associated with a font family and font object. Then, you can use these values along with Font Manager enumeration functions to identify the changes in the database.



< Previous PageNext Page > Hide TOC


Last updated: 2007-12-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice