1 | use crate::hb::ot_layout::LayoutLookup; |
2 | use crate::hb::ot_layout_common::SubstLookup; |
3 | use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t; |
4 | use crate::hb::ot_layout_gsubgpos::{Apply, WouldApply, WouldApplyContext}; |
5 | use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t}; |
6 | |
7 | impl LayoutLookup for SubstLookup<'_> { |
8 | fn props(&self) -> u32 { |
9 | self.props |
10 | } |
11 | |
12 | fn is_reverse(&self) -> bool { |
13 | self.reverse |
14 | } |
15 | |
16 | fn digest(&self) -> &hb_set_digest_t { |
17 | &self.set_digest |
18 | } |
19 | } |
20 | |
21 | impl WouldApply for SubstLookup<'_> { |
22 | fn would_apply(&self, ctx: &WouldApplyContext) -> bool { |
23 | self.digest().may_have_glyph(ctx.glyphs[0]) |
24 | && self |
25 | .subtables |
26 | .iter() |
27 | .any(|subtable: &SubstitutionSubtable<'_>| subtable.would_apply(ctx)) |
28 | } |
29 | } |
30 | |
31 | impl Apply for SubstLookup<'_> { |
32 | fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> { |
33 | if self.digest().may_have_glyph(ctx.buffer.cur(0).as_glyph()) { |
34 | for subtable: &SubstitutionSubtable<'_> in &self.subtables { |
35 | if subtable.apply(ctx).is_some() { |
36 | return Some(()); |
37 | } |
38 | } |
39 | } |
40 | |
41 | None |
42 | } |
43 | } |
44 | |