pub mod arabic;
pub mod indic;
pub mod khmer;
pub mod myanmar;
mod syllable;
pub mod syriac;
pub mod thai_lao;
use crate::glyph_position::TextDirection;
use crate::gsub::{GlyphOrigin, RawGlyph};
use crate::scripts::syllable::SyllableChar;
use crate::tag;
use crate::unicode::mcc::sort_by_modified_combining_class;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ScriptType {
Arabic,
Default,
Indic,
Khmer,
Myanmar,
Syriac,
ThaiLao,
}
impl From<u32> for ScriptType {
fn from(script_tag: u32) -> Self {
match script_tag {
tag::ARAB => ScriptType::Arabic,
tag::LATN => ScriptType::Default,
tag::CYRL => ScriptType::Default,
tag::GREK => ScriptType::Default,
tag::DEVA => ScriptType::Indic,
tag::BENG => ScriptType::Indic,
tag::GURU => ScriptType::Indic,
tag::GUJR => ScriptType::Indic,
tag::ORYA => ScriptType::Indic,
tag::TAML => ScriptType::Indic,
tag::TELU => ScriptType::Indic,
tag::KNDA => ScriptType::Indic,
tag::MLYM => ScriptType::Indic,
tag::SINH => ScriptType::Indic,
tag::KHMR => ScriptType::Khmer,
tag::MYMR => ScriptType::Myanmar,
tag::MYM2 => ScriptType::Myanmar,
tag::SYRC => ScriptType::Syriac,
tag::THAI => ScriptType::ThaiLao,
tag::LAO => ScriptType::ThaiLao,
_ => ScriptType::Default,
}
}
}
impl<T> SyllableChar for RawGlyph<T> {
fn char(&self) -> char {
match self.glyph_origin {
GlyphOrigin::Char(ch) => ch,
GlyphOrigin::Direct => panic!("unexpected glyph origin"),
}
}
}
pub fn preprocess_text(cs: &mut Vec<char>, script_tag: u32) {
match ScriptType::from(script_tag) {
ScriptType::Arabic => arabic::reorder_marks(cs),
ScriptType::Default => sort_by_modified_combining_class(cs),
ScriptType::Indic => indic::preprocess_indic(cs, script_tag),
ScriptType::Khmer => khmer::preprocess_khmer(cs),
ScriptType::Myanmar => {}
ScriptType::Syriac => sort_by_modified_combining_class(cs),
ScriptType::ThaiLao => thai_lao::reorder_marks(cs),
}
}
mod rtl_tags {
use crate::tag;
pub const ARAB: u32 = tag!(b"arab"); pub const HEBR: u32 = tag!(b"hebr");
pub const SYRC: u32 = tag!(b"syrc"); pub const THAA: u32 = tag!(b"thaa");
pub const CPRT: u32 = tag!(b"cprt");
pub const KHAR: u32 = tag!(b"khar");
pub const PHNX: u32 = tag!(b"phnx"); pub const NKO: u32 = tag!(b"nko ");
pub const LYDI: u32 = tag!(b"lydi");
pub const AVST: u32 = tag!(b"avst"); pub const ARMI: u32 = tag!(b"armi"); pub const PHLI: u32 = tag!(b"phli"); pub const PRTI: u32 = tag!(b"prti"); pub const SARB: u32 = tag!(b"sarb"); pub const ORKH: u32 = tag!(b"orkh"); pub const SAMR: u32 = tag!(b"samr");
pub const MAND: u32 = tag!(b"mand");
pub const MERC: u32 = tag!(b"merc"); pub const MERO: u32 = tag!(b"mero");
pub const MANI: u32 = tag!(b"mani"); pub const MEND: u32 = tag!(b"mend"); pub const NBAT: u32 = tag!(b"nbat"); pub const NARB: u32 = tag!(b"narb"); pub const PALM: u32 = tag!(b"palm"); pub const PHLP: u32 = tag!(b"phlp");
pub const HATR: u32 = tag!(b"hatr");
pub const ADLM: u32 = tag!(b"adlm");
pub const ROHG: u32 = tag!(b"rohg"); pub const SOGO: u32 = tag!(b"sogo"); pub const SOGD: u32 = tag!(b"sogd");
pub const ELYM: u32 = tag!(b"elym");
pub const CHRS: u32 = tag!(b"chrs"); pub const YEZI: u32 = tag!(b"yezi");
pub const OUGR: u32 = tag!(b"ougr");
pub const GARA: u32 = tag!(b"gara"); }
pub fn horizontal_text_direction(script: u32) -> TextDirection {
use rtl_tags as rtl;
match script {
| rtl::ARAB | rtl::HEBR
| rtl::SYRC | rtl::THAA
| rtl::CPRT
| rtl::KHAR
| rtl::PHNX | rtl::NKO
| rtl::LYDI
| rtl::AVST | rtl::ARMI | rtl::PHLI | rtl::PRTI | rtl::SARB | rtl::ORKH | rtl::SAMR
| rtl::MAND
| rtl::MERC | rtl::MERO
| rtl::MANI | rtl::MEND | rtl::NBAT | rtl::NARB | rtl::PALM | rtl::PHLP
| rtl::HATR
| rtl::ADLM
| rtl::ROHG | rtl::SOGO | rtl::SOGD
| rtl::ELYM
| rtl::CHRS | rtl::YEZI
| rtl::OUGR
| rtl::GARA => TextDirection::RightToLeft,
_ => TextDirection::LeftToRight,
}
}