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.
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.
The following data types are used in the OpenType font file. All OpenType fonts use Motorola-style byte ordering (Big Endian):
Data Type | Description |
---|---|
BYTE | 8-bit unsigned integer. |
CHAR | 8-bit signed integer. |
USHORT | 16-bit unsigned integer. |
SHORT | 16-bit signed integer. |
ULONG | 32-bit unsigned integer. |
LONG | 32-bit signed integer. |
FIXED | 32-bit signed fixed-point number (16.16) |
FUNIT | Smallest measurable distance in the em space. |
FWORD | 16-bit signed integer (SHORT) that describes a quantity in FUnits. |
UFWORD | Unsigned 16-bit integer (USHORT) that describes a quantity in FUnits. |
F2DOT14 | 16-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 Value | Mantissa | Fraction |
---|---|---|---|
1.999939 | 0x7fff | 1 | 16383/16384 |
1.75 | 0x7000 | 1 | 0/16384 |
0.000061 | 0x0001 | 0 | 1/16384 |
0.0 | 0x0000 | 0 | 0/16384 |
-0.000061 | 0xffff | -1 | 16383/16384 |
-2.0 | 0x8000 | -2 | 0/16384 |
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 | Name | Description |
---|---|---|
Fixed | sfnt 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 | Name | Description |
---|---|---|
ULONG | tag | 4 -byte identifier. |
ULONG | checkSum | CheckSum for this table. |
ULONG | offset | Offset from beginning of TrueType font file. |
ULONG | length | 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.
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 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.
Type | Name | Description |
---|---|---|
TAG | TTCTag | TrueType Collection ID string: 'ttcf' |
ULONG | Version | Version of the TTC Header (initially 0x0001000) |
ULONG | DirectoryCount | Number of Table Directories in TTC |
ULONG | TableDirectory[DirectoryCount] | Array of offsets to Table Directories from the beginning of the file |
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
Tag | Name |
---|---|
cvt | Control Value Table |
fpgm | Font program |
glyf | Glyph data |
loca | Index to location |
maxp | Maximum profile |
prep | CVT 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
Tag | Name |
---|---|
CFF | PostScript font program (compact font format) |
fvar | Apple's font variations table |
MMSD | Multiple master supplementary data |
MMFX | Multiple 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
Tag | Name |
---|---|
cmap | Character to glyph mapping |
head | Font header |
hhea | Horizontal header |
hmtx | Horizontal metrics |
name | Naming table |
OS/2 | OS/2 and Windows specific metrics |
post | PostScript information |
There are also several optional tables that support vertical layout as well as other advanced typographic functions:
Advanced Typographic Tables
Tag | Name |
---|---|
BASE | Baseline data |
GDEF | Glyph definition data |
GPOS | Glyph positioning data |
GSUB | Glyph substitution data |
JSTF | Justification data |
vhea | Vertical Metrics header |
vmtx | Vertical 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
Tag | Name |
---|---|
EBDT | Embedded bitmap data |
EBLC | Embedded bitmap location data |
EBSC | Embedded bitmap scaling data |
Other OpenType Tables
Tag | Name |
---|---|
DSIG | Digital signature |
hdmx | Linear threshhold data |
PCLT | PCL 5 data |
VDMX | Vertical device metrics |