text_scripts

source of text_scripts

1// Complex scripts for pkg::alloy::text (REFOCUS.md, R6d): the2// shapers HarfBuzz has for Arabic and Syriac, Hebrew, the nine Indic3// scripts, Khmer, Myanmar, Thai and Lao, Hangul and the 84 scripts of4// the Universal Shaping Engine, with their syllable machines and5// tables; text in either direction and both mixed by UAX #9; lines of6// Thai, Lao, Khmer and Myanmar broken between graphemes; and the7// OpenType language systems of every BCP 47 tag HarfBuzz knows. A program8// installs them on its fonts before laying text out:9//10// ```text11// var fonts = Fonts::create();12// text_scripts::install_into(&var fonts);13// ui.install_fonts(text_scripts::install_into); // or a ui's, for each fonts it lays text out with14// ```15//16// Without them every run is shaped by the default shaper (Arabic letters17// unjoined, Indic clusters unordered) and laid out left to right, the18// same on every target.19//20// ## How it was built21//22// **R6d as built** (2026-10-22; REFOCUS.md, question 5A): moved23// out of `text`, whose F10b and F10c notes tell how it was built:24// `shaping/` the shapers (`complex.alloy` choosing one per run and25// dispatching to it as text's `ComplexShaper`, kept in the plan) with26// `machines.alloy` and `language_tags.alloy`, which `unicode/machines.alloy`27// and `unicode/language_tags.alloy` generate from HarfBuzz 14.1.0's28// headers, and `languages.alloy` reading BCP 47 tags; `unicode/` bidi29// (`bidi.alloy`, `levels.alloy`) and `script_tables.alloy`, the30// Bidi_Class, mirrors, Indic and USE categories, vowel constraints and31// Arabic presentation forms text's `unicode/generate.alloy` writes beside32// its own tables. `install_into` sets text's `ScriptHooks` on the fonts.33// Tests: `tests.alloy`; `check.alloy` against `hb-shape` (HarfBuzz's own34// tests, the scripts' cases in Noto fonts, pointed Hebrew right to left);35// `unicode/conformance.alloy` BidiTest.txt and BidiCharacterTest.txt.3637import std::option;3839import pkg::alloy::text;40import pkg::alloy::text::shaping::shapers;41import shaping::complex;42import shaping::languages;43import unicode::script_properties;44import unicode::levels;4546// What the fonts lay text out with from here on: the complex shapers,47// bidi and the language systems.48exp fn install_into(fonts: &var Fonts) {49    fonts.install_scripts(hooks());50}5152// The hooks text calls, for a plan made apart from fonts (text's53// `Plan::compile` and `shape`).54exp fn hooks() -> ScriptHooks => ScriptHooks {55    .shaper = complex_shaper,56    .languages = language_tags,57    .mirror = mirror,58    .levels = paragraph_levels,59    .reorder = reorder_line60};