rustybuzz/hb/ot/layout/GSUB/
single_subst.rsuse crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t;
use crate::hb::ot_layout_gsubgpos::{Apply, WouldApply, WouldApplyContext};
use ttf_parser::gsub::SingleSubstitution;
use ttf_parser::GlyphId;
impl WouldApply for SingleSubstitution<'_> {
fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
ctx.glyphs.len() == 1 && self.coverage().get(ctx.glyphs[0]).is_some()
}
}
impl Apply for SingleSubstitution<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
let glyph = ctx.buffer.cur(0).as_glyph();
let subst = match *self {
Self::Format1 { coverage, delta } => {
coverage.get(glyph)?;
GlyphId((i32::from(glyph.0) + i32::from(delta)) as u16)
}
Self::Format2 {
coverage,
substitutes,
} => {
let index = coverage.get(glyph)?;
substitutes.get(index)?
}
};
ctx.replace_glyph(subst);
Some(())
}
}