Important: The information in this document is obsolete and should not be used for new development.
Font Handling
As discussed under "Fonts" on page 1-44, a Macintosh font provides a specifically designed set of glyphs that implement the character set and other written forms that belong to a given script system. Fonts can be classified as 1-byte and 2-byte, and as bitmapped or outline. Some fonts provide plain (unstyled) glyphs, whereas others provide styled variations, such as bold or italic. This section summarizes some of the basic font issues to keep in mind when working with text, and especially multiscript text.Font Availability and Selection
You cannot display text in a given script system without a font for that script system. A font is available only if its file resides in the Fonts folder within the System Folder, or if its resources are installed in the System file itself.In terms of font availability and font selection for text, remember these points:
- The script management system uses font family ID (the ID number of the font resource of type
'FOND'
) to refer to fonts. That is the ID you supply as a parameter to text-handling calls. However, do not store font family ID numbers in your text files; store font names instead, and redetermine the ID numbers at run time with Font Manager calls. Font family IDs are not unique, and the system can renumber fonts between executions of your application.- Every font family has an ID number in a range that identifies the script system it belongs to. Identifying the font family used to write text is equivalent to identifying the script system of that text. See Figure 1-35 on page 1-50 for an illustration of resource ID ranges. A text string in a font with a font family ID of 200 is interpreted as Roman text, while the same text string in a font whose ID is 17000 is interpreted as Chinese text and displayed accordingly. You can use the Script Manager to convert font IDs into script codes.
- Because the script management system uses the font associated with a given range of text to determine the script system of that text, store your text in such a way that, for each run of text, you track the font to be used to display it.
- Because the script system can be determined from just the font family ID, the Font Manager can use that information to substitute a font of the proper script system, even when an entire font family is missing.
- Because the Roman script system is present in all Macintosh systems, at least two Roman fonts are always available: 12-point Chicago and 12-point Geneva.
System Font and Application Font
Macintosh system software recognizes two special fonts that should always be present: the system font and the application font. The system font is the font used for menus, dialog boxes, and other messages to the user from the Finder or Operating System. The application font is the suggested default font for use by monostyled TextEdit and by applications that do not support user selection of fonts. In all unmodified Roman versions of Macintosh system software, the system font is 12-point Chicago and the application font is 12-point Geneva.In all localized versions of Macintosh system software, whether Roman or not, the system font has a special font designator of 0, and the application font has a special designator of 1. These special designators are not actual font family resource ID numbers and cannot be used as such in Resource Manager calls; however, you can use them in place of a font family ID in the
txFont
field of the graphics port, and in text-related calls that take a font family ID, such asFontToScript
. The system maps the special designators to the actual font family IDs for the system font and application font. You can use the Font Manager to determine the actual ID numbers of the system font and application font for any system script.Remember these points about the system font and the application font, in relation to Chicago font, Geneva font, and the special designators:
Perhaps the most common mistake developers make in adapting their applications to global markets is to assume that the application font is always Geneva. Do not assume that different script systems have the same system and application fonts.
- On localized versions of system software in which the system script is Roman, Chicago is the system font and it has a font family ID of 0. The special designator 0 also refers to Chicago font.
- When the system script is non-Roman, Chicago has a different font family ID (usually 16383), and the special font designator 0 refers to the system font for the non-Roman system script. On system software in which Japanese is the system script, for example, a value of 0 in the
txFont
field means the Osaka font, which has a font family ID of 16384.- When the system script is Roman, Geneva is the application font and it has a font family ID of 3. The special designator 1 also refers to Geneva font.
- When the system script is non-Roman, Geneva has the same font family ID of 3, but the special font designator 1 refers to the application font for the non-Roman system script. On system software in which Thai is the system script, for example, a value of 1 in the
txFont
field means the Thonburi font, which has a font family ID of 26625.- The actual font family ID of the system font is specified in the low-memory global variable
SysFontFam
; the actual font family ID of the application font is specified in the low-memory global variableAppFontID
. You can get the actual font family ID of the system font or the application font by making Font Manager calls; see the chapter "Font Manager" in this book. You can also get the actual font family ID of the preferred system font or application font for a script system by making Script Manager calls; see the discussion of script variables in the chapter "Script Manager" in this book.
Roman Characters and Associated Fonts
All Macintosh script systems include the low-ASCII Roman characters and control characters as part of their character sets. Most non-Roman fonts provide glyphs for those low-ASCII Roman characters. If the font itself does not contain those characters, the script system substitutes characters from an associated font--a Roman font that is associated with that script system--for character codes (mostly in the low-ASCII range) that the script system determines are Roman. Some contextual script systems must use associated fonts because they need more glyphs than can fit into the high-ASCII range normally available for native glyphs.
In most cases your application does not have to account for associated fonts; glyphs from the associated font are substituted automatically when you draw text that contains Roman characters. However, keep in mind that font measurements (such as the results of the
- Note
- A script system specifies the associated font for its system font and application font, but may allow the user to select a single Roman font to associate with all other fonts of the script system.
GetFontInfo
andFontMetrics
procedures) always account for the width and height characteristics of both the current font and the associated font. This can sometimes cause unexpected results, such as a line height that is greater than the current font's expected line height. TheGetFontInfo
procedure is described in the chapter "QuickDraw Text" in this book; font measurement and theFontMetrics
procedure are further described in the chapter "Font Manager" in this book.There are several other issues to keep in mind related to Roman characters and Roman fonts:
- Remember that the presence of Roman glyphs in displayed or printed text does not necessarily imply that they were created with a Roman font. The Text Utilities can help you locate Roman characters in a text buffer and explicitly change them to the Roman script system, if you wish.
- As noted on page 1-56, the Roman script system does not have a consistent character set across all fonts. For example, character codes in the Symbol font map to different glyphs from the same character codes in the Geneva font. Conversely, identical symbols can have different character codes in different fonts. The division sign (\x97) is located at $D6 in the Helvetica font and $B8 in the Symbol font.
- Inconsistent character codes for symbols other than letters and numbers can also be a problem across script systems. For instance, in the Roman script system the division sign (\x97) is located at $D6 in most fonts, whereas in the Arabic script system the division sign (\x97) is at $9B.
Other Font Issues
In general, when drawing text, you set the font characteristics before you make a call, and the script management system makes sure that the font you specify is used. However, there are some issues and complications to keep in mind:
- If a particular size or styled variation (such as bold or italic) of a font is not available on the computer, the Font Manager can scale an existing size and QuickDraw can apply a style to an existing plain version of a font. Certain styles may be disabled in scripts where they are inappropriate. You can use the Script Manager to determine all of the valid styles for a given script system.
- The setting of the font force flag is controlled by the user when a script system that supports it is the system script. If the font force flag is
TRUE
, text written with a Roman font is considered instead to be text of the system script; any character codes corresponding to native characters of the system script are drawn in the system font rather than in the specified Roman font. If you do not want that to happen in your application, you must monitor the state of the font force flag and change it temporarily whenever necessary.- The font force flag exists to permit multiple-language support by applications that expect a single font. It is only a partial solution to the problem. Do not hardcode your application to require any single font.
- If your application needs to have a font whose characters should never be interpreted as system script characters (for example, symbol fonts used for paint program palettes), you can assign the font an ID in the reserved range $7E00 to $7FFF (uninterpreted symbols) rather than in the Roman range. Then, even if the font force flag is set to
TRUE
, your symbols are not re-interpreted as system-script characters.- When displaying characters as they are typed in by the user, you must make sure that the font for text display belongs to the same script system that is used for text input. See "Font Script and Keyboard Script" beginning on page 1-51.
- Many fonts--particularly those associated with non-Roman writing systems--do not draw legibly unless they are at least 12 point. However, you cannot assume that the system font size is always 12 point. Use QuickDraw, Font Manager, and Menu Manager calls to get the default size for the system font, default size for the current font, and required menu bar height for the system font.
- Do not assume that the application font exists in a 9-point size. Use the Script Manager to determine the application font family and size for legible small text.
- Diacritical marks (such as the acute accent over the "E" in "École") may extend above or below the normal limits for character height. The Font Manager allows you to either extend the spacing between lines or shrink the marked characters to make sure that the characters are not cut off at the top or bottom.
- If you use your own menu-definition (
'MDEF'
) resource to draw a Font menu in your application, be sure it can draw all font names correctly. It should use the font itself, or a font of the same script system, to display the font name. See the Menu Manager chapter of Inside Macintosh: Macintosh Toolbox Essentials for more information on creating menus.- A 2-byte font can be very large; outline fonts for 2-byte script systems can contain single resources over 6 MB in size. Large numbers of 2-byte fonts can be a storage problem for the user. Furthermore, because the Resource Manager limits the size of a file's resource fork to 16 MB, it may be difficult to include 2-byte fonts with your application or document files.