swash/feature/
aat.rs

1use super::internal::{aat::morx, raw_tag};
2use super::util::*;
3
4pub use morx::chains;
5use morx::Chains;
6
7#[derive(Copy, Clone)]
8pub struct Features<'a> {
9    chains: Chains<'a>,
10    features: Option<morx::Features<'a>>,
11    kern: bool,
12    seen: SeenFeatures,
13}
14
15impl<'a> Features<'a> {
16    pub fn new(chains: Chains<'a>, kern: bool) -> Self {
17        Self {
18            chains,
19            features: None,
20            kern,
21            seen: SeenFeatures::new(),
22        }
23    }
24}
25
26impl<'a> Iterator for Features<'a> {
27    type Item = (u32, &'static str);
28
29    fn next(&mut self) -> Option<Self::Item> {
30        loop {
31            if self.features.is_none() {
32                if let Some(chain) = self.chains.next() {
33                    self.features = Some(chain.features());
34                } else if self.kern {
35                    let tag = raw_tag(b"kern");
36                    let (_, desc) = desc_from_at(tag).unwrap_or((0, "Kerning"));
37                    self.kern = false;
38                    return Some((tag, desc));
39                } else {
40                    return None;
41                }
42            }
43            if let Some(features) = &mut self.features {
44                if let Some(feature) = features.next() {
45                    if let Some((index, tag, desc)) =
46                        desc_from_aat(feature.selector, feature.setting_selector)
47                    {
48                        if self.seen.mark(index) {
49                            return Some((tag, desc));
50                        }
51                    }
52                } else {
53                    self.features = None;
54                    continue;
55                }
56            }
57        }
58    }
59}
60
61pub type OnceItem<'a> = Option<Item<'a>>;
62// #[derive(Copy, Clone)]
63// pub struct OnceItem<'a> {
64//     pub item: Item<'a>,
65//     pub given: bool,
66// }
67
68// impl<'a> OnceItem<'a> {
69//     pub fn new(item: Item<'a>) -> Self {
70//         Self { item, given: false }
71//     }
72// }
73
74// impl<'a> Iterator for OnceItem<'a> {
75//     type Item = Item<'a>;
76
77//     fn next(&mut self) -> Option<Self::Item> {
78//         if self.given {
79//             None
80//         } else {
81//             self.given = true;
82//             Some(self.item)
83//         }
84//     }
85// }
86
87#[derive(Copy, Clone)]
88pub struct Item<'a> {
89    pub chains: Chains<'a>,
90    pub kern: bool,
91}