#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Joining {
NonJoining,
JoinCausing,
DualJoining,
LeftJoining,
RightJoining,
Transparent,
}
pub mod gsub;
pub mod joining;
mod joining_table;
pub mod read;
pub mod script;
mod script_table;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Shaped {
pub glyph: u16,
pub cluster: usize,
}
pub const AFTER_FORMS: &[[u8; 4]] = &[*b"ccmp", *b"rlig", *b"rclt", *b"calt", *b"liga"];
#[must_use]
pub fn shape(
glyph_of: impl Fn(char) -> Option<u16>,
gsub: Option<&gsub::Gsub<'_>>,
script: &[u8; 4],
text: &[char],
) -> Vec<Shaped> {
let forms = joining::forms(text);
let mut pairs: Vec<(u16, usize)> = Vec::with_capacity(text.len());
for (i, c) in text.iter().enumerate() {
if let Some(g) = glyph_of(*c) {
pairs.push((g, i));
}
}
let Some(gsub) = gsub else {
return pairs
.into_iter()
.map(|(glyph, cluster)| Shaped { glyph, cluster })
.collect();
};
let mut buf = gsub::Buffer::new(&pairs);
for i in 0..buf.len() {
let Some(form) = forms.get(buf.clusters[i]) else {
continue;
};
let mut one = gsub::Buffer::new(&[(buf.glyphs[i], buf.clusters[i])]);
gsub.apply_feature(script, &form.tag(), &mut one);
if one.len() == 1 {
buf.glyphs[i] = one.glyphs[0];
}
}
for tag in AFTER_FORMS {
gsub.apply_feature(script, tag, &mut buf);
}
buf.glyphs
.iter()
.zip(&buf.clusters)
.map(|(glyph, cluster)| Shaped {
glyph: *glyph,
cluster: *cluster,
})
.collect()
}