Appendix A
Feature order
“Does my calt run before my ccmp?” has no single answer. It depends on the script shaper, and on the order of the lookups in the font. This appendix gives the order for each of HarfBuzz’s shapers, as HarfBuzz 15.2.0 runs it. Each table is generated automatically by running HarfBuzz when the book is built, so it can’t drift from the code.
The rule
Planning sorts features into stages (From features to lookups):
- Stages run one after another, in a fixed order that the shaper sets.
- Within a stage, lookups run in LookupList order, whatever features they belong to (GSUB). The order in which the features are listed, requested, or written doesn’t count.
- GPOS always has one stage. All its lookups run in LookupList order, after all of GSUB.
So each table below lists stages, not features. Within one stage, the features are listed alphabetically, because their order there is the font’s, not HarfBuzz’s.
Between the stages, the tables show the other steps HarfBuzz’s trace reports, in italics, under the names the trace gives them:
| Step | What it is |
|---|---|
| preprocess-text | the shaper’s work on the characters before shaping, such as composing Hangul jamo (Hebrew, Thai, Lao, and Hangul) |
| decompose, reorder, compose | normalization’s three rounds (Normalization) |
| reordering … | a shaper moving glyphs between stages: the Indic, Khmer, Myanmar, and USE reorderings |
| postprocess-glyphs | the shaper’s work after GPOS, such as stretching for Arabic stch (Joining scripts) |
| fallback mark, fallback kern | HarfBuzz positioning marks or kerning itself, for a font without the GPOS features (Fallbacks) |
Only steps that the shaped text needs appear. A step that leaves no message in the trace isn’t shown either. Finding syllables, for example, leaves no message, but it ends a stage.
How the tables are made
fonts/feature-order/build-fonts.py builds a pair of fonts for each script. Each font has one lookup for every feature tag that any of HarfBuzz’s shapers asks for, 58 in all, plus smcp to stand for a feature an application asks for. Each lookup acts on a glyph that is never in the text, so it changes nothing. It is there to be seen: HarfBuzz’s trace reports every lookup in the plan, in the order it runs, whether or not it matches.
The two fonts differ only in how their lookups are numbered: alphabetically by feature tag in one, and in reverse in the other. Within a stage, LookupList order decides, so the two fonts give opposite orders. Across stages, the stage order decides, so they agree. A stage therefore ends exactly where the lookups run so far are the same set in both fonts. The order block in tools/build-site.mjs shapes both fonts and finds the stages that way.
A feature that is missing from a table wasn’t asked for. Under the Indic shaper, for example, liga is turned off, so it never runs, even though the fonts have it.
The default shaper
The default shaper handles Latin, Greek, Cyrillic, Han, and most other scripts, and Thai and Lao use its features too (From tags to a shaper). It adds no pauses, so after rvrn everything is one stage: the font’s lookup order decides everything else.
hb-shape order-latn-a.ttf "a" --features=smcp --trace, and the same with order-latn-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | BUZZ Buzz HARF Harf calt ccmp clig dnom frac liga locl ltra ltrm numr rand rclt rlig smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
In right-to-left text, as with the Hebrew shaper, rtla and rtlm take the place of ltra and ltrm:
hb-shape order-hebr-a.ttf "א" --features=smcp --trace, and the same with order-hebr-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | BUZZ Buzz HARF Harf calt ccmp clig dnom frac liga locl numr rand rclt rlig rtla rtlm smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
In vertical text, vert replaces the horizontal features calt, clig, curs, dist, kern, liga, and rclt:
hb-shape order-latn-a.ttf "a" --features=smcp --direction=ttb --trace, and the same with order-latn-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | BUZZ Buzz HARF Harf ccmp dnom frac locl numr rand rlig smcp vert |
| GPOS 1 | abvm blwm mark mkmk |
Arabic
The Arabic shaper is used for Arabic in horizontal text, and for Syriac in horizontal text if the font has a Syriac script tag. The other joining scripts, such as Mongolian and N’Ko, are shaped by USE (Joining scripts); Choosing a script shaper has the conditions. It puts a pause after each joining feature, and after rlig, so isol, fina, fin2, fin3, medi, med2, init, and rlig each run on their own, in that order (Joining scripts):
hb-shape order-arab-a.ttf "بب" --features=smcp --trace, and the same with order-arab-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | HARF Harf dnom frac numr rand rtla rtlm stch |
| GSUB 3 | ccmp locl |
| GSUB 4 | isol |
| GSUB 5 | fina |
| GSUB 6 | fin2 |
| GSUB 7 | fin3 |
| GSUB 8 | medi |
| GSUB 9 | med2 |
| GSUB 10 | init |
| GSUB 11 | rlig |
| GSUB 12 | BUZZ Buzz calt clig liga mset rclt smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
| postprocess-glyphs |
Indic
The nine Indic scripts, under their 2 tags or their old ones (The Indic model). Syllables are found before the shaper’s first feature, and the glyphs are reordered twice: after locl and ccmp, and after the basic features. Each basic feature has a stage of its own, so each sees what the one before made. The presentation features then share the last stage with the common ones and the application’s.
hb-shape order-dev2-a.ttf "कि" --features=smcp --trace, and the same with order-dev2-b.ttf| Stage | Features, or another step |
|---|---|
| preprocess-text | |
| decompose | |
| reorder | |
| compose | |
| GSUB 1 | rvrn |
| GSUB 2 | HARF Harf dnom frac ltra ltrm numr rand |
| GSUB 3 | ccmp locl |
| reordering indic initial | |
| GSUB 4 | nukt |
| GSUB 5 | akhn |
| GSUB 6 | rphf |
| GSUB 7 | rkrf |
| GSUB 8 | pref |
| GSUB 9 | blwf |
| GSUB 10 | abvf |
| GSUB 11 | half |
| GSUB 12 | pstf |
| GSUB 13 | vatu |
| GSUB 14 | cjct |
| reordering indic final | |
| GSUB 15 | BUZZ Buzz abvs blws calt clig haln init pres psts rclt rlig smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
Khmer
Khmer reorders first, before any of its own features. Then the basic features share one stage (Khmer and Myanmar):
hb-shape order-khmr-a.ttf "ក" --features=smcp --trace, and the same with order-khmr-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | HARF Harf dnom frac ltra ltrm numr rand |
| reordering khmer | |
| GSUB 3 | abvf blwf ccmp cfar locl pref pstf |
| GSUB 4 | BUZZ Buzz abvs blws calt clig pres psts rclt rlig smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
Myanmar
Under mym2, Myanmar reorders after locl and ccmp, and its basic features each have a stage of their own (Khmer and Myanmar):
hb-shape order-mym2-a.ttf "က" --features=smcp --trace, and the same with order-mym2-b.ttf| Stage | Features, or another step |
|---|---|
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | HARF Harf dnom frac ltra ltrm numr rand |
| GSUB 3 | ccmp locl |
| reordering myanmar | |
| GSUB 4 | rphf |
| GSUB 5 | pref |
| GSUB 6 | blwf |
| GSUB 7 | pstf |
| GSUB 8 | BUZZ Buzz abvs blws calt clig liga pres psts rclt rlig smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
The Universal Shaping Engine
USE covers the scripts in its list, and the nine Indic scripts under the unregistered 3 tags, such as dev3 (The Universal Shaping Engine). The order is the same for all of them. Balinese is the example here:
hb-shape order-bali-a.ttf "ᬓ" --features=smcp --trace, and the same with order-bali-b.ttf| Stage | Features, or another step |
|---|---|
| preprocess-text | |
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | HARF Harf dnom frac ltra ltrm numr rand |
| GSUB 3 | akhn ccmp locl nukt |
| GSUB 4 | rphf |
| GSUB 5 | pref |
| GSUB 6 | abvf blwf cjct half pstf rkrf vatu |
| reordering USE | |
| GSUB 7 | fina init isol medi |
| GSUB 8 | BUZZ Buzz abvs blws calt clig haln liga pres psts rclt rlig smcp |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
Only rphf and pref have stages of their own, because what each one did is recorded before the next. The specification leaves the order within each group to the font.
Hangul
The Hangul shaper composes or decomposes the jamo before shaping, and its ljmo, vjmo, and tjmo share the default shaper’s single stage (Hebrew, Thai, Lao, and Hangul):
hb-shape order-hang-a.ttf "한" --features=smcp --trace, and the same with order-hang-b.ttf| Stage | Features, or another step |
|---|---|
| preprocess-text | |
| decompose | |
| GSUB 1 | rvrn |
| GSUB 2 | BUZZ Buzz HARF Harf calt ccmp clig dnom frac liga ljmo locl ltra ltrm numr rand rclt rlig smcp tjmo vjmo |
| GPOS 1 | abvm blwm curs dist kern mark mkmk |
AAT fonts
A font with a morx table that HarfBuzz uses gets none of the GSUB stages: morx runs in GSUB’s place (When morx is used). Its order is the font’s own: chains run in the order they are stored, and the subtables in each chain likewise. Feature tags only turn subtables on and off (From feature tags to feature types).
What it means for a font
- Under the default shaper, the order of lookups in the LookupList is the order in which they run, apart from
rvrn. In a feature file, that is the order the lookups are written in. - Under the default shaper, no feature is “early” or “late” except
rvrn.caltruns late only if its lookups come late in the LookupList. Under the Arabic, Indic, Khmer, Myanmar, and USE shapers it really is late, in the last stage with the presentation features. - Under a shaper with stages, a lookup can’t see the output of a feature in a later stage, wherever it is in the LookupList. A
ccmplookup never sees whatinitmade, under the Arabic shaper or the Indic one. rvrnalways runs first, in a stage of its own.- An application’s features, such as
smcporss01, always run in the last stage, after all reordering, so they can’t change how a syllable is reordered. - GPOS runs after all of GSUB, so its lookups see only the final glyphs.
Where to read the source
| What | Where |
|---|---|
| The features every shaper asks for, and in what order | hb_ot_shape_collect_features, src/hb-ot-shape.cc:317 |
| Running the stages, and the trace’s lookup messages | hb_ot_map_t::apply, src/hb-ot-layout.cc:2094 |
| Each shaper’s features and pauses | collect_features_* in src/hb-ot-shaper-arabic.cc, -indic.cc, -khmer.cc, -myanmar.cc, -use.cc, -hangul.cc |
| The fonts | fonts/feature-order/build-fonts.py |
The order block |
blockOrder, tools/build-site.mjs |
In short
- Features run in stages: in order across stages, and in LookupList order within one.
- The default shaper has one stage after
rvrn, so the font decides the order. - The Arabic, Indic, Khmer, Myanmar, and USE shapers add stages, and reorder glyphs between them.
- An application’s features run last in GSUB, and GPOS runs after GSUB, in one stage.