Part VI · Scripts
24. Hebrew, Thai, Lao, and Hangul
Hebrew, Thai, Lao, and Korean need no syllable machine and no reordering of letters. A font’s own GSUB and GPOS can do nearly everything their text needs, and HarfBuzz’s shapers for them are small: three files, none of them 500 lines long, license included. Each exists for a job the font can’t do on its own, either because it has to be done to the characters before they become glyphs, or because it depends on what the font has.
| Shaper | Scripts | Hooks it fills | Its job |
|---|---|---|---|
| Hebrew | Hebrew | compose, reorder_marks, gpos_tag |
puts one sequence of points in a better order; makes presentation forms for old fonts |
| Thai | Thai, Lao | preprocess_text |
splits SARA AM; for old Thai fonts, swaps marks for the font’s private-use glyphs |
| Hangul | Hangul | collect_features, override_features, data_create, preprocess_text, setup_masks |
decides, from the font, whether a syllable is one glyph or several jamo |
How a script gets one of these shapers is in Choosing a script shaper, and where each hook runs is in The pipeline, step by step. The examples use test fonts in fonts/hebrew-thai-lao-and-hangul/, built by build-fonts.py there from three small feature files. Most glyphs are boxes, named after their characters. The Thai ones are drawn so that a mark’s different forms can be told apart. Every result on this page was produced by HarfBuzz 15.2.0 when the page was built.
Hebrew
One sequence of points
Normalization sorts each run of marks by HarfBuzz’s modified combining classes, which for Hebrew follow the order of the SBL Hebrew manual rather than Unicode’s (Unicode inside HarfBuzz). Then it gives the shaper’s reorder_marks hook the sorted run (Normalization). The Hebrew shaper’s is short (hb-ot-shaper-hebrew.cc:166, trimmed):
for (unsigned i = start + 2; i < end; i++)
{
unsigned c0 = info_cc (info[i - 2]);
unsigned c1 = info_cc (info[i - 1]);
unsigned c2 = info_cc (info[i - 0]);
if ((c0 == CCC17 || c0 == CCC18) /* patach or qamats */ &&
(c1 == CCC10 || c1 == CCC14) /* sheva or hiriq */ &&
(c2 == CCC22 || c2 == BELOW) /* meteg or below */)
{
buffer->merge_clusters (i - 1, i + 1);
hb_swap (info[i - 1], info[i]);
break;
}
}
In the sorted order, patah and qamats (modified classes 20 and 21) come just before sheva and hiriq (22 and 23), and those come before meteg (25) and the cantillation marks below, such as etnahta (220). Where all three are there in a row, the second and third swap, so the meteg or accent comes straight after the patah or qamats. It happens once in a run, at the first place it matches:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hebrew-mark.ttf | לִַֽU+05DC U+05B7 U+05B4 U+05BD | --language=he --no-positions | [hiriq=0| |
| hebrew-mark.ttf | לִַֽU+05DC U+05BD U+05B4 U+05B7 | --language=he --no-positions | [hiriq=0| |
| hebrew-mark.ttf | לְָ֑U+05DC U+05B8 U+05B0 U+0591 | --language=he --no-positions | [sheva=0| |
| hebrew-mark.ttf | לִֽU+05DC U+05B4 U+05BD | --language=he --no-positions | [meteg=0| |
| hebrew-mark.ttf | לִַ◌͏ֽU+05DC U+05B7 U+05B4 U+034F U+05BD | --language=he --no-positions | [meteg=0| |
The output is in visual order, so read it from the right: lamed, patah, meteg, hiriq, whichever order the points were typed in. A qamats, sheva, and etnahta swap the same way. Without a patah or qamats, hiriq and meteg keep their sorted order. A combining grapheme joiner between the hiriq and the meteg puts them in different runs, and nothing moves (the joiner is the space glyph: GSUB).
The source gives no reason beyond the names in its comment, and the swap’s history is no clearer: NEWS for 5.0.0 says only “Improve multiple mark interactions in Hebrew”. The pattern is the one in the traditional spelling of Jerusalem, יְרוּשָׁלִַם, whose lamed carries both a patah and a hiriq, and the swap keeps a meteg or accent next to the first of the two vowels (inferred).
Presentation forms for old fonts
Unicode’s Alphabetic Presentation Forms block has Hebrew presentation forms from U+FB1D to U+FB4F, most of them letters with their points, such as SHIN WITH SHIN DOT (U+FB2A) or VAV WITH HOLAM (U+FB4B). They have canonical decompositions, but they are excluded from composition, so normalization never makes one from its parts. Old fonts, with no GPOS to place the points, drew these forms instead and mapped them in their cmap.
The Hebrew shaper’s compose hook makes them anyway, for those fonts. When Unicode’s composition finds nothing, and the plan has no mark feature, it composes about three dozen pairs into presentation forms: a dagesh with each letter that has a dagesh form, shin and sin dots with SHIN, rafe with BET, KAF, and PE, and five more with particular vowels (hb-ot-shaper-hebrew.cc:81). Normalization’s last round calls the hook, and as with any composition, only uses the result if the font has a glyph for it (Normalization). A composed form can compose again, so SHIN, dagesh, and shin dot become U+FB2C in two steps.
hebrew-old.ttf has the letters, the points, and seven presentation forms, and no layout tables at all. hebrew-mark.ttf adds a GPOS with a mark feature under hebr, and hebrew-mark-DFLT.ttf has the same GPOS under DFLT:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hebrew-old.ttf | שׁU+05E9 U+05C1 | --language=he | [shin_shindot=0+700] |
| hebrew-old.ttf | שּׁU+05E9 U+05BC U+05C1 | --language=he | [shin_dagesh_shindot=0+700] |
| hebrew-old.ttf | וֹU+05D5 U+05B9 | --language=he | [vav_holam=0+300] |
| hebrew-old.ttf | חּU+05D7 U+05BC | --language=he | [dagesh=0@600,0+0| |
| hebrew-mark.ttf | שּׁU+05E9 U+05BC U+05C1 | --language=he | [dagesh=0@300,250+0| |
| hebrew-mark.ttf | שּׁU+05E9 U+05BC U+05C1 | --language=he --features=-mark | [shin_dagesh_shindot=0+700] |
| hebrew-mark-DFLT.ttf | שּׁU+05E9 U+05BC U+05C1 | --language=he | [shin_dagesh_shindot=0+700] |
The old font gets its single glyphs. HET has no dagesh form in Unicode, so its dagesh stays a mark, placed by HarfBuzz’s fallback positioner. With a mark feature, the letters and points stay apart for GPOS to place, unless the feature is turned off, which takes it out of the plan.
The last line gets the presentation form too. The Hebrew shaper’s gpos_tag says that GPOS is only used if the script it chose is hebr (Choosing a script shaper), so that font’s GPOS is ignored. The test for composing is whether GPOS is applied and has a mark feature (has_gpos_mark, hb-ot-shape.cc:192), and a mark feature in an ignored GPOS doesn’t count. Before 15.2.0 the test looked only for the feature, so planning found the DFLT one, and the font got neither its GPOS nor its presentation forms (HHW-21).
For type designers: a Hebrew font gets its GPOS only if GPOS has a
hebrscript, and gets presentation forms only if its GPOS isn’t used or has nomarkfeature. A font that has both kinds of data, and wants its GPOS to place the points, should put it underhebr.
HB_NO_OT_SHAPER_HEBREW_FALLBACK leaves the presentation forms out, and HB_NO_OT_SHAPE_FALLBACK implies it.
Thai and Lao
SARA AM
SARA AM, U+0E33 ำ, is a vowel written as a small circle over the consonant and a spacing SARA AA after it. Unicode gives it a compatibility decomposition to NIKHAHIT (U+0E4D) and SARA AA (U+0E32), but a compatibility decomposition is not one that normalization applies. When a tone mark goes on the same consonant, it is typed before SARA AM but drawn above the circle.
The Thai shaper splits every SARA AM, and moves the NIKHAHIT back over any above-base marks before it. A long comment in preprocess_text_thai says this isn’t in Microsoft’s Thai specification, but is what Uniscribe and other engines do, and gives Eric Muller’s example: <0E14, 0E4B, 0E33> becomes <0E14, 0E4D, 0E4B, 0E32>. The loop, trimmed (hb-ot-shaper-thai.cc:324):
if (!IS_SARA_AM (u)) { buffer->next_glyph (); continue; }
/* Is SARA AM. Decompose and reorder. */
buffer->output_glyph (NIKHAHIT_FROM_SARA_AM (u));
_hb_glyph_info_set_continuation (&buffer->prev(), buffer);
buffer->replace_glyph (SARA_AA_FROM_SARA_AM (u));
/* Make Nikhahit be recognized as a ccc=0 mark when zeroing widths. */
unsigned int end = buffer->out_len;
_hb_glyph_info_set_general_category (&buffer->out_info[end - 2],
HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK);
unsigned int start = end - 2;
while (start > 0 && IS_ABOVE_BASE_MARK (buffer->out_info[start - 1].codepoint))
start--;
/* ...move the NIKHAHIT from end - 2 to start, and merge clusters... */
The two new characters are copies of SARA AM, so the NIKHAHIT is given the general category of a non-spacing mark, which the copy lacked. Then it moves back over the run of above-base marks: MAI HAN-AKAT, the upper vowels SARA I to SARA UEE, and MAITAIKHU to YAMAKKAN, which includes the tone marks. The clusters from the first of those to the SARA AA are merged, and then merged with the consonant’s cluster too.
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| thai.ttf | กำU+0E01 U+0E33 | --language=th | [kokai=0+500| |
| thai.ttf | ด๋ำU+0E14 U+0E4B U+0E33 | --language=th | [dodek=0+500| |
| thai.ttf | ดิ๋ำU+0E14 U+0E34 U+0E4B U+0E33 | --language=th | [dodek=0+500| |
| thai.ttf | ด๋ําU+0E14 U+0E4B U+0E4D U+0E32 | --language=th | [dodek=0+500| |
In the second line the NIKHAHIT now comes before MAI CHATTAWA, so a font sees the order it sees for a consonant with an upper vowel and a tone mark, and can stack them the same way. In the third it goes back over SARA I as well. The fourth line types NIKHAHIT and SARA AA separately, after the tone mark. They aren’t moved: the comment says the reordering “is legit only when the NIKHAHIT comes from a SARA AM”. They aren’t merged into the consonant’s cluster either, as SARA AA’s cluster number, 3, shows.
The trace shows the change in the characters, before normalization or the cmap sees them:
hb-shape thai.ttf "ด๋ำ" --language=th --trace| start preprocess-text | <U+0E14=0|U+0E4B=0|U+0E33=2> |
| end preprocess-text | <U+0E14=0|U+0E4D=0|U+0E4B=0|U+0E32=0> |
This happens whether or not the font has Thai layout tables, and the font’s own glyph for SARA AM is never used. thai-am-only.ttf has one, and no glyphs for NIKHAHIT or SARA AA:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| thai-am-only.ttf | กำU+0E01 U+0E33 | --language=th | [kokai=0+500| |
For type designers: a Thai font needs glyphs for NIKHAHIT and SARA AA, and a Lao font for their Lao counterparts. A glyph for SARA AM is never reached in HarfBuzz.
Old fonts and the private use area
Before OpenType, Thai fonts for Windows and the Mac had no GPOS to move a mark out of the way of another, or of a consonant’s ascender or descender. They drew the moved forms as extra glyphs, mapped in the cmap to code points in Unicode’s private use area (PUA): a tone mark drawn lower, for when there’s no vowel above, or further left, to clear PO PLA’s ascender; YO YING without its descender, for when a vowel goes below it. Windows fonts put them at U+F700 to U+F71A, Mac fonts at U+F884 to U+F89E. The software chose the form.
HarfBuzz chooses them too, if the text is Thai and GSUB didn’t find the thai script, which includes fonts with no GSUB at all (hb-ot-shaper-thai.cc:368). The rules follow Theppitak Karoonboonyanan’s description of Thai shaping, which the source cites (linux.thai.net/~thep/th-otf/shaping.html). do_thai_pua_shaping walks the text with two small state machines, one for the space above the consonant and one for the space below, both reset at each character that isn’t a Thai mark. A consonant sets their starting states by its shape:
| Consonants | Kind | Above | Below |
|---|---|---|---|
| PO PLA, FO FA, FO FAN | ascender (AC) | starts in T1 | B0 |
| YO YING, THO THAN | removable descender (RC) | T0 | B1 |
| DO CHADA, TO PATAK | strict descender (DC) | T0 | B2 |
| the other consonants, U+0E01 to U+0E2E | normal (NC) | T0 | B0 |
| anything else | T3 | B2 |
Each mark is an upper vowel or sign (MAI HAN-AKAT, SARA I to SARA UEE, MAITAIKHU, NIKHAHIT, YAMAKKAN), a lower vowel (SARA U, SARA UU, PHINTHU), or a tone mark (MAI EK to THANTHAKHAT), and moves both machines on. The transitions that do something are:
| Where | Mark | Action |
|---|---|---|
| T0: nothing above yet | tone mark | shift down |
| T1: an ascender, nothing above yet | upper vowel | shift left |
| T1 | tone mark | shift down and left |
| T2: an ascender and a shifted upper vowel | tone mark | shift left |
| B1: a removable descender | lower vowel | take the descender off the consonant |
| B2: a strict descender, or a lower vowel already | lower vowel | shift down |
Any other mark changes nothing, and once a tone mark or a plain upper vowel has been placed, the state above is T3, where nothing changes again. An action is carried out by looking the character up in one of four small tables, which give its Windows and Mac PUA code points. If the font maps the Windows one, the character becomes that; if not, the Mac one; if neither, it stays as it was (thai_pua_shape, :98). “Take the descender off” changes the consonant, not the mark.
thai-pua.ttf has the same glyphs as thai.ttf and no layout tables, and maps the moved forms at the Windows code points. thai-pua-mac.ttf maps them at the Mac ones. thai.ttf has a GSUB under thai, whose one lookup removes YO YING’s descender before SARA U, as a modern font’s ccmp might:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| thai.ttf | ก่␣ป่␣ปิ่␣ญุ␣ฎุU+0E01 U+0E48 U+0020 U+0E1B U+0E48 U+0020 U+0E1B U+0E34 U+0E48 U+0020 U+0E0D U+0E38 U+0020 U+0E0E U+0E38 | --language=th | [kokai=0+500| |
| thai-pua.ttf | ก่␣ป่␣ปิ่␣ญุ␣ฎุU+0E01 U+0E48 U+0020 U+0E1B U+0E48 U+0020 U+0E1B U+0E34 U+0E48 U+0020 U+0E0D U+0E38 U+0020 U+0E0E U+0E38 | --language=th | [kokai=0+500| |
| thai-pua-mac.ttf | ก่␣ป่␣ปิ่␣ญุ␣ฎุU+0E01 U+0E48 U+0020 U+0E1B U+0E48 U+0020 U+0E1B U+0E34 U+0E48 U+0020 U+0E0D U+0E38 U+0020 U+0E0E U+0E38 | --language=th | [kokai=0+500| |
| thai-pua.ttf | กิ่␣ก่ำU+0E01 U+0E34 U+0E48 U+0020 U+0E01 U+0E48 U+0E33 | --language=th | [kokai=0+500| |
In the PUA fonts, MAI EK on KO KAI comes down into the space a vowel would have used, and on PO PLA it also moves left. With SARA I before it on PO PLA, both move left and the tone mark stays high. YO YING loses its descender and DO CHADA’s SARA U goes lower. The Windows and Mac fonts get the same glyphs. In the last line nothing is shifted: an upper vowel is already there, and so is a NIKHAHIT from SARA AM, moved before the tone mark, which counts as one. Drawn, with thai-pua.ttf first and thai.ttf, which has no GPOS to move anything, second:
[kokai=0+500|maiek.low=0+0|space=2+250|popla=3+500|maiek.lowleft=3+0|space=5+250|popla=6+500|sarai.left=6+0|maiek.left=6+0|space=9+250|yoying.nodesc=10+500|sarau=10+0|space=12+250|dochada=13+500|sarau.low=13+0]hb-vector thai-pua.ttf "ก่␣ป่␣ปิ่␣ญุ␣ฎุ" --language=th[kokai=0+500|maiek=0+0|space=2+250|popla=3+500|maiek=3+0|space=5+250|popla=6+500|sarai=6+0|maiek=6+0|space=9+250|yoying.nodesc=10+500|sarau=10+0|space=12+250|dochada=13+500|sarau=13+0]hb-vector thai.ttf "ก่␣ป่␣ปิ่␣ญุ␣ฎุ" --language=thIn the second drawing, the tone marks on PO PLA run into its ascender and SARA U on DO CHADA runs into its descender. A modern font would move them with GPOS.
The new code points replace the characters in the buffer, before normalization, so the cmap is asked for them in the ordinary way:
hb-shape thai-pua.ttf "ปิ่" --language=th --trace| start preprocess-text | <U+0E1B=0|U+0E34=0|U+0E48=0> |
| end preprocess-text | <U+0E1B=0|U+F701=0|U+F713=0> |
Only the code point changes. The Unicode properties were set before this step, so the PUA character keeps the general category and combining class of the mark it replaced: it is still zeroed as a mark, and still sorted with the other marks (read from the code: the hook writes only codepoint). Each mark the machines look at also marks the text from its consonant to it as unsafe to break.
HB_NO_OT_SHAPER_THAI_FALLBACK (implied by HB_NO_OT_SHAPE_FALLBACK) leaves the PUA shaping out, but not SARA AM’s.
Why Lao shares the shaper
The Lao block was laid out after the Thai one, and the characters the shaper cares about are at the same places, 0x80 higher. The comment in preprocess_text_thai puts it as “Note how the Lao versions are the same as Thai + 0x80”, and the code tests characters with that bit masked off:
#define IS_SARA_AM(x) (((x) & ~0x0080u) == 0x0E33u)
So Lao’s SARA AM, U+0EB3, is split and its NIKHAHIT moved the same way:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| thai.ttf | ກ່ຳU+0E81 U+0EC8 U+0EB3 | --language=lo | [lko=0+500| |
The PUA fallback is Thai only: its tables hold only Thai code points, and the test is for HB_SCRIPT_THAI. The modified combining class that puts SARA U and SARA UU before PHINTHU is Thai only too, since “Lao does NOT have a U+0E3A equivalent” (:297). Neither script gets fallback mark positioning or a legacy kern table, as Fallbacks and Legacy kern explain: the Thai shaper’s fallback_position is false.
Hangul
Syllables and jamo
A Korean syllable is written as a block of two or three letters, jamo: a leading consonant (L), a vowel (V), and an optional trailing consonant (T). Unicode encodes the jamo, U+1100 to U+11FF and two extension blocks, and also 11,172 precomposed syllables, U+AC00 to U+D7A3, one for each combination of the 19 modern leading consonants, 21 vowels, and 28 trailing choices (27 consonants or none). The syllables decompose to jamo by arithmetic, and the jamo compose back. The other jamo, in U+1100 to U+11FF and the extension blocks U+A960 and U+D7B0, are for Old Hangul, Korean as written before the twentieth century, whose syllables have no precomposed characters. A font shows an Old Hangul syllable by combining jamo glyphs, chosen by the features ljmo, vjmo, and tjmo.
So one syllable can come as a precomposed character <LV> or <LVT>, as jamo <L,V> or <L,V,T>, or as <LV,T>, and a font may have a glyph for the precomposed syllable, or jamo that combine, or both. Fonts, a comment in normalization says, “are not designed to mix-and-match pre-composed syllables and Jamo” (hb-ot-shape-normalize.cc:443). The Hangul shaper’s job is to pick one for each syllable, from what the font has.
Composing and decomposing, with the font in mind
It uses normalization mode NONE, so that normalization neither composes nor decomposes (Normalization), and does both itself in preprocess_text_hangul (hb-ot-shaper-hangul.cc:144). Its comment states the aim:
- If the whole syllable can be precomposed, do that,
- Otherwise, fully decompose and apply ljmo/vjmo/tjmo features.
In more detail, the loop looks at each character in turn:
<L,V>or<L,V,T>. If all are modern jamo that compose, and the font has the precomposed syllable, they become that one character. Otherwise they stay jamo, marked for the three features.<LV>or<LVT>. If the next character is a T that composes and the font has the result, they become that. Otherwise, if the font lacks the syllable, or the next character is a T that can’t compose with it, the syllable is decomposed into jamo, if the font has all of them, and marked for the features. A T that followed is taken into the syllable.
“Compose” here means only the modern jamo: L from U+1100 to U+1112, V from U+1161 to U+1175, T from U+11A8 to U+11C2. And “the whole syllable” means it: if the font has GA but not GAK, then GA followed by the trailing KIYEOK is decomposed into three jamo, not left as GA and one jamo. hangul.ttf has the syllables GA (가) and GAK (각) and the jamo they’re made of. hangul-no-gak.ttf is the same without GAK. Each line spells GA or GAK one of the possible ways:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | 가U+AC00 | --language=ko | [ga=0+1000] |
| hangul.ttf | 가U+1100 U+1161 | --language=ko | [ga=0+1000] |
| hangul.ttf | 각U+AC01 | --language=ko | [gak=0+1000] |
| hangul.ttf | 각U+1100 U+1161 U+11A8 | --language=ko | [gak=0+1000] |
| hangul.ttf | 각U+AC00 U+11A8 | --language=ko | [gak=0+1000] |
| hangul-no-gak.ttf | 가U+1100 U+1161 | --language=ko | [ga=0+1000] |
| hangul-no-gak.ttf | 각U+AC01 | --language=ko | [kiyeok.ljmo=0+500| |
| hangul-no-gak.ttf | 각U+1100 U+1161 U+11A8 | --language=ko | [kiyeok.ljmo=0+500| |
| hangul-no-gak.ttf | 각U+AC00 U+11A8 | --language=ko | [kiyeok.ljmo=0+500| |
Each spelling of a syllable gives the same glyphs in the same font: GAK where the font has it, and otherwise the three jamo in their ljmo, vjmo, and tjmo forms. The trace shows the decomposition in the characters:
hb-shape hangul-no-gak.ttf "각" --language=ko --trace| start preprocess-text | <U+AC01=0> |
| end preprocess-text | <U+1100=0|U+1161=0|U+11A8=0> |
An Old Hangul syllable never composes. Neither does a modern one with an Old Hangul trailing consonant, such as U+11EB PANSIOS, even where the font has the syllable before it:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | ᄒᆞᆫU+1112 U+119E U+11AB | --language=ko | [hieuh.ljmo=0+500| |
| hangul.ttf | 가ᇫU+AC00 U+11EB | --language=ko | [kiyeok.ljmo=0+500| |
The jamo features
collect_features_hangul adds ljmo, vjmo, and tjmo to the plan. They aren’t global: each gets its own mask bit (From features to lookups). While it composes and decomposes, the shaper writes into a spare byte of each jamo it leaves (hangul_shaping_feature, a buffer variable that Buffers lists) which of the three it should get, and setup_masks_hangul turns that into the feature’s mask bit (:416). So a font’s ljmo lookup only touches an L that begins a syllable of jamo. A leading consonant on its own isn’t one:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | ᄀU+1100 | --language=ko | [kiyeok=0+500] |
| hangul.ttf | 가ᇫU+1100 U+1161 U+11EB | --language=ko | [kiyeok.ljmo=0+500| |
calt, kept off jamo
Uniscribe doesn’t apply calt to Hangul, and some fonts, Noto Sans CJK and Source Han Sans among them, put all their jamo lookups in calt, where they aren’t wanted (the comment at :69, citing HarfBuzz discussion #4853; Why shaping exists has more on Uniscribe’s influence). Until 14.3.0 HarfBuzz turned calt off for the whole run. Now override_features_hangul asks for calt once more, which gives it a mask bit of its own (From features to lookups), and setup_masks_hangul clears that bit on every jamo character, L, V, or T. Everything else in the run, syllables included, keeps calt. The test font’s calt changes the first of two KIYEOKs, and the first of two GAs:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | ᄀᄀU+1100 U+1100 | --language=ko | [kiyeok=0+500| |
| hangul.ttf | 가가U+AC00 U+AC00 | --language=ko | [ga.calt=0+1000| |
| hangul.ttf | 가가U+1100 U+1161 U+1100 U+1161 | --language=ko | [ga.calt=0+1000| |
The two jamo are left alone. The syllables, including the ones composed from jamo, get the rule. Since the check is on the character, jamo still count as context for other glyphs’ calt rules: a context needn’t have the lookup’s mask (GSUB).
Tone marks
Middle Korean marked pitch with dots beside the syllable, encoded as U+302E HANGUL SINGLE DOT TONE MARK and U+302F HANGUL DOUBLE DOT TONE MARK. They follow the syllable in the text but are written before it, to its left. The shaper moves a tone mark that follows a syllable it has just recognized to the front of it, and merges their clusters, unless the font gives the tone mark zero advance, in which case “we leave it untouched, assuming it’s designed to overstrike” (:174). In hangul.ttf the single dot has an advance and the double dot doesn’t:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | 가〮U+AC00 U+302E | --language=ko | [singledot=0+200| |
| hangul.ttf | ᄒᆞᆫ〮U+1112 U+119E U+11AB U+302E | --language=ko | [singledot=0+200| |
| hangul.ttf | 가〯U+AC00 U+302F | --language=ko | [ga=0+1000| |
The double dot stays where it was typed, and since the font has no GPOS, HarfBuzz’s fallback positioner centers it over the syllable, as it does any mark of its class (Fallbacks).
A tone mark that doesn’t follow a recognized syllable gets a dotted circle, unless the buffer says not to or the font has none. It is the Hangul shaper’s own way of inserting one, one of four in HarfBuzz (Dotted circles and broken clusters). A tone mark with an advance goes before the circle, and a zero-width one after it:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul.ttf | 〮U+302E | --language=ko | [singledot=0+200| |
| hangul.ttf | ᄀ〮U+1100 U+302E | --language=ko | [kiyeok=0+500| |
| hangul.ttf | 〮U+302E | --language=ko --bot | [singledot=0+200| |
The dotted circle is made by replace_glyphs, which copies the tone mark’s buffer entry, and is then given the Unicode properties of U+25CC (:247), as the generic dotted circle inserted at the start of text is (hb-ot-shape.cc:566). So the circle is a base, and keeps its advance even after a lone KIYEOK, in the second line, where the tone mark, a spacing mark to the fallback positioner, is placed over the KIYEOK. At the beginning of text (--bot), the generic circle comes first, and the Hangul shaper takes a dotted circle as a tone mark’s base (:402), so the text gets one circle. Before 15.2.0 the shaper’s circle kept the tone mark’s properties and lost its advance after a base, and with --bot there were two circles (HHW-19, HHW-20).
Old Hangul and KOH
The shaper never looks at the language. OpenType has a language system tag for Old Hangul, KOH, and HarfBuzz maps the language ko to KOR and then KOH, and okm, Middle Korean, to KOH (hb-ot-tag-table.hh:113, :933; Choosing a script shaper). So a font that keeps its jamo features under KOH alone still gets them for Korean text, unless it also has a KOR language system. hangul-koh.ttf registers ljmo, vjmo, and tjmo only under KOH:
| Font | Text | Options | hb-shape output |
|---|---|---|---|
| hangul-koh.ttf | ᄒᆞᆫU+1112 U+119E U+11AB | --language=ko | [hieuh.ljmo=0+500| |
| hangul-koh.ttf | ᄒᆞᆫU+1112 U+119E U+11AB | --language=okm | [hieuh.ljmo=0+500| |
| hangul-koh.ttf | ᄒᆞᆫU+1112 U+119E U+11AB | --language=en | [hieuh=0+500| |
For type designers: the Hangul shaper uses a precomposed syllable whenever the font has it, and decomposes it whenever the font lacks it and has all its jamo. A font with jamo features for Old Hangul still gets precomposed glyphs for modern syllables. Put jamo lookups in
ljmo,vjmo, andtjmo, notcalt, and don’t rely oncaltreaching jamo.
Where to read the source
| File | What’s there |
|---|---|
src/hb-ot-shaper-hebrew.cc |
compose_hebrew (presentation forms), reorder_marks_hebrew, the gpos_tag |
src/hb-ot-shaper-thai.cc |
preprocess_text_thai (SARA AM), do_thai_pua_shaping and thai_pua_shape (the PUA fallback) |
src/hb-ot-shaper-hangul.cc |
preprocess_text_hangul (composing, decomposing, tone marks), the jamo features and calt masks |
src/hb-unicode.hh |
the modified combining classes for Hebrew, Thai, and Lao |
src/hb-ot-shape-normalize.cc |
where compose and reorder_marks are called, and mode NONE |
src/hb-ot-shape.cc |
has_gpos_mark and the gpos_tag test, in the planner |
src/hb-ot-tag-table.hh |
ko to KOR and KOH, generated by gen-tag-table.py |
None of this chapter’s tables is generated: the Hebrew presentation forms, the Thai state machines and PUA mappings, and the Hangul constants are written out in the shaper files.
In short
- Hebrew: after normalization sorts the points, one sequence is swapped so that a meteg or accent below follows a patah or qamats. Old fonts with no
markfeature get Hebrew presentation forms, composed from letters and points. So do fonts whose GPOS is ignored because it has nohebrscript. - Thai and Lao: SARA AM is always split into NIKHAHIT and SARA AA, and the NIKHAHIT moved back before any tone mark, so the font needs those two glyphs.
- Thai fonts without a
thaiGSUB script get marks and consonants swapped for the Windows or Mac private-use glyphs that old fonts used, chosen by two small state machines. - Lao shares the Thai shaper because its block mirrors Thai’s, 0x80 higher; the PUA fallback is Thai only.
- Hangul: each syllable becomes a precomposed glyph if the font has the whole of it, and jamo with
ljmo,vjmo, andtjmootherwise.caltis kept off jamo only. - Hangul tone marks move before their syllable unless they have zero width. A stray tone mark gets a dotted circle, with U+25CC’s own properties, or uses one already there as its base.