1use ttf_parser::gsub::*;
2use ttf_parser::opentype_layout::LookupIndex;
3
4use super::buffer::hb_buffer_t;
5use super::hb_font_t;
6use super::ot_layout::*;
7use super::ot_layout_common::{SubstLookup, SubstitutionTable};
8use super::ot_layout_gsubgpos::*;
9use super::ot_shape_plan::hb_ot_shape_plan_t;
10use OT::hb_ot_apply_context_t;
11
12pub fn substitute(plan: &hb_ot_shape_plan_t, face: &hb_font_t, buffer: &mut hb_buffer_t) {
13 apply_layout_table(plan, face, buffer, table:face.gsub.as_ref());
14}
15
16impl<'a> LayoutTable for SubstitutionTable<'a> {
17 const INDEX: TableIndex = TableIndex::GSUB;
18 const IN_PLACE: bool = false;
19
20 type Lookup = SubstLookup<'a>;
21
22 fn get_lookup(&self, index: LookupIndex) -> Option<&Self::Lookup> {
23 self.lookups.get(index:usize::from(index))
24 }
25}
26
27impl WouldApply for SubstitutionSubtable<'_> {
28 fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
29 match self {
30 Self::Single(t: &SingleSubstitution<'_>) => t.would_apply(ctx),
31 Self::Multiple(t: &MultipleSubstitution<'_>) => t.would_apply(ctx),
32 Self::Alternate(t: &AlternateSubstitution<'_>) => t.would_apply(ctx),
33 Self::Ligature(t: &LigatureSubstitution<'_>) => t.would_apply(ctx),
34 Self::Context(t: &ContextLookup<'_>) => t.would_apply(ctx),
35 Self::ChainContext(t: &ChainedContextLookup<'_>) => t.would_apply(ctx),
36 Self::ReverseChainSingle(t: &ReverseChainSingleSubstitution<'_>) => t.would_apply(ctx),
37 }
38 }
39}
40
41impl Apply for SubstitutionSubtable<'_> {
42 fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
43 match self {
44 Self::Single(t: &SingleSubstitution<'_>) => t.apply(ctx),
45 Self::Multiple(t: &MultipleSubstitution<'_>) => t.apply(ctx),
46 Self::Alternate(t: &AlternateSubstitution<'_>) => t.apply(ctx),
47 Self::Ligature(t: &LigatureSubstitution<'_>) => t.apply(ctx),
48 Self::Context(t: &ContextLookup<'_>) => t.apply(ctx),
49 Self::ChainContext(t: &ChainedContextLookup<'_>) => t.apply(ctx),
50 Self::ReverseChainSingle(t: &ReverseChainSingleSubstitution<'_>) => t.apply(ctx),
51 }
52 }
53}
54