How HarfBuzz Works From Unicode to positioned glyphs, and everything in between
HarfBuzz 15.2.0
Contents

Appendix B

Reading feature files

HarfBuzz never reads a feature file, but this book’s examples are written in them: the GSUB and GPOS chapters show feature-file source beside every compiled lookup, and most of the book’s test fonts get their layout tables, GSUB, GPOS, and their GDEF glyph classes, from feature files. This appendix is enough to read that source, and to know what a rule becomes in the font HarfBuzz sees. To make a test font of your own and see what HarfBuzz does with a rule, see Testing with a font of your own. It isn’t a guide to writing feature files, but its last section says where to find one.

The language

The feature file format is Adobe’s, defined for its font tools (AFDKO) in the OpenType Feature File Specification, now at document version 1.27. It is mainly for writing GSUB and GPOS rules. It can also give GDEF its glyph classes, and set values in BASE, head, hhea, name, OS/2, vhea, vmtx, and STAT (its section 9), several of which HarfBuzz reads (Where metrics come from, Other tables). Font editors take feature code in the same language.

A rule says what a lookup should do, such as sub f i by f_i;. A compiler turns the rules into lookups, groups them into features, and registers the features under language systems. HarfBuzz never reads a feature file. It sees only the tables a compiler made.

The compilers

The language leaves a compiler much to decide: how rules are split into lookups and subtables, which subtable formats to use, and how lookups are numbered. Two compilers need not make the same tables from the same file. What this book says about compiled lookups is what feaLib made, and What a feature file compiles to shows the cases that surprise.

The key

One row for each construct the book’s examples use. The middle column is what feaLib makes of it. It was checked by compiling one rule of each kind with feaLib and reading back the lookup types: it isn’t made when the book is built.

You write feaLib makes Explained in
languagesystem latn TRK; a language system, TRK under the script latn, that the features are registered under Choosing a script shaper
feature liga { … } liga; a feature record for liga, listing the lookups made from the rules inside From features to lookups
lookup NAME { … } NAME; a named lookup, used by any feature that refers to it with lookup NAME; From features to lookups
@VOWELS = [a e i]; and [a e i] nothing of its own: a glyph class is written out wherever it is used
sub a by a.alt1; Single substitution (GSUB type 1) GSUB
sub x by f i; Multiple substitution (GSUB type 2) GSUB
sub a from [a.alt1 a.alt2]; Alternate substitution (GSUB type 3) GSUB
sub f i by f_i; Ligature substitution (GSUB type 4) GSUB
sub a' e by a.alt3; Chained context (GSUB type 6), and an unnamed single substitution it calls GSUB
ignore sub f' i; a chained-context rule that calls no lookup GSUB
pos a 10; or pos a <40 100 0 0>; Single adjustment (GPOS type 1) GPOS
pos A V -80; Pair adjustment (GPOS type 2) GPOS
pos cursive x <anchor 0 0> <anchor 500 0>; Cursive attachment (GPOS type 3) GPOS
markClass acutecomb <anchor 250 500> @TOP; nothing of its own: the marks and their anchors, for the attachment rules that use the class GPOS
pos base a <anchor 250 500> mark @TOP; Mark to base (GPOS type 4) GPOS
pos ligature f_i <anchor …> mark @TOP ligComponent <anchor …> mark @TOP; Mark to ligature (GPOS type 5), one anchor per component GPOS
pos mark acutecomb <anchor 250 700> mark @TOP; Mark to mark (GPOS type 6) GPOS
pos T' 40 o n; Chained context (GPOS type 8), and an unnamed single adjustment it calls GPOS
lookupflag IgnoreMarks; the flags of the lookups made from the rules after it GSUB
script latn; language TRK exclude_dflt; which language systems the following rules’ lookups are registered under GSUB, Turkish i
language TRK required; the language system’s required feature From features to lookups
table GDEF { GlyphClassDef … ; } GDEF; GDEF’s glyph classes: bases, ligatures, marks, and components GSUB

Three things the key can’t show:

Writing feature files

Much of a font’s layout isn’t written by hand. Font editors and build tools make many features themselves: kern, mark, and mkmk from the kerning and the glyphs’ anchors, and often ccmp, locl, liga, or the joining features from glyph names. Some show what they made as feature code; others build the lookups without it. Either way, HarfBuzz sees only the result. For what you do write by hand:

In short