Features and Lookups

Features define the functionality of a TrueType Open font and they are named to convey meaning to the text-processing client. Consider a feature named "liga" to create ligatures. Because of its name, the client knows what the feature does and can decide whether to apply it. A current list of TrueType Open registered features and their are listed in the TrueType Open Registry chapter at the end of this document. Font developers can use these features, as well as create their own.

After choosing which features to use, the client assembles all lookups from the selected features. Multiple lookups may be needed to define the data required for different substitution and positioning actions, as well as to control the sequencing and effects of those actions.

To implement features, a client applies the lookups in the order the lookup definitions occur in the LookupList. As a result, within the GSUB or GPOS table, lookups from several different features may be interleaved during text processing. A lookup is completed when the client locates a target glyph or glyph context and substitutes or positions a glyph.

Note: The substitution (GSUB) lookups always occur before the positioning (GPOS) lookups. The lookup sequencing mechanism in TrueType relies on the font to determine the proper order of text-processing operations.

Lookup data is defined in one or more subtables that contain information about specific glyphs and the operations to be performed on them. Each type of lookup has one or more corresponding subtable definitions. The choice of a subtable format depends upon two factors: the precise content of the information being applied to an operation, and the required storage efficiency. (For complete definitions of all lookup types and subtables, see the the GSUB and GPOS chapters of this document.)

TrueType Open features define information that is specific to the layout of the glyphs in a font. They do not encode information that is constant within the conventions of a particular language or the typography of a particular script. Information that would be replicated across all fonts in a given language belongs in the text-processing application for that language, not in the fonts.

Feature List Table

The headers of the GSUB and GPOS tables contain offsets to Feature List tables (FeatureList) that enumerate all the features in a font. Features in a particular FeatureList are not limited to any single script. A FeatureList contains the entire list of either the GSUB or GPOS features that are used to render the glyphs in all the scripts in the font.

The FeatureList table enumerates features in an array of records (FeatureRecord) and specifies the total number of features (FeatureCount). Every feature must have a FeatureRecord, which consists of a FeatureTag that identifies the feature and an offset to a Feature table (described next). The FeatureRecord array is arranged alphabetically by FeatureTag names.

Note: The values stored in the FeatureIndex array of a LangSys table are used to locate records in the FeatureRecord array of a FeatureList table.

FeatureList table

Type

Name

Description

uint16

FeatureCount

Number of FeatureRecords in this table

struct

FeatureRecord

Array of FeatureRecords

[FeatureCount]

—zero-based (first feature has FeatureIndex = 0)

—listed alphabetically by FeatureTag


FeatureRecord

Type

Name

Description

Tag

FeatureTag

4-byte feature identification tag

Offset

ð Feature

Offset to Feature table

—from beginning of FeatureList


Feature Table

A Feature table defines a feature with one or more lookups. The client uses the lookups to substitute or position glyphs.

Feature tables defined within the GSUB table contain references to glyph substitution lookups, and feature tables defined within the GPOS table contain references to glyph positioning lookups. If a text-processing operation requires both glyph substitution and positioning, then both the GSUB and GPOS tables must each define a Feature table, and the tables must use the same FeatureTags.

A Feature table consists of an offset to a Feature Parameters (FeatureParams) table (currently reserved for future use and set to NULL), a count of the lookups listed for the feature (LookupCount), and an arbitrarily ordered array of indices into a LookupList (LookupListIndex). The LookupList indices are references into an array of offsets to Lookup tables.

To identify the features in a GSUB or GPOS table, a text-processing client reads the FeatureTag of each FeatureRecord referenced in a given LangSys table. Then the client selects the features it wants to implement and uses the LookupList to retrieve the Lookup indices of the chosen features. Next, the client arranges the indices in the LookupList order. Finally, the client applies the lookup data to substitute or position glyphs.

Example 3 at the end of this chapter shows the FeatureList and Feature tables used to substitute ligatures in two languages.

Feature table

Type

Name

Description

Offset

ð FeatureParams

= NULL (reserved for offset to FeatureParams)

uint16

LookupCount

Number of LookupList indices for this feature

uint16

LookupListIndex

Array of LookupList indices for this feature

[LookupCount]

—zero-based (first lookup is LookupListIndex = 0)


Lookup List Table

The headers of the GSUB and GPOS tables contain offsets to Lookup List tables (LookupList) for glyph substitution (GSUB table) and glyph positioning (GPOS table). The LookupList table contains an array of offsets to Lookup tables (Lookup). The font developer defines the Lookup sequence in the Lookup array to control the order in which a text-processing client applies lookup data to glyph substitution and positioning operations. LookupCount specifies the total number of Lookup table offsets in the array.

Example 4 at the end of this chapter shows three ligature lookups in the LookupList table.

LookupList table

Type

Name

Description

uint16

LookupCount

Number of lookups in this table

Offset

ð Lookup[LookupCount]

Array of offsets to Lookup tables

—from beginning of LookupList

—zero based (first lookup is Lookup index = 0)


Lookup Table

A Lookup table (Lookup) defines the specific conditions, type, and results of a substitution or positioning action that is used to implement a feature. For example, a substitution operation requires a list of target glyph indices to be replaced, a list of replacement glyph indices, and a description of the type of substitution action.

Each Lookup table may contain only one type of information (LookupType), determined by whether the lookup is part of a GSUB or GPOS table. GSUB supports five LookupTypes, and GPOS supports seven LookupTypes (for details about LookupTypes, see the GSUB and GPOS chapters of the document).

Each LookupType is defined with one or more subtables, and each subtable definition provides a different representation format. The format is determined by the content of the information required for an operation and by required storage efficiency. When glyph information is best presented in more than one format, a single lookup may contain more than one subtable, as long as all the subtables are the same LookupType. For example, within a given lookup, a glyph index array format may best represent one set of target glyphs, whereas a glyph index range format may be better for another set of target glyphs.

During text processing, a client applies a lookup to each glyph in the string before moving to the next lookup. Once the client finds a target glyph index or context in a subtable and substitutes or positions the glyph, the lookup is completed for that glyph.

A Lookup table contains a LookupType, specified as an integer, that defines the type of information stored in the lookup. The LookupFlag specifies lookup qualifiers that assist a text-processing client in substituting or positioning glyphs. The SubTableCount specifies the total number of SubTables. The SubTable array specifies offsets, measured from the beginning of the Lookup table, to each SubTable enumerated in the SubTable array.

Lookup table

Type

Name

Description

uint16

LookupType

Different enumerations for GSUB and GPOS

uint16

LookupFlag

Lookup qualifiers

uint16

SubTableCount

Number of SubTables for this lookup

Offset

ð SubTable

Array of offsets to SubTables

[SubTableCount]

—from beginning of Lookup table


The LookupFlag uses four bits:

The first bit, RightToLeft, is set when the text is written from right to left. This bit defines the order in which lookups specify glyph sequences.

The next three bits—IgnoreBaseGlyphs, IgnoreLigatures, and IgnoreMarks—are set to specify additional instructions for applying a lookup to a glyph string.

LookupFlag bit enumeration

Mask

Name

Description

0x0001

RightToLeft

If set, implied glyph order is right to left

—otherwise, glyph order is left to right

0x0002

IgnoreBaseGlyphs

If set, skips over base glyphs

0x0004

IgnoreLigatures

If set, skips over ligatures

0x0008

IgnoreMarks

If set, skips over combining marks

0xFFF0

Reserved

For future use


For example, in Arabic text, a character string might have the pattern <base character - mark character - base character>. That string could be converted into a ligature composed of two components, one for each base character, with the combining mark glyph over the first component. To produce this ligature, the font developer would set the IgnoreMarks bit to tell the client to ignore the mark, substitute the ligature glyph first, and then position the mark glyph over the ligature. Alternatively, a lookup which did not set the IgnoreMarks bit could be used to describe a three-component ligature glyph, composed of the first base glyph, the mark glyph, and the second base glyph.