rustybuzz/hb/ot/layout/GSUB/
alternate_subst.rs

1use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t;
2use crate::hb::ot_layout_gsubgpos::{Apply, WouldApply, WouldApplyContext};
3use ttf_parser::gsub::AlternateSubstitution;
4
5// AlternateSubstFormat1::would_apply
6impl WouldApply for AlternateSubstitution<'_> {
7    fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
8        ctx.glyphs.len() == 1 && self.coverage.get(ctx.glyphs[0]).is_some()
9    }
10}
11
12// AlternateSubstFormat1::apply
13impl Apply for AlternateSubstitution<'_> {
14    fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
15        let glyph = ctx.buffer.cur(0).as_glyph();
16        let index = self.coverage.get(glyph)?;
17        let set = self.alternate_sets.get(index)?;
18        set.apply(ctx)
19    }
20}