//! UI fallback fonts for the non-CJK scripts the bundled Inter / JetBrains Mono don't draw //! (Thai, Arabic, Hebrew, the Indic scripts, ...): which characters belong to which script, and //! which installed font files to try for it. //! //! Candidates come from the file names in the platform font directories (the same directories //! [`crate::fonts::FontDb`] scans), listed once per process and only when first asked for, so //! nothing is read at startup and no path is hard-coded per distribution. Noto fonts are matched //! by their family-derived file names (`NotoSansThai-Regular.ttf`, `NotoSansThai[wght].ttf`), //! platform fonts by their known file names (Leelawadee UI, Nirmala UI, Segoe UI, Geeza Pro, //! Kohinoor, DejaVu Sans, Lohit, ...). A file name is only a hint: callers check that a face //! really maps the character ([`covering_face`]) before using it. CJK has its own, //! locale-ordered lists ([`crate::cjk`]). /// A script that needs a UI fallback font. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Script { Thai, Lao, Khmer, Myanmar, Tibetan, Arabic, Hebrew, Armenian, Georgian, Ethiopic, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala, } impl Script { pub const ALL: [Script; 20] = [ Script::Thai, Script::Lao, Script::Khmer, Script::Myanmar, Script::Tibetan, Script::Arabic, Script::Hebrew, Script::Armenian, Script::Georgian, Script::Ethiopic, Script::Devanagari, Script::Bengali, Script::Gurmukhi, Script::Gujarati, Script::Oriya, Script::Tamil, Script::Telugu, Script::Kannada, Script::Malayalam, Script::Sinhala, ]; /// Font file names for this script, most preferred first: lowercase, without extension, /// spaces, underscores or style suffix (`NotoSansThai-Bold.ttf` and `NotoSansThai[wght].ttf` /// are both `notosansthai`). Noto first (the usual Linux font), then Windows, macOS and /// other Linux families. fn file_names(self) -> &'static [&'static str] { use Script::*; match self { Thai => &[ "notosansthai", "notosansthailooped", "notosansthaiui", "notoserifthai", "leelawui", "leelawad", "tahoma", "thonburi", "sukhumvitset", "ayuthaya", "loma", "garuda", "waree", "kinnari", "norasi", ], Lao => &["notosanslao", "notosanslaoui", "notoseriflao", "leelawui", "laosangammn", "laomn", "phetsarathot", "saysetthaot"], Khmer => &["notosanskhmer", "notosanskhmerui", "notoserifkhmer", "leelawui", "daunpenh", "khmersangammn", "khmermn", "khmeros", "khmerossys"], Myanmar => &["notosansmyanmar", "notosansmyanmarui", "notoserifmyanmar", "mmrtext", "myanmarsangammn", "myanmarmn", "padauk"], Tibetan => &["notoseriftibetan", "himalaya", "kailasa", "jomolhari", "tibetanmachineuni"], Arabic => &[ "notosansarabic", "notosansarabicui", "notonaskharabic", "notonaskharabicui", "notokufiarabic", "segoeui", "tahoma", "geezapro", "sfarabic", "dejavusans", "kacstone", "kacstbook", "amiri", "arial", ], Hebrew => &["notosanshebrew", "notoserifhebrew", "segoeui", "arialhb", "sfhebrew", "dejavusans", "arial", "freesans", "culmus"], Armenian => &["notosansarmenian", "notoserifarmenian", "segoeui", "sylfaen", "mshtakan", "dejavusans", "freesans"], Georgian => &["notosansgeorgian", "notoserifgeorgian", "segoeui", "sylfaen", "dejavusans", "freesans"], Ethiopic => &["notosansethiopic", "notoserifethiopic", "ebrima", "kefa", "abyssinicasil"], Devanagari => &[ "notosansdevanagari", "notosansdevanagariui", "notoserifdevanagari", "nirmala", "mangal", "kohinoor", "kohinoordevanagari", "itfdevanagari", "devanagarimt", "devanagarisangammn", "lohitdevanagari", "lohit-devanagari", "gargi", "freesans", ], Bengali => &[ "notosansbengali", "notosansbengaliui", "notoserifbengali", "nirmala", "vrinda", "kohinoorbangla", "banglasangammn", "banglamn", "lohitbengali", "lohit-bengali", "lohit-assamese", ], Gurmukhi => &[ "notosansgurmukhi", "notosansgurmukhiui", "notoserifgurmukhi", "nirmala", "raavi", "gurmukhisangammn", "gurmukhimn", "lohit-gurmukhi", "lohit-punjabi", ], Gujarati => &[ "notosansgujarati", "notosansgujaratiui", "notoserifgujarati", "nirmala", "shruti", "kohinoorgujarati", "gujaratisangammn", "gujaratimt", "lohit-gujarati", ], Oriya => &["notosansoriya", "notosansoriyaui", "notoseriforiya", "nirmala", "kalinga", "oriyasangammn", "oriyamn", "lohit-odia", "lohit-oriya"], Tamil => &["notosanstamil", "notosanstamilui", "notoseriftamil", "nirmala", "latha", "tamilsangammn", "tamilmn", "lohit-tamil"], Telugu => { &["notosanstelugu", "notosansteluguui", "notoseriftelugu", "nirmala", "gautami", "kohinoortelugu", "telugusangammn", "telugumn", "lohit-telugu"] } Kannada => &["notosanskannada", "notosanskannadaui", "notoserifkannada", "nirmala", "tunga", "kannadasangammn", "kannadamn", "lohit-kannada"], Malayalam => { &["notosansmalayalam", "notosansmalayalamui", "notoserifmalayalam", "nirmala", "kartika", "malayalamsangammn", "malayalammn", "lohit-malayalam"] } Sinhala => &["notosanssinhala", "notosanssinhalaui", "notoserifsinhala", "nirmala", "iskpota", "sinhalasangammn", "sinhalamn", "lklug"], } } } /// The script of a character that needs a non-CJK fallback font, or `None`. pub fn classify(c: char) -> Option