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


Storing a Font Name in a Document

When presenting a font to a user, you should always refer to a font by name rather than by font family ID; this prevents several problems that can arise if you use the font family ID. One problem with identifying fonts by font family ID rather than by name is the plethora of font families available for the Macintosh computer. Many share the same font family ID, and even though the font the user wants is present in the System file, another font with the same ID may appear in a font menu. Another problem is that one font family may have different IDs on different computer systems, so that when the application opens the document using this font family on a different computer system, it can't find the proper font, even though it is available, and substitutes another.

If you've stored the name of the font in the document, you can find its font family ID by calling the GetFNum procedure, which is described on page 4-47. However, if the font isn't present in the system software when the user opens the document, GetFNum returns 0 for the ID. Since 0 is also the system font ID (or the neighborhood base font for the active script system), you need to double-check the name of the font from the document against the name of the system font, as illustrated in Listing 4-1.

Listing 4-1 Checking a font name against the system font name

FUNCTION MyGetFontNumber(fontName: Str255;
                         VAR fontNum: Integer): Boolean;
      {MyGetFontNumber returns in the fontNum parameter the number for }
      { the font with the given font name. If there's no such font, }
      { it returns FALSE.}

VAR
   systemFontName: Str255;

BEGIN
   GetFNum(fontName, fontNum);
   IF fontNum = 0 THEN 
      BEGIN {either the font was not found, or it is the system font}
      GetFontName(0, systemFontName);
      GetFontNumber := EqualString(fontName, systemFontName, FALSE, FALSE);
      END{ if theNum was not 0, the font is available }
   ELSE
      GetFontNumber := TRUE;
END;
Storing a font's name rather than its ID is a more reliable method of finding a font, because the name, unlike the font family ID, does not change from one computer system to another. You may also want to store the checksum of a font (the sum of the values of the bytes in the font data) with its name, to be sure that the version of the font is the same on different computer systems. Listing 4-2 on page 4-72 provides a function for computing a checksum.

If the font versions are different--that is, if the checksums don't match--you should offer users the option of substituting for the font temporarily (until they can find the proper version of the font) or permanently (with another font that is currently available).

If you are developing software for use with non-Roman fonts and the font is not found (by a function such as MyGetFontNumber above), you can use the neighborhood base font rather than the system font. The neighborhood base font is the lowest font ID for a particular script.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996