rustybuzz/hb/ot/layout/GSUB/
single_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::SingleSubstitution;
4use ttf_parser::GlyphId;
5
6impl WouldApply for SingleSubstitution<'_> {
9 fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
10 ctx.glyphs.len() == 1 && self.coverage().get(ctx.glyphs[0]).is_some()
11 }
12}
13
14impl Apply for SingleSubstitution<'_> {
17 fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
18 let glyph = ctx.buffer.cur(0).as_glyph();
19 let subst = match *self {
20 Self::Format1 { coverage, delta } => {
21 coverage.get(glyph)?;
22 GlyphId((i32::from(glyph.0) + i32::from(delta)) as u16)
25 }
26 Self::Format2 {
27 coverage,
28 substitutes,
29 } => {
30 let index = coverage.get(glyph)?;
31 substitutes.get(index)?
32 }
33 };
34
35 ctx.replace_glyph(subst);
36 Some(())
37 }
38}