ui_controls

source of pkg::alloy::text::shaping::tags

1// OpenType's script tags for a run, as HarfBuzz gives them2// (hb-ot-tag.cc): a script's new tags (`dev3`, `dev2`) before its old one3// (`deva`). The language systems a BCP 47 tag names are text_scripts'.45import std::vector;6import std::option;78import font::reader;9import unicode::tables;10import unicode::properties;11import opentype;1213// Up to three tags, the first preferred.14exp type Tags = struct {15    exp values: [u32 : 3] = [0, 0, 0],16    exp count: u64 = 0,17};1819exp fn push(self tags: &var Tags, value: u32) {20    if (tags.count < 3) {21        tags.values[tags.count] = value;22        tags.count += 1;23    }24}2526exp fn view(self tags: &Tags) -> &[u32] => &tags.values[..tags.count];2728// The script's tags, the newest specification's first.29exp fn script_tags(s: Script) -> Tags {30    var tags = Tags {};31    const new_tag: u32 = match (s) {32        ::Bengali tag(&"bng2");33        ::Devanagari tag(&"dev2");34        ::Gujarati tag(&"gjr2");35        ::Gurmukhi tag(&"gur2");36        ::Kannada tag(&"knd2");37        ::Malayalam tag(&"mlm2");38        ::Oriya tag(&"ory2");39        ::Tamil tag(&"tml2");40        ::Telugu tag(&"tel2");41        ::Myanmar tag(&"mym2");42        else 0;43    };44    if (new_tag != 0) {45        if (!(s is ::Myanmar)) {46            tags.push((new_tag & 0xFFFFFF00) | '3' to u32);47        }48        tags.push(new_tag);49    }50    // the old tag: the ISO 15924 code with a lowercase first letter51    const old_tag: u32 = match (s) {52        ::Hiragana tag(&"kana");53        ::Lao tag(&"lao ");54        ::Yi tag(&"yi  ");55        ::Nko tag(&"nko ");56        ::Vai tag(&"vai ");57        else script_code(s) | 0x20000000;58    };59    tags.push(old_tag);60    return tags;61}6263// Whether the script is written right to left.64exp fn is_right_to_left_script(s: Script) -> bool => match (s) {65    ::Arabic, ::Hebrew, ::Syriac, ::Thaana, ::Cypriot, ::Kharoshthi, ::Phoenician,66    ::Nko, ::Lydian, ::Avestan, ::ImperialAramaic, ::InscriptionalPahlavi,67    ::InscriptionalParthian, ::OldSouthArabian, ::OldTurkic, ::Samaritan, ::Mandaic,68    ::MeroiticCursive, ::MeroiticHieroglyphs, ::Manichaean, ::MendeKikakui,69    ::Nabataean, ::OldNorthArabian, ::Palmyrene, ::PsalterPahlavi, ::Hatran, ::Adlam,70    ::HanifiRohingya, ::OldSogdian, ::Sogdian, ::Elymaic, ::Chorasmian, ::Yezidi,71    ::OldUyghur, ::Garay true;72    else false;73};7475// Whether the script may be written either way.76exp fn is_either_direction_script(s: Script) -> bool => match (s) {77    ::OldHungarian, ::OldItalic, ::Runic, ::Tifinagh true;78    else false;79};