The OpenType Font File

An OpenType font file contains data, in table format, that comprises either a TrueType or a PostScript outline font. The rasterizer uses combinations of data from different tables to render the glyph data in the font.

Filenames

OpenType fonts may have the extension .OTF or .TTF, depending on the kind of outlines in the font and the creator's desire for downlevel compatibility.

Data Types

The following data types are used in the OpenType font file. All OpenType fonts use Motorola-style byte ordering (Big Endian):
Data TypeDescription
BYTE8-bit unsigned integer.
CHAR8-bit signed integer.
USHORT16-bit unsigned integer.
SHORT16-bit signed integer.
ULONG32-bit unsigned integer.
LONG32-bit signed integer.
FIXED32-bit signed fixed-point number (16.16)
FUNITSmallest measurable distance in the em space.
FWORD16-bit signed integer (SHORT) that describes a quantity in FUnits.
UFWORDUnsigned 16-bit integer (USHORT) that describes a quantity in FUnits.
F2DOT1416-bit signed fixed number with the low 14 bits of fraction (2.14).
  

Most tables have version numbers, and the version number for the entire font is contained in the Table Directory. Note that there are two different version number types, each with its own numbering scheme. USHORT version numbers always start at zero (0). Fixed version numbers always start at one (1.0 or 0x00010000).

The Fixed point format consists of a signed, 2's complement mantissa and an unsigned fraction. To compute the actual value, take the mantissa and add the fraction. Examples of 2.14 values are:

Decimal Value Hex ValueMantissaFraction
1.9999390x7fff 116383/16384
1.750x7000 10/16384
0.0000610x0001 01/16384
0.00x0000 00/16384
-0.0000610xffff -116383/16384
-2.00x8000 -20/16384

Organization of an OpenType Font

A key characteristic of the OpenType format is the TrueType sfnt "wrapper", which provides organization for a collection of tables in a general and extensible manner.

The OpenType font file begins at byte 0 with the Offset Table.
Type NameDescription
Fixedsfnt version 0x00010000 for version 1.0.
USHORT numTables Number of tables.
USHORT searchRange (Maximum power of 2 <= numTables) x 16.
USHORT entrySelector Log2(maximum power of 2 <= numTables).
USHORT rangeShift NumTables x 16-searchRange.
  

OpenType fonts that contain TrueType outlines should use the value of 1.0 for the sfnt version. OpenType fonts containing CFF data should use the tag 'OTTO' as the sfnt version number.

The Offset Table is followed at byte 12 by the Table Directory entries. Entries in the Table Directory must be sorted in ascending order by tag. Offset values in the Table Directory are measured from the start of the font file.
Type NameDescription
ULONGtag 4 -byte identifier.
ULONGcheckSum CheckSum for this table.
ULONGoffset Offset from beginning of TrueType font file.
ULONGlength Length of this table.
  

The Table Directory makes it possible for a given font to contain only those tables it actually needs. As a result there is no standard value for numTables.

Tags are the names given to tables in the OpenType font file. All tag names consist of four characters. Names with less than four letters are allowed if followed by the necessary trailing spaces. Table checksums are the unsigned sum of the longs of a given table. In C, the following function can be used to determine a checksum:

ULONG
CalcTableChecksum(ULONG *Table, ULONG Length)
{
ULONG Sum = 0L;
ULONG *Endptr = Table+((Length+3) & ~3) / sizeof(ULONG);

while (Table < EndPtr)
	Sum += *Table++;
return Sum;
}

Note: This function implies that the length of a table must be a multiple of four bytes. While this is not a requirement for the TrueType scaler itself, it is suggested that all tables begin on four byte boundries, and pad any remaining space between tables with zeros. The length of all tables should be recorded in the table directory with their actual length.

TrueType Collections

A TrueType Collection (TTC) is a means of delivering multiple OpenType fonts in a single file structure. TrueType Collections are most useful when the fonts to be delivered together share many glyphs in common. By allowing multiple fonts to share glyph sets, TTCs can result in a significant saving of file space.

For example, a group of Japanese fonts may each have their own designs for the kana glyphs, but share identical designs for the kanji. With ordinary OpenType font files, the only way to include the common kanji glyphs is to copy their glyph data into each font. Since the kanji represent much more data than the kana, this results in a great deal of wasteful duplication of glyph data. TTCs were defined to solve this problem.

The CFF rasterizer does not currently support TTC files.

The TTC File Structure

A TrueType Collection file consists of a single TTC Header table, two or more Table Directories, and a number of OpenType tables. The TTC Header must be located at the beginning of the TTC file.

The TTC file must contain a complete Table Directory for each different font design. A TTC file Table Directory has exactly the same format as a TTF file Table Directory. The table offsets in all Table Directories within a TTC file are measured from the beginning of the TTC file.

Each OpenType table in a TTC file is referenced through the Table Directories of all fonts which use that table. Some of the OpenType tables must appear multiple times, once for each font included in the TTC; while other tables should be shared by all fonts in the TTC.

As an example, consider a TTC file which combines two Japanese fonts (Font1 and Font2). The fonts have different kana designs (Kana1 and Kana2) but use the same design for kanji. The TTC file contains a single 'glyf' table which includes both designs of kana together with the kanji; both fonts' Table Directories point to this 'glyf' table. But each font's Table Directory points to a different 'cmap' table, which identifies the glyph set to use. Font1's 'cmap' table points to the Kana1 region of the 'loca' and 'glyf' tables for kana glyphs, and to the kanji region for the kanji. Font2's 'cmap' table points to the Kana2 region of the 'loca' and 'glyf' tables for kana glyphs, and to the same kanji region for the kanji.

The tables that should have a unique copy per font are those that are used by the system in identifying the font and its character mapping, including 'cmap', 'name', and 'OS/2'. The tables that should be shared by all fonts in the TTC are those that define glyph and instruction data or use glyph indices to access data: 'glyf', 'loca', 'hmtx', 'hdmx', 'LTSH', 'cvt ', 'fpgm', 'prep', 'EBLC', 'EBDT', 'EBSC', 'maxp', and so on. In practice, any tables which have identical data for two or more fonts may be shared.

Creating a TrueType Collection by combining existing OpenType font files is a non-trivial process, but a tool is available to help. The process involves paying close attention the issue of glyph renumbering in a font and the side effects that can result, in the 'cmap' table and elsewhere. The fonts to be merged must also have compatible TrueType instructions—that is, their preprograms, function definitions, and control values must not conflict.

TrueType Collection files use the filename suffix .TTC.

TTC Header

The purpose of the TTC Header table is to locate the different Table Directories within a TTC file. The TTC Header is located at the beginning of the TTC file (offset = 0). It consists of an identification tag, a version number, a count of the number of OpenType fonts (Table Directories) in the file, and an array of offsets to each Table Directory.
TypeName Description
TAGTTCTag TrueType Collection ID string: 'ttcf'
ULONGVersion Version of the TTC Header (initially 0x0001000)
ULONGDirectoryCount Number of Table Directories in TTC
ULONGTableDirectory[DirectoryCount] Array of offsets to Table Directories from the beginning of the file

Font Tables

The rasterizer has a much easier time traversing tables if they are padded so that each table begins on a 4-byte boundary. It is highly recommended that all tables be long aligned and padded with zeroes.

For OpenType fonts based on TrueType outlines, the following tables are used:
 
Tables Related to TrueType Outlines
TagName
cvtControl Value Table
fpgmFont program
glyfGlyph data
locaIndex to location
maxpMaximum profile
prepCVT Program
  

The PostScript font extensions define a new set of tables containing data specific to PostScript fonts that are used instead of the tables listed above.

 
Tables Related to PostScript Outlines
TagName
CFFPostScript font program (compact font format)
fvarApple's font variations table
MMSDMultiple master supplementary data
MMFXMultiple master font metrics
  

Whether TrueType or PostScript outlines are used in an OpenType font, the following tables are required for the font to function correctly:
 
Required Tables
TagName
cmapCharacter to glyph mapping
headFont header
hheaHorizontal header
hmtxHorizontal metrics
nameNaming table
OS/2OS/2 and Windows specific metrics
postPostScript information
  

There are also several optional tables that support vertical layout as well as other advanced typographic functions:

 
Advanced Typographic Tables
TagName
BASEBaseline data
GDEFGlyph definition data
GPOSGlyph positioning data
GSUBGlyph substitution data
JSTFJustification data
vheaVertical Metrics header
vmtxVertical Metrics
  

OpenType fonts may also contain bitmaps of glyphs, in addition to outlines. Hand-tuned bitmaps are especially useful in OpenType fonts for representing complex glyphs at very small sizes. If a bitmap for a particular size is provided in a font, it will be used by the system instead of the outline when rendering the glyph. ATM will support hand-tuned bitmaps in OpenType fonts.
 
Tables Related to Bitmap Glyphs
TagName
EBDTEmbedded bitmap data
EBLCEmbedded bitmap location data
EBSCEmbedded bitmap scaling data
  


 
Other OpenType Tables
TagName
DSIGDigital signature
hdmxLinear threshhold data
PCLTPCL 5 data
VDMXVertical device metrics