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

Part V · The pipeline

19. GPOS: positioning glyphs

When GPOS starts, the glyphs are settled. GSUB has chosen them, and the positions array has been cleared and filled with each glyph’s advance from the font (The pipeline, step by step). GPOS never changes which glyphs there are. It changes four numbers per glyph, the advance and the offset in each direction, and it records which glyph is attached to which, so that the attachments can be worked out once all its lookups have run.

GPOS has the same structure as GSUB, and HarfBuzz runs it with the same machinery, so this chapter covers only what is different: the nine lookup types as HarfBuzz runs them, then the last step, in which a tree of attachments becomes offsets an application can draw with. For how to write each type in a feature file, with Nastaliq cursive attachment and Thai mark-to-ligature among the examples, see “Types of Positioning Rule” in Simon Cozens’ Fonts and Layout for Global Scripts.

The examples come from one test font, gpos.ttf, built from fonts/gpos/gpos.fea, and three variants of it. It has the GSUB chapter’s f, i, and their ligatures, a few letters to kern, two combining marks, and letters that join in a cursive chain. Its glyphs are boxes. Every shaping result and trace on this page was produced by running HarfBuzz 15.2.0 on those fonts when the page was built.

What changes from GSUB

A GPOS table has a ScriptList, a FeatureList, a LookupList, and optional FeatureVariations, exactly as GSUB does (The shape of the table). Its lookups have nine types:

Type Name What it does
1 Single adjustment moves one glyph, or changes its advance
2 Pair adjustment the same for two glyphs in sequence: kerning
3 Cursive attachment joins a glyph’s exit point to the next glyph’s entry point
4 Mark-to-base attachment puts a mark’s anchor on a base glyph’s anchor
5 Mark-to-ligature attachment the same, on one component of a ligature
6 Mark-to-mark attachment puts a mark on the mark before it
7 Context runs other lookups where an input sequence matches
8 Chained context the same, also checking the glyphs before and after
9 Extension a wrapper allowing 32-bit offsets

Types 1 to 6 have beyond-64k formats too: SinglePos and PairPos formats 3 and 4, and format 2 of the others.

Each lookup runs through GSUB’s apply_forward loop, with its digests, mask test, and glyph-property test (Running one lookup). The second-glyph digest holds a pair subtable’s second glyphs and a mark subtable’s bases, so a mark lookup is skipped for a buffer with none of its bases. Planning puts all of GPOS in one stage: no script shaper pauses between GPOS lookups, so they all run in LookupList order (From features to lookups).

One array, in place

GSUB reads from the buffer and writes to a second array (An input buffer and an output buffer). GPOS never needs to, since it never adds or removes a glyph. The proxy through which HarfBuzz applies GPOS says so with one constant (hb-ot-layout.cc:1960):

struct GPOSProxy
{
  static constexpr unsigned table_index = 1u;
  static constexpr bool always_inplace = true;
  typedef OT::PosLookup Lookup;
  /* … (trimmed) */
};

With always_inplace, apply_string skips clear_output and sync, and next_glyph just moves idx on. Glyphs before idx and after it are in the same array, so a lookup that looks backwards, as cursive and mark attachment do, reads the glyphs directly. There are no reverse lookups: PosLookup::is_reverse always returns false.

What a lookup passes over

Lookup flags and GDEF classes work as in GSUB (Which glyphs a lookup sees). Default ignorables are treated differently. The matcher sets its rules from the table it is in (hb-ot-layout-gsubgpos.hh:902):

/* Ignore ZWNJ if we are matching GPOS, or matching GSUB context and asked to. */
ignore_zwnj = c->table_index == 1 || (context_match && c->auto_zwnj);
/* Ignore ZWJ if we are matching context, or asked to. */
ignore_zwj = context_match || c->auto_zwj;
/* Ignore hidden glyphs (like CGJ) during GPOS. */
ignore_hidden = c->table_index == 1;

So in GPOS, compared with the GSUB table:

ZWJ ZWNJ Hidden: CGJ, Mongolian FVS1–4, TAG characters Other default ignorables
input passed over, unless the feature has manual ZWJ passed over passed over passed over
context passed over passed over passed over passed over

A ZWNJ asks for no joining, a matter for GSUB, so it never stops kerning. Hidden characters have been passed over since 10.0.0 (Unicode inside HarfBuzz shows kerning across each). For the default shaper only mark and mkmk have manual ZWJ (hb-ot-shape.cc:298), so a ZWJ between a base and its mark keeps them apart. The per-syllable rule of the syllabic shapers applies only to GSUB.

Value records

Single and pair adjustments say what to change in a value record: up to eight fields, of which only those named in a ValueFormat are stored. Four are numbers in font units: xPlacement and yPlacement, which move the glyph without moving anything after it, and xAdvance and yAdvance, which change its advance. The other four are offsets to Device tables, one for each of those. To find a record’s length, HarfBuzz counts only the eight defined bits: the specification says every set bit takes two bytes, but a comment (ValueFormat.hh:61) cites Microsoft developers saying only the defined fields count.

Single adjustment, type 1, applies one value record to every glyph in its coverage (format 1) or one record per glyph (format 2). The test font’s first lookup moves a 40 units right and 100 up:

Lookup 0: Single adjustment (type 1)
  lookupFlag: none
  subtable 0: SinglePosFormat1
    coverage: [a]
    valueFormat: xPlacement yPlacement
    value: <xPlacement 40, yPlacement 100>
feature ss01 {
  pos a <40 100 0 0>;
} ss01;
<Lookup index="0">
  <LookupType value="1"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <SinglePos index="0" Format="1">
    <Coverage>
      <Glyph value="a"/>
    </Coverage>
    <ValueFormat value="3"/>
    <Value XPlacement="40" YPlacement="100"/>
  </SinglePos>
</Lookup>
gpos.ttf, lookup 0
FontTextOptionshb-shape output
gpos.ttfaU+0061[a=0+500]
gpos.ttfaU+0061--features=ss01[a=0@40,100+500]

apply_value (ValueFormat.hh:109) scales each number with em_scale_x or em_scale_y and adds it, saturating rather than overflowing. Placements apply in either direction of text. xAdvance applies only in horizontal text and yAdvance only in vertical, negated, because HarfBuzz’s vertical advances grow downwards (Vertical text).

Device tables

A Device table is read only if the font has a ppem set or variation coordinates that aren’t all zero (ValueFormat.hh:145). Two kinds share the offset. A hinting Device table, formats 1 to 3, gives a correction in pixels for a range of sizes, scaled into the font’s units (Fonts and font functions shows one). A VariationIndex table, format 0x8000, holds an index into GDEF’s item variation store (Deltas); its delta is scaled, then rounded.

var-kern.ttf is the shared variable font variations/var.ttf with one kerning pair added. Its value is −20 at the lightest weight, −60 at the default, −150 at the heaviest, and its spec-like view shows the VariationIndex behind it:

Lookup 0: Pair adjustment (type 2)
  lookupFlag: none
  subtable 0: PairPosFormat1
    coverage: [H]
    valueFormat[0]: xAdvance xAdvDevice
    valueFormat[1]: none
    pairSet:
      (H)
        V: <xAdvance -60, xAdvDevice VariationIndex 0:0>
<Lookup index="0">
  <LookupType value="2"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <PairPos index="0" Format="1">
    <Coverage>
      <Glyph value="H"/>
    </Coverage>
    <ValueFormat1 value="68"/>
    <ValueFormat2 value="0"/>
    <!-- PairSetCount=1 -->
    <PairSet index="0">
      <!-- PairValueCount=1 -->
      <PairValueRecord index="0">
        <SecondGlyph value="V"/>
        <Value1 XAdvance="-60">
          <XAdvDevice>
            <StartSize value="0"/>
            <EndSize value="0"/>
            <DeltaFormat value="32768"/>
          </XAdvDevice>
        </Value1>
      </PairValueRecord>
    </PairSet>
  </PairPos>
</Lookup>
var-kern.ttf, lookup 0
FontTextOptionshb-shape output
var-kern.ttfHVU+0048 U+0056--variations=wght=100 --features=-kern[H=0+560|V=1+200]
var-kern.ttfHVU+0048 U+0056--variations=wght=100[H=0+540|V=1+200]
var-kern.ttfHVU+0048 U+0056--variations=wght=650 --features=-kern[H=0+660|V=1+420]
var-kern.ttfHVU+0048 U+0056--variations=wght=650[H=0+555|V=1+420]
var-kern.ttfHVU+0048 U+0056--variations=wght=900 --features=-kern[H=0+700|V=1+560]
var-kern.ttfHVU+0048 U+0056--variations=wght=900[H=0+550|V=1+560]

Halfway between the default and the heaviest weight, the kern is halfway between −60 and −150: H’s 660 becomes 555. A value record’s Device offsets count from its nearest parent table: the subtable, or in glyph-pair kerning the PairSet.

The sanitizer doesn’t follow these offsets when GPOS is loaded. It checks them when they are first used, and treats a bad one as missing (Some of GPOS).

Pair adjustment

Pair adjustment is how fonts kern. A subtable covers the first glyph of a pair; HarfBuzz finds the second with the skipping iterator, so a lookup with IgnoreMarks kerns across marks. The test font’s kerning lookup has both formats:

Lookup 1: Pair adjustment (type 2)
  lookupFlag: none
  subtable 0: PairPosFormat1
    coverage: [A T V]
    valueFormat[0]: xAdvance
    valueFormat[1]: none
    pairSet:
      (A)
        V: <xAdvance -80>
      (T)
        o: <xAdvance -100>
      (V)
        e: <xAdvance 0>
  subtable 1: PairPosFormat2
    coverage: [T V]
    valueFormat1: xAdvance
    valueFormat2: none
    classDef1 (class 0: the rest of the coverage):
    classDef2 (class 0: every other glyph):
      1 = [a e o]
    values (1 × 2):
      0 × 0: <xAdvance 0>
      0 × 1: <xAdvance -60>
feature kern {
  pos A V -80;
  pos T o -100;
  pos V e 0;
  pos [T V] [a e o] -60;
} kern;
<Lookup index="1">
  <LookupType value="2"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=2 -->
  <PairPos index="0" Format="1">
    <Coverage>
      <Glyph value="A"/>
      <Glyph value="T"/>
      <Glyph value="V"/>
    </Coverage>
    <ValueFormat1 value="4"/>
    <ValueFormat2 value="0"/>
    <!-- PairSetCount=3 -->
    <PairSet index="0">
      <!-- PairValueCount=1 -->
      <PairValueRecord index="0">
        <SecondGlyph value="V"/>
        <Value1 XAdvance="-80"/>
      </PairValueRecord>
    </PairSet>
    <PairSet index="1">
      <!-- PairValueCount=1 -->
      <PairValueRecord index="0">
        <SecondGlyph value="o"/>
        <Value1 XAdvance="-100"/>
      </PairValueRecord>
    </PairSet>
    <PairSet index="2">
      <!-- PairValueCount=1 -->
      <PairValueRecord index="0">
        <SecondGlyph value="e"/>
        <Value1 XAdvance="0"/>
      </PairValueRecord>
    </PairSet>
  </PairPos>
  <PairPos index="1" Format="2">
    <Coverage>
      <Glyph value="T"/>
      <Glyph value="V"/>
    </Coverage>
    <ValueFormat1 value="4"/>
    <ValueFormat2 value="0"/>
    <ClassDef1>
    </ClassDef1>
    <ClassDef2>
      <ClassDef glyph="a" class="1"/>
      <ClassDef glyph="e" class="1"/>
      <ClassDef glyph="o" class="1"/>
    </ClassDef2>
    <!-- Class1Count=1 -->
    <!-- Class2Count=2 -->
    <Class1Record index="0">
      <Class2Record index="0">
        <Value1 XAdvance="0"/>
      </Class2Record>
      <Class2Record index="1">
        <Value1 XAdvance="-60"/>
      </Class2Record>
    </Class1Record>
  </PairPos>
</Lookup>
template <typename Types>
struct PairPosFormat1_3
{
  using PairSet = GPOS_impl::PairSet<Types>;
  using PairValueRecord = GPOS_impl::PairValueRecord<Types>;

  protected:
  HBUINT16      format;                 /* Format identifier--format = 1 */
  typename Types::template LOffsetTo<Coverage>
                coverage;               /* Offset to Coverage table--from
                                         * beginning of subtable */
  ValueFormat   valueFormat[2];         /* [0] Defines the types of data in
                                         * ValueRecord1--for the first glyph
                                         * in the pair--may be zero (0) */
                                        /* [1] Defines the types of data in
                                         * ValueRecord2--for the second glyph
                                         * in the pair--may be zero (0) */
  typename Types::template ArrayOf<typename Types::template OffsetTo<PairSet>>
                pairSet;                /* Array of PairSet tables ordered by
                                         * Coverage Index */
  public:
  DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + 2 * ValueFormat::static_size + Types::HBUINT::static_size, pairSet);
  /* … */
};
src/OT/Layout/GPOS/PairPosFormat1.hh:11
gpos.ttf, lookup 1

Format 1 lists pairs of glyphs. The first glyph’s coverage index chooses a PairSet, a list of second glyphs, each with a value record for the first glyph and one for the second, searched by binary search (PairSet.hh:173). Format 2 kerns classes: two class definitions, and a matrix with a pair of value records for each pair of classes. Class 0 is every glyph not given a class.

Glyph pairs first, then classes

The formats differ in when they decline. Format 1 declines when the second glyph isn’t in the pair set, and the next subtable gets a chance. Format 2 has a value for every pair of classes, zero or not, so once its coverage has the first glyph and a second is found, it applies, and no later subtable is tried. That is how kerning exceptions work: pos V e 0 is a glyph pair, found first, whose zero stops the class pair [T V] [a e o] from applying. feaLib always puts the glyph pairs first. class-first.ttf is the same font with the two subtables swapped:

FontTextOptionshb-shape output
gpos.ttfToU+0054 U+006F[T=0+500|o=1+500]
class-first.ttfToU+0054 U+006F[T=0+540|o=1+500]
gpos.ttfVeU+0056 U+0065[V=0+600|e=1+500]
class-first.ttfVeU+0056 U+0065[V=0+540|e=1+500]

In class-first.ttf, the class subtable claims every pair that starts with T or V, so T o gets the class value, −60, instead of its own −100, and V e is kerned though the font says it shouldn’t be.

For type designers: in a lookup, a class-pair subtable ends the search for every glyph in its coverage, whatever the second glyph is. Exceptions have to come before it.

The second glyph

If a pair has a value record for the second glyph, its ValueFormat is nonzero, and HarfBuzz moves on past the second glyph after applying the pair (PairSet.hh:210). The second glyph has been positioned already, so it can’t start a pair of its own. If the second ValueFormat is zero, the next pair starts at the second glyph. That depends on the format, not on the values. second-value.ttf is gpos.ttf with its glyph-pair subtable given a second value record, xAdvance 0, for every pair:

FontTextOptionshb-shape output
gpos.ttfAVaU+0041 U+0056 U+0061[A=0+520|V=1+540|a=2+500]
second-value.ttfAVaU+0041 U+0056 U+0061[A=0+520|V=1+600|a=2+500]

In gpos.ttf, A V is kerned by −80 and then V a by −60. In second-value.ttf the pair A V takes the V with it, so V a is never tried.

Safe to break

A pair whose values changed something is unsafe to break. A pair whose values are all zero is only unsafe to concatenate (PairSet.hh:207: “Even a zero-valued pair record is a concat hazard”). When the second glyph had a value record, the glyph after it is marked unsafe to break too (HarfBuzz issues #3824 and #3888):

FontTextOptionshb-shape output
gpos.ttfToU+0054 U+006F--show-flags --unsafe-to-concat[T=0+500|o=1+500#3]
gpos.ttfVeU+0056 U+0065--show-flags --unsafe-to-concat[V=0+600#2|e=1+500#2]
second-value.ttfAVaaU+0041 U+0056 U+0061 U+0061--show-flags[A=0+520|V=1+600#1|a=2+500#1|a=3+500]

#1 is unsafe to break, #2 unsafe to concatenate (Buffers). HarfBuzz 4.0.0 split a simple kern between the two glyphs of a pair, “for improved cursor positioning”, its NEWS says. The code is still in PairPosFormat2.hh:288, behind HB_SPLIT_KERN, and off: “Disabled, because causes issues… :-(” (HarfBuzz issue #3408).

Pair adjustment is also cached. Each of a lookup’s first eight subtables gets a small cache of coverage lookups (hb-ot-layout-gsubgpos.hh:1669), and either a digest of each pair set’s second glyphs, which rejects most absent pairs without a search, or caches of the two class definitions. HB_NO_OT_LAYOUT_LOOKUP_CACHE leaves them out.

Anchors

The other four positioning types work with anchors: points on a glyph, in font units, where something attaches. There are three formats:

Anchors are scaled to floats, and kept as floats until two of them are subtracted: the difference is rounded, not each anchor (hb-ot-layout-common.hh:6486). An anchor offset that is null, in a cursive record or in a mark lookup’s matrix, means there is no anchor, and the subtable declines, so the next subtable gets a chance at the glyph (MarkArray.hh:144).

Cursive attachment

A cursive lookup gives each glyph it covers an entry anchor and an exit anchor, and joins each glyph’s exit to the entry of the glyph after it. In the test font, n enters at (50, 0) and exits 100 units higher, at (450, 100), so a run of them climbs:

Lookup 2: Cursive attachment (type 3)
  lookupFlag: none
  subtable 0: CursivePosFormat1
    coverage: [n beh]
    entryExitRecord:
      n: entry (50, 0), exit (450, 100)
      beh: entry (450, 0), exit (50, 100)
feature curs {
  pos cursive n <anchor 50 0> <anchor 450 100>;
  pos cursive beh <anchor 450 0> <anchor 50 100>;
} curs;
<Lookup index="2">
  <LookupType value="3"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <CursivePos index="0" Format="1">
    <Coverage>
      <Glyph value="n"/>
      <Glyph value="beh"/>
    </Coverage>
    <!-- EntryExitCount=2 -->
    <EntryExitRecord index="0">
      <EntryAnchor Format="1">
        <XCoordinate value="50"/>
        <YCoordinate value="0"/>
      </EntryAnchor>
      <ExitAnchor Format="1">
        <XCoordinate value="450"/>
        <YCoordinate value="100"/>
      </ExitAnchor>
    </EntryExitRecord>
    <EntryExitRecord index="1">
      <EntryAnchor Format="1">
        <XCoordinate value="450"/>
        <YCoordinate value="0"/>
      </EntryAnchor>
      <ExitAnchor Format="1">
        <XCoordinate value="50"/>
        <YCoordinate value="100"/>
      </ExitAnchor>
    </EntryExitRecord>
  </CursivePos>
</Lookup>
template <typename Types>
struct CursivePosFormat1_2
{

  protected:
  HBUINT16      format;                 /* Format identifier--format = 1 */
  typename Types::template LOffsetTo<Coverage>
                coverage;               /* Offset to Coverage table--from beginning of subtable */
  typename Types::template ArrayOf<EntryExitRecord<Types>>
                entryExitRecord;        /* Array of EntryExit records--in
                                         * Coverage Index order */
  public:
  DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, entryExitRecord);
  /* … */
};
src/OT/Layout/GPOS/CursivePosFormat1.hh:227
gpos.ttf, lookup 2
FontTextOptionshb-shape output
gpos.ttfnnnnU+006E U+006E U+006E U+006E[n=0+450|n=1@-50,100+400|n=2@-50,200+400|n=3@-50,300+450]

CursivePosFormat1::apply (CursivePosFormat1.hh:275) takes the current glyph’s entry anchor and looks back, with the skipping iterator, for the previous glyph’s exit, which must be in the same subtable. apply_cursive_attachment then works along the line and across it.

Along the line, it changes advances so the two anchors meet. In left-to-right text, the first glyph’s advance becomes its exit’s x, 450, and the second glyph is moved back by its entry’s x, 50, its advance shortened to match. Each n in the middle gets both: moved back 50, with an advance of 450 − 50. Right-to-left text mirrors this, and vertical text does it with y.

Across the line, one glyph has to move so that its anchor is level with the other’s. Which one moves is set by the lookup’s RightToLeft flag, the only lookup flag that isn’t about skipping glyphs. HarfBuzz thinks of the moved glyph as a child attached to a parent (CursivePosFormat1.hh:164):

unsigned int child  = i;
unsigned int parent = j;
hb_position_t x_offset = (hb_position_t) roundf (entry_x - exit_x);
hb_position_t y_offset = (hb_position_t) roundf (entry_y - exit_y);
if  (!(c->lookup_props & LookupFlag::RightToLeft))
{
  unsigned int k = child;
  child = parent;
  parent = k;
  x_offset = -x_offset;
  y_offset = -y_offset;
}

i is the earlier glyph, in logical order. Without the flag the later glyph is the child, so a chain’s first glyph stays on the baseline and each later one hangs from the one before. With it, the last glyph stays on the baseline, as a Nastaliq font wants: an Urdu word ends on the baseline and climbs toward its start. Lookup 3 is lookup 2 with the flag set:

FontTextOptionshb-shape output
gpos.ttfبببU+0628 U+0628 U+0628--language=ar[beh=2@0,200+450|beh=1@-50,100+400|beh=0@-50,0+450]
gpos.ttfبببU+0628 U+0628 U+0628--language=ar --features=-curs,ss03[beh=2+450|beh=1@-50,-100+400|beh=0@-50,-200+450]
gpos.ttfnnnnU+006E U+006E U+006E U+006E--features=-curs,ss03[n=0@0,-300+450|n=1@-50,-200+400|n=2@-50,-100+400|n=3@-50,0+450]

Read the Arabic from the right. Without the flag the first beh, beh=0 on the right, is on the baseline. With it the last, on the left, is.

The child stores the offset across the line, and a link to its parent in two fields that GPOS keeps in the spare var of each position, set to zero by position_start before GPOS starts (OT/Layout/GPOS/Common.hh:17):

The offset is relative to the parent; chains are added up at the end of GPOS. When a child that already has a parent gets a new one, from a second cursive lookup, reverse_cursive_minor_offset reverses every link of its old chain, so its whole old tree hangs from the new parent. If the new parent was its child, that link is cut (HarfBuzz issue #2469). The join is unsafe to break. Marks may be attached cursively too, since 1.2.0.

Mark to base

A mark-to-base subtable has two coverages, for marks and for bases. Each mark has a class and an anchor, and each base has one anchor for each class:

Lookup 4: Mark-to-base attachment (type 4)
  lookupFlag: none
  subtable 0: MarkBasePosFormat1
    markCoverage: [acutecomb gravecomb]
    baseCoverage: [A T V a e f i n o]
    classCount: 1
    markArray:
      acutecomb: class 0, anchor (0, 0)
      gravecomb: class 0, anchor (0, 0)
    baseArray:
      A: [(250, 700)]
      T: [(250, 700)]
      V: [(250, 700)]
      a: [(250, 500)]
      e: [(250, 500)]
      f: [(250, 700)]
      i: [(250, 700)]
      n: [(250, 500)]
      o: [(250, 500)]
feature mark {
  pos base [a e o n] <anchor 250 500> mark @TOP;
  pos base [f i A T V] <anchor 250 700> mark @TOP;
  pos ligature f_i <anchor 225 700> mark @TOP
    ligComponent <anchor 675 700> mark @TOP;
  pos ligature f_f_i <anchor 150 700> mark @TOP
    ligComponent <anchor 450 700> mark @TOP
    ligComponent <anchor 750 700> mark @TOP;
} mark;
<Lookup index="4">
  <LookupType value="4"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <MarkBasePos index="0" Format="1">
    <MarkCoverage>
      <Glyph value="acutecomb"/>
      <Glyph value="gravecomb"/>
    </MarkCoverage>
    <BaseCoverage>
      <Glyph value="A"/>
      <Glyph value="T"/>
      <Glyph value="V"/>
      <Glyph value="a"/>
      <Glyph value="e"/>
      <Glyph value="f"/>
      <Glyph value="i"/>
      <Glyph value="n"/>
      <Glyph value="o"/>
    </BaseCoverage>
    <!-- ClassCount=1 -->
    <MarkArray>
      <!-- MarkCount=2 -->
      <MarkRecord index="0">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
      <MarkRecord index="1">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
    </MarkArray>
    <BaseArray>
      <!-- BaseCount=9 -->
      <BaseRecord index="0">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="700"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="1">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="700"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="2">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="700"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="3">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="500"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="4">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="500"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="5">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="700"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="6">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="700"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="7">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="500"/>
        </BaseAnchor>
      </BaseRecord>
      <BaseRecord index="8">
        <BaseAnchor index="0" Format="1">
          <XCoordinate value="250"/>
          <YCoordinate value="500"/>
        </BaseAnchor>
      </BaseRecord>
    </BaseArray>
  </MarkBasePos>
</Lookup>
template <typename Types>
struct MarkBasePosFormat1_2
{
  protected:
  HBUINT16      format;                 /* Format identifier--format = 1 */
  typename Types::template LOffsetTo<Coverage>
                markCoverage;           /* Offset to MarkCoverage table--from
                                         * beginning of MarkBasePos subtable */
  typename Types::template LOffsetTo<Coverage>
                baseCoverage;           /* Offset to BaseCoverage table--from
                                         * beginning of MarkBasePos subtable */
  HBUINT16      classCount;             /* Number of classes defined for marks */
  typename Types::template LOffsetTo<MarkArray<Types>>
                markArray;              /* Offset to MarkArray table--from
                                         * beginning of MarkBasePos subtable */
  typename Types::template LOffsetTo<AnchorMatrix<Types>>
                baseArray;              /* Offset to BaseArray table--from
                                         * beginning of MarkBasePos subtable */

  public:
  DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
  /* … */
};
src/OT/Layout/GPOS/MarkBasePosFormat1.hh:10
gpos.ttf, lookup 4
FontTextOptionshb-shape output
gpos.ttfa◌́U+0061 U+0301[a=0+500|acutecomb=0@-250,500+0]

Finding the base

When the current glyph is in the mark coverage, HarfBuzz looks back for the nearest glyph that isn’t a mark, using the skipping iterator’s matcher with its lookup props replaced by IgnoreMarks alone: the lookup’s own flags don’t say what counts as a base. Instead of the iterator’s prev, which the comment says would be O(n²), it has a loop of its own (MarkBasePosFormat1.hh:113), which remembers what it found in two fields of the apply context, last_base and last_base_until. Each mark in a run after one base then searches only the glyphs not yet searched. The cache is reset for each lookup.

The glyph found needn’t be a GDEF base (that check “is too strong; disabled”), only in the base coverage. One kind of non-mark is passed over: the second or later glyph of a multiple substitution, so that a mark after x decomposed into f i would attach to the f (HarfBuzz issue #740). The rule, accept (:75), stops at a mark inside the sequence (#1020), and since #4124 doesn’t pass over a glyph that is itself in the base coverage.

The loop stops at the first glyph it doesn’t skip, as prev would. If that glyph doesn’t match, because its mask lacks the lookup’s bit, there is no base, and the mark isn’t attached (MarkBasePosFormat1.hh:123). With mark turned off for the e alone, the acute after it stays where it is:

FontTextOptionshb-shape output
gpos.ttfae◌́U+0061 U+0065 U+0301--cluster-level=1[a=0+500|e=1+500|acutecomb=2@-250,500+0]
gpos.ttfae◌́U+0061 U+0065 U+0301--cluster-level=1 --features=mark[1:2]=0[a=0+500|e=1+500|acutecomb=2+0]

(Cluster level 1 keeps the acute in a cluster of its own, so the range covers only the e.) The acute has no offset: it isn’t attached to the e, whose mark is off, nor to the a behind it. From 7.0.0 until 15.2.0 the loop passed over such a glyph like a mark, and attached the acute to the a, 750 units back (HHW-12, fixed by #6736).

Attaching

Once the base is found and in the coverage, the base’s anchor for the mark’s class is fetched, and apply_mark_attachment (MarkArray.hh:41) sets the mark’s offset to the base anchor minus the mark anchor. It sets it: whatever offset the mark had from earlier lookups is replaced. The mark then points to its base with attach_chain and ATTACH_TYPE_MARK. Here the base anchor of a is (250, 500) and the acute’s anchor (0, 0), so its offset is (250, 500) for now, and becomes (−250, 500) once the base’s advance is taken off, at the end.

The two directions are treated differently. Across the line, the base’s offset is added now, including all the offsets up its cursive chain (resolve_cross_offset, MarkArray.hh:12). Along the line, the base’s offset is added only at the end. So a mark follows a base that a later lookup moves along the line, but not one it moves across:

FontTextOptionshb-shape output
gpos.ttfa◌́U+0061 U+0301--features=ss01[a=0@40,100+500|acutecomb=0@-210,600+0]
gpos.ttfa◌́U+0061 U+0301--features=ss02[a=0@40,100+500|acutecomb=0@-210,500+0]
gpos.ttfnn◌́U+006E U+006E U+0301[n=0+450|n=1@-50,100+450|acutecomb=1@-250,600+0]

ss01 (lookup 0) and ss02 (lookup 7) both move a by (40, 100). After ss01, which runs before the marks, the acute follows both; after ss02, only the 40. The acute on the second n follows it up the cursive chain, which was made first. This is from 14.3.0, for compatibility with DirectWrite and Core Text, whose NEWS says “marks no longer follow a cross-direction shift that a later lookup applies to the base”.

The attachment makes the base and mark unsafe to break apart. Joiners behave as the table near the start of this chapter says:

FontTextOptionshb-shape output
gpos.ttfa⟨ZWJ⟩◌́U+0061 U+200D U+0301[a=0+500|space=0+0|acutecomb=0+0]
gpos.ttfa⟨ZWNJ⟩◌́U+0061 U+200C U+0301[a=0+500|space=1+0|acutecomb=1@-250,500+0]
gpos.ttfa◌͏◌́U+0061 U+034F U+0301[a=0+500|space=0+0|acutecomb=0@-250,500+0]

The ZWJ stops the attachment: with manual ZWJ it isn’t passed over, so it is the glyph the base search finds, and it isn’t in the base coverage. The ZWNJ and the combining grapheme joiner are passed over.

Mark to ligature

A mark-to-ligature subtable is the same, except that each ligature has a row of anchors for each of its components. Which row a mark uses comes from GSUB. When ligate_input made the ligature, it gave the ligature a ligature ID, and gave each mark it passed over the same ID and the number of the component it followed (Matching, and the marks in between). The choice is in MarkLigPosFormat1.hh:166:

if (lig_id && lig_id == mark_id && mark_comp > 0)
  comp_index = hb_min (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1;
else
  comp_index = comp_count - 1;

A mark with the ligature’s ID goes on its own component. Any other mark, such as one typed after the whole ligature, goes on the last. The GSUB chapter could show this only with HarfBuzz’s fallback positioning, which divides a ligature into equal parts. gpos.ttf has the same ligatures, with anchors:

Lookup 5: Mark-to-ligature attachment (type 5)
  lookupFlag: none
  subtable 0: MarkLigPosFormat1
    markCoverage: [acutecomb gravecomb]
    ligatureCoverage: [f_i f_f_i]
    classCount: 1
    markArray:
      acutecomb: class 0, anchor (0, 0)
      gravecomb: class 0, anchor (0, 0)
    ligatureArray:
      f_i:
        component 1: [(225, 700)]
        component 2: [(675, 700)]
      f_f_i:
        component 1: [(150, 700)]
        component 2: [(450, 700)]
        component 3: [(750, 700)]
feature mark {
  pos base [a e o n] <anchor 250 500> mark @TOP;
  pos base [f i A T V] <anchor 250 700> mark @TOP;
  pos ligature f_i <anchor 225 700> mark @TOP
    ligComponent <anchor 675 700> mark @TOP;
  pos ligature f_f_i <anchor 150 700> mark @TOP
    ligComponent <anchor 450 700> mark @TOP
    ligComponent <anchor 750 700> mark @TOP;
} mark;
<Lookup index="5">
  <LookupType value="5"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <MarkLigPos index="0" Format="1">
    <MarkCoverage>
      <Glyph value="acutecomb"/>
      <Glyph value="gravecomb"/>
    </MarkCoverage>
    <LigatureCoverage>
      <Glyph value="f_i"/>
      <Glyph value="f_f_i"/>
    </LigatureCoverage>
    <!-- ClassCount=1 -->
    <MarkArray>
      <!-- MarkCount=2 -->
      <MarkRecord index="0">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
      <MarkRecord index="1">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
    </MarkArray>
    <LigatureArray>
      <!-- LigatureCount=2 -->
      <LigatureAttach index="0">
        <!-- ComponentCount=2 -->
        <ComponentRecord index="0">
          <LigatureAnchor index="0" Format="1">
            <XCoordinate value="225"/>
            <YCoordinate value="700"/>
          </LigatureAnchor>
        </ComponentRecord>
        <ComponentRecord index="1">
          <LigatureAnchor index="0" Format="1">
            <XCoordinate value="675"/>
            <YCoordinate value="700"/>
          </LigatureAnchor>
        </ComponentRecord>
      </LigatureAttach>
      <LigatureAttach index="1">
        <!-- ComponentCount=3 -->
        <ComponentRecord index="0">
          <LigatureAnchor index="0" Format="1">
            <XCoordinate value="150"/>
            <YCoordinate value="700"/>
          </LigatureAnchor>
        </ComponentRecord>
        <ComponentRecord index="1">
          <LigatureAnchor index="0" Format="1">
            <XCoordinate value="450"/>
            <YCoordinate value="700"/>
          </LigatureAnchor>
        </ComponentRecord>
        <ComponentRecord index="2">
          <LigatureAnchor index="0" Format="1">
            <XCoordinate value="750"/>
            <YCoordinate value="700"/>
          </LigatureAnchor>
        </ComponentRecord>
      </LigatureAttach>
    </LigatureArray>
  </MarkLigPos>
</Lookup>
template <typename Types>
struct MarkLigPosFormat1_2
{
  protected:
  HBUINT16      format;                 /* Format identifier--format = 1 */
  typename Types::template LOffsetTo<Coverage>
                markCoverage;           /* Offset to Mark Coverage table--from
                                         * beginning of MarkLigPos subtable */
  typename Types::template LOffsetTo<Coverage>
                ligatureCoverage;       /* Offset to Ligature Coverage
                                         * table--from beginning of MarkLigPos
                                         * subtable */
  HBUINT16      classCount;             /* Number of defined mark classes */
  typename Types::template LOffsetTo<MarkArray<Types>>
                markArray;              /* Offset to MarkArray table--from
                                         * beginning of MarkLigPos subtable */
  typename Types::template LOffsetTo<LigatureArray<Types>>
                ligatureArray;          /* Offset to LigatureArray table--from
                                         * beginning of MarkLigPos subtable */
  public:
  DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
  /* … */
};
src/OT/Layout/GPOS/MarkLigPosFormat1.hh:11
gpos.ttf, lookup 5
FontTextOptionshb-shape output
gpos.ttff◌́iU+0066 U+0301 U+0069[f_i=0+900|acutecomb=0@-675,700+0]
gpos.ttffi◌́U+0066 U+0069 U+0301[f_i=0+900|acutecomb=0@-225,700+0]
gpos.ttff◌́f◌́iU+0066 U+0301 U+0066 U+0301 U+0069[f_f_i=0+900|acutecomb=0@-750,700+0|acutecomb=0@-450,700+0]

The anchors are where the fallback positioner puts marks, a quarter and three quarters along f_i, so the acutes land where the GSUB chapter’s did, −675 and −225; but now they come from the font, and on f_f_i they are at 150 and 450, not at thirds. A trace shows each mark’s offset from its component’s anchor, before anything is added up:

hb-shape gpos.ttf "f◌́i◌́" --trace
start lookup 5 feature 'mark'[f_i=0+900|acutecomb=0+0|acutecomb=0+0]
attaching mark glyph at 1 to glyph at 0[f_i=0+900|acutecomb=0+0|acutecomb=0+0]
attached mark glyph at 1 to glyph at 0[f_i=0+900|acutecomb=0@225,700+0|acutecomb=0+0]
attaching mark glyph at 2 to glyph at 0[f_i=0+900|acutecomb=0@225,700+0|acutecomb=0+0]
attached mark glyph at 2 to glyph at 0[f_i=0+900|acutecomb=0@225,700+0|acutecomb=0@675,700+0]
end lookup 5 feature 'mark'[f_i=0+900|acutecomb=0@225,700+0|acutecomb=0@675,700+0]

If the chosen component has no anchor for the mark’s class, the subtable declines. The base search, the cache, and the multiple-substitution rule are the same as for mark-to-base.

Mark to mark

Mark-to-mark attaches a mark to a mark before it, usually to stack accents:

Lookup 6: Mark-to-mark attachment (type 6)
  lookupFlag: none
  subtable 0: MarkMarkPosFormat1
    mark1Coverage: [acutecomb gravecomb]
    mark2Coverage: [acutecomb gravecomb]
    classCount: 1
    mark1Array:
      acutecomb: class 0, anchor (0, 0)
      gravecomb: class 0, anchor (0, 0)
    mark2Array:
      acutecomb: [(0, 150)]
      gravecomb: [(0, 150)]
feature mkmk {
  pos mark @MARKS <anchor 0 150> mark @TOP;
} mkmk;
<Lookup index="6">
  <LookupType value="6"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <MarkMarkPos index="0" Format="1">
    <Mark1Coverage>
      <Glyph value="acutecomb"/>
      <Glyph value="gravecomb"/>
    </Mark1Coverage>
    <Mark2Coverage>
      <Glyph value="acutecomb"/>
      <Glyph value="gravecomb"/>
    </Mark2Coverage>
    <!-- ClassCount=1 -->
    <Mark1Array>
      <!-- MarkCount=2 -->
      <MarkRecord index="0">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
      <MarkRecord index="1">
        <Class value="0"/>
        <MarkAnchor Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="0"/>
        </MarkAnchor>
      </MarkRecord>
    </Mark1Array>
    <Mark2Array>
      <!-- Mark2Count=2 -->
      <Mark2Record index="0">
        <Mark2Anchor index="0" Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="150"/>
        </Mark2Anchor>
      </Mark2Record>
      <Mark2Record index="1">
        <Mark2Anchor index="0" Format="1">
          <XCoordinate value="0"/>
          <YCoordinate value="150"/>
        </Mark2Anchor>
      </Mark2Record>
    </Mark2Array>
  </MarkMarkPos>
</Lookup>
template <typename Types>
struct MarkMarkPosFormat1_2
{
  protected:
  HBUINT16      format;                 /* Format identifier--format = 1 */
  typename Types::template LOffsetTo<Coverage>
                mark1Coverage;          /* Offset to Combining Mark1 Coverage
                                         * table--from beginning of MarkMarkPos
                                         * subtable */
  typename Types::template LOffsetTo<Coverage>
                mark2Coverage;          /* Offset to Combining Mark2 Coverage
                                         * table--from beginning of MarkMarkPos
                                         * subtable */
  HBUINT16      classCount;             /* Number of defined mark classes */
  typename Types::template LOffsetTo<MarkArray<Types>>
                mark1Array;             /* Offset to Mark1Array table--from
                                         * beginning of MarkMarkPos subtable */
  typename Types::template LOffsetTo<AnchorMatrix<Types, HBUINT16>>
                mark2Array;             /* Offset to Mark2Array table--from
                                         * beginning of MarkMarkPos subtable */
  public:
  DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
  /* … */
};
src/OT/Layout/GPOS/MarkMarkPosFormat1.hh:10
gpos.ttf, lookup 6

This search uses the iterator’s prev, with the lookup’s flags minus the three Ignore flags (MarkMarkPosFormat1.hh:87), so a mark-filtering set or mark attachment class still decides which marks are passed over, and the glyph found must be a mark: a base ends the search. Then the two marks must belong together (:108): both with ligature ID 0, on the same base; or on the same component of one ligature; or, if their IDs differ, one must be a ligature of marks, with an ID and component number 0.

FontTextOptionshb-shape output
gpos.ttfa◌́◌́U+0061 U+0301 U+0301[a=0+500|acutecomb=0@-250,500+0|acutecomb=0@-250,650+0]
gpos.ttff◌́◌́iU+0066 U+0301 U+0301 U+0069[f_i=0+900|acutecomb=0@-675,700+0|acutecomb=0@-675,850+0]
gpos.ttff◌́i◌́U+0066 U+0301 U+0069 U+0301[f_i=0+900|acutecomb=0@-675,700+0|acutecomb=0@-225,700+0]

The first two stack the second acute on the first, 150 units up. In the third, the two acutes end up next to each other after f_i, the first belonging to component 1 and the second to component 2. They have the same ligature ID and different component numbers, so mkmk leaves them alone, and the acute typed over the i stays where mark-to-ligature put it.

Context, chained context, and extension

Types 7 to 9 are the same code as GSUB’s types 5 to 7 (Context and chained context). Nested positioning lookups never change the buffer’s length, so the guessing that apply_lookup does after a nested GSUB lookup never comes up.

Their commonest use is kerning that depends on a third glyph, a kerning triplet. A pair can only say how far apart two glyphs are; a triplet changes that when a particular glyph comes before or after them. The test font context.ttf, from context.fea, kerns T o by −100 as a pair, and gives 40 of it back when n follows:

feature kern {
  pos T o -100;
  pos T' 40 o n;
} kern;

As with substitutions (What a feature file compiles to), the second rule becomes two lookups: a chained-context lookup whose rule matches T before o n, and a single adjustment, lookup 2, that it calls:

feature kern {
  pos T o -100;
  pos T' 40 o n;
} kern;
<Lookup index="1">
  <LookupType value="8"/>
  <LookupFlag value="0"/>
  <!-- SubTableCount=1 -->
  <ChainContextPos index="0" Format="1">
    <Coverage>
      <Glyph value="T"/>
    </Coverage>
    <!-- ChainPosRuleSetCount=1 -->
    <ChainPosRuleSet index="0">
      <!-- ChainPosRuleCount=1 -->
      <ChainPosRule index="0">
        <!-- BacktrackGlyphCount=0 -->
        <!-- InputGlyphCount=1 -->
        <!-- LookAheadGlyphCount=2 -->
        <LookAhead index="0" value="o"/>
        <LookAhead index="1" value="n"/>
        <!-- PosCount=1 -->
        <PosLookupRecord index="0">
          <SequenceIndex value="0"/>
          <LookupListIndex value="2"/>
        </PosLookupRecord>
      </ChainPosRule>
    </ChainPosRuleSet>
  </ChainContextPos>
</Lookup>
context.ttf, lookup 1

Both lookups run, the pair first, and their values add up. T before o loses 100 units of advance, and before o n it loses 60:

FontTextOptionshb-shape output
context.ttfToU+0054 U+006F--language=en[T=0+500|o=1+500]
context.ttfTonU+0054 U+006F U+006E--language=en[T=0+540|o=1+500|n=2+500]
hb-shape context.ttf "Ton" --language=en --trace
start lookup 0 feature 'kern'[T=0+600|o=1+500|n=2+500]
try kerning glyphs at 0,1[T=0+600|o=1+500|n=2+500]
kerned glyphs at 0,1[T=0+500|o=1+500|n=2+500]
tried kerning glyphs at 0,1[T=0+500|o=1+500|n=2+500]
end lookup 0 feature 'kern'[T=0+500|o=1+500|n=2+500]
start lookup 1 feature 'kern'[T=0+500|o=1+500|n=2+500]
start recursing to lookup 2 at 0[T=0+500|o=1+500|n=2+500]
positioning glyph at 0[T=0+500|o=1+500|n=2+500]
positioned glyph at 0[T=0+540|o=1+500|n=2+500]
end recursing to lookup 2[T=0+540|o=1+500|n=2+500]
end lookup 1 feature 'kern'[T=0+540|o=1+500|n=2+500]

So a triplet is usually a correction on top of the pair, written as a later lookup. Written the other way round, before the pair, it would still add, because positioning values accumulate: unlike a substitution, an earlier adjustment doesn’t stop a later one from matching.

Resolving attachments

After GPOS, and after the shaper has zeroed the advances of marks (The pipeline, step by step), position_finish_offsets (OT/Layout/GPOS/GPOS.hh:173) turns relative offsets into offsets from each glyph’s own pen position, if an attachment set the buffer’s HAS_GPOS_ATTACHMENT scratch flag. For each glyph with an attach_chain, propagate_attachment_offsets (:73) resolves the parent first, recursively, and then:

Each link is cleared as it is resolved, so nothing is added twice. In the trace above the acutes left GPOS at x 225 and 675; taking off the ligature’s 900 gives −675 and −225. The code also handles a mark whose base comes after it, which kerx can produce (AAT positioning). Last comes synthetic slant (Fonts and font functions).

A limit on the depth

The recursion is bounded by HB_MAX_NESTING_LEVEL, 64, and the glyphs are visited in the buffer’s direction: from the start in left-to-right text, from the end in right-to-left (GPOS.hh:186). That order came from kerx, whose cross-stream kerning links every glyph to its neighbor and was losing a link every 64 glyphs (HarfBuzz issue #5514): visited in order, each parent is resolved before its child, and the recursion stays shallow.

A cursive chain can point the other way. In left-to-right text with the RightToLeft flag, every glyph’s parent comes after it, so resolving the first glyph recurses down the whole chain, and gives up at depth 64. In right-to-left text it is a chain without the flag, the usual kind in Arabic, that does this. Here are 67 ns with the flag set:

FontTextOptionshb-shape output
gpos.ttfnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnU+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E U+006E--features=-curs,ss03[n=0@0,-6500+450|n=1@-50,-6400+400|n=2@-50,-6300+400|n=3@-50,-6200+400|n=4@-50,-6100+400|n=5@-50,-6000+400|n=6@-50,-5900+400|n=7@-50,-5800+400|n=8@-50,-5700+400|n=9@-50,-5600+400|n=10@-50,-5500+400|n=11@-50,-5400+400|n=12@-50,-5300+400|n=13@-50,-5200+400|n=14@-50,-5100+400|n=15@-50,-5000+400|n=16@-50,-4900+400|n=17@-50,-4800+400|n=18@-50,-4700+400|n=19@-50,-4600+400|n=20@-50,-4500+400|n=21@-50,-4400+400|n=22@-50,-4300+400|n=23@-50,-4200+400|n=24@-50,-4100+400|n=25@-50,-4000+400|n=26@-50,-3900+400|n=27@-50,-3800+400|n=28@-50,-3700+400|n=29@-50,-3600+400|n=30@-50,-3500+400|n=31@-50,-3400+400|n=32@-50,-3300+400|n=33@-50,-3200+400|n=34@-50,-3100+400|n=35@-50,-3000+400|n=36@-50,-2900+400|n=37@-50,-2800+400|n=38@-50,-2700+400|n=39@-50,-2600+400|n=40@-50,-2500+400|n=41@-50,-2400+400|n=42@-50,-2300+400|n=43@-50,-2200+400|n=44@-50,-2100+400|n=45@-50,-2000+400|n=46@-50,-1900+400|n=47@-50,-1800+400|n=48@-50,-1700+400|n=49@-50,-1600+400|n=50@-50,-1500+400|n=51@-50,-1400+400|n=52@-50,-1300+400|n=53@-50,-1200+400|n=54@-50,-1100+400|n=55@-50,-1000+400|n=56@-50,-900+400|n=57@-50,-800+400|n=58@-50,-700+400|n=59@-50,-600+400|n=60@-50,-500+400|n=61@-50,-400+400|n=62@-50,-300+400|n=63@-50,-200+400|n=64@-50,-100+400|n=65@-50,-100+400|n=66@-50,0+450]

Each glyph should be 100 units below the next. Glyphs 64 and 65 are both at −100: the recursion stopped at glyph 64 before adding glyph 65’s offset, so glyphs 0 to 64 are all 100 units too high. Chains that long are rare. It looks like a bug of the same kind as #5514, left for chains that run against the buffer’s direction (HHW-13), but HarfBuzz keeps the limit on purpose: a pull request that resolved the links without recursion, #6753, was closed unmerged.

For programmers: a message callback that reads positions during GPOS sees attachments still relative to their parents, with the links in var, not the offsets the application will get.

Where to read the source

File What’s there
src/OT/Layout/GPOS/*.hh one file per subtable type and format, with its apply; value records, anchors, and MarkArray.hh (apply_mark_attachment, resolve_cross_offset)
src/OT/Layout/GPOS/CursivePosFormat1.hh apply_cursive_attachment, the RightToLeft flag, reverse_cursive_minor_offset
src/OT/Layout/GPOS/GPOS.hh position_start, position_finish_offsets, propagate_attachment_offsets
src/OT/Layout/GPOS/Common.hh attach_chain, attach_type
src/hb-ot-layout-gsubgpos.hh what GSUB and GPOS share: the matcher’s GPOS rules, the skipping iterator, the subtable caches, last_base
src/hb-ot-layout.cc GPOSProxy, apply_string, hb_ot_map_t::position
src/hb-ot-layout-common.hh Device, HintingDevice, VariationDevice
src/hb-ot-shape.cc where GPOS runs in the pipeline; the mark, mkmk, curs, and kern features

In short