write_fonts/tables/
gsub.rs

1//! the [GSUB] table
2//!
3//! [GSUB]: https://docs.microsoft.com/en-us/typography/opentype/spec/gsub
4
5include!("../../generated/generated_gsub.rs");
6
7use super::layout::{
8    ChainedSequenceContext, CoverageTable, FeatureList, FeatureVariations, Lookup, LookupList,
9    LookupSubtable, LookupType, ScriptList, SequenceContext,
10};
11
12pub mod builders;
13#[cfg(test)]
14mod spec_tests;
15
16/// A GSUB lookup list table.
17pub type SubstitutionLookupList = LookupList<SubstitutionLookup>;
18
19super::layout::table_newtype!(
20    SubstitutionSequenceContext,
21    SequenceContext,
22    read_fonts::tables::layout::SequenceContext<'a>
23);
24
25super::layout::table_newtype!(
26    SubstitutionChainContext,
27    ChainedSequenceContext,
28    read_fonts::tables::layout::ChainedSequenceContext<'a>
29);
30
31impl Gsub {
32    fn compute_version(&self) -> MajorMinor {
33        if self.feature_variations.is_none() {
34            MajorMinor::VERSION_1_0
35        } else {
36            MajorMinor::VERSION_1_1
37        }
38    }
39}
40
41super::layout::lookup_type!(gsub, SingleSubst, 1);
42super::layout::lookup_type!(gsub, MultipleSubstFormat1, 2);
43super::layout::lookup_type!(gsub, AlternateSubstFormat1, 3);
44super::layout::lookup_type!(gsub, LigatureSubstFormat1, 4);
45super::layout::lookup_type!(gsub, SubstitutionSequenceContext, 5);
46super::layout::lookup_type!(gsub, SubstitutionChainContext, 6);
47super::layout::lookup_type!(gsub, ExtensionSubtable, 7);
48super::layout::lookup_type!(gsub, ReverseChainSingleSubstFormat1, 8);
49
50impl<T: LookupSubtable + FontWrite> FontWrite for ExtensionSubstFormat1<T> {
51    fn write_into(&self, writer: &mut TableWriter) {
52        1u16.write_into(writer);
53        T::TYPE.write_into(writer);
54        self.extension.write_into(writer);
55    }
56}
57
58// these can't have auto impls because the traits don't support generics
59impl<'a> FontRead<'a> for SubstitutionLookup {
60    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
61        read_fonts::tables::gsub::SubstitutionLookup::read(data).map(|x| x.to_owned_table())
62    }
63}
64
65impl<'a> FontRead<'a> for SubstitutionLookupList {
66    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
67        read_fonts::tables::gsub::SubstitutionLookupList::read(data).map(|x| x.to_owned_table())
68    }
69}