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 / Font Manager Reference
The Outline Font ('sfnt') Resource


The Font Directory

The font directory is a guide to the tables in the outline font resource. It provides you with the information that is needed to efficiently find the other parts of the resource. Each table in the resource has a tag name, a checksum, a location that is defined as an offset in bytes from the first byte of the resource, and a length in bytes. To use the data in a table, you first find the table's tag name in the font directory and then access its data starting at the specified location.

The font directory consists of an offset component and a variable length array of directory entries, as shown in Figure 4-17.

Figure 4-17 The font directory

The font directory offset component specifies the number of tables in the resource (and thus in the directory component). It contains several values that you can use to optimize searching through the directory components for a tag name:

The search range, entry selector, and range shift values are used together to construct a binary search through the directory if it is too large for an efficient sequential search. Note, however, that most programs that access kerning data use a linear search and do not make use of these values.

If a font does contain a large number of tables, you can perform a binary search
of the directory components. You use the range shift value as the initial position in the directory to examine. Compare the tag name of the component at this position with
the one you are searching for. If the target tag name comes before the one you are searching for, search from the beginning of the directory to the range shift position. If the target name comes after the one you are searching for, search from that position to
the end of the directory.

The font directory table entries are sorted alphabetically by tag name. Each component consists of the following elements:

Listing 4-2 shows a function that determines the checksum of a given table.

Listing 4-2 Calculating the checksum of a given table

TYPE
   LongPtr = ^LongInt;

FUNCTION MyCalcTableChecksum (table: LongPtr;
                              lngth: LongInt): LongInt;
VAR
   sum : LongInt;
   mask: LongInt;

BEGIN
   sum := 0;
   WHILE lngth > 0 DO BEGIN
      IF lngth > 3 THEN
         sum := sum + table^
      ELSE BEGIN
         mask := BitShift($FFFFFFFF, 8 * (4 - lngth));
         sum := sum + BitAnd(table^, mask);
         table := LongPtr(ord(table) + 4);
         lngth := lngth - 4;
      END;
   END;
   MyCalcTableChecksum := sum;
END;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996