fea_rs/common/
glyph_class.rs1use write_fonts::{read::collections::IntSet, types::GlyphId16};
2
3use super::GlyphOrClass;
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
25pub(crate) struct GlyphClass(Vec<GlyphId16>);
26
27pub type GlyphSet = IntSet<GlyphId16>;
32
33impl GlyphClass {
34 pub const EMPTY: Self = GlyphClass(Vec::new());
36
37 pub(crate) fn items(&self) -> &[GlyphId16] {
38 &self.0
39 }
40
41 pub(crate) fn to_glyph_set(&self) -> GlyphSet {
43 self.iter().collect()
44 }
45
46 pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId16> + '_ {
47 self.items().iter().copied()
48 }
49
50 pub(crate) fn len(&self) -> usize {
51 self.0.len()
52 }
53}
54
55impl std::iter::FromIterator<GlyphId16> for GlyphClass {
56 fn from_iter<T: IntoIterator<Item = GlyphId16>>(iter: T) -> Self {
57 GlyphClass(iter.into_iter().collect())
58 }
59}
60
61impl<'a> std::iter::IntoIterator for &'a GlyphClass {
62 type Item = &'a GlyphId16;
63
64 type IntoIter = std::slice::Iter<'a, GlyphId16>;
65
66 fn into_iter(self) -> Self::IntoIter {
67 self.0.iter()
68 }
69}
70
71impl From<Vec<GlyphId16>> for GlyphClass {
72 fn from(src: Vec<GlyphId16>) -> GlyphClass {
73 GlyphClass(src)
74 }
75}
76
77impl From<GlyphClass> for GlyphSet {
78 fn from(value: GlyphClass) -> Self {
79 value.iter().collect()
80 }
81}
82
83impl From<GlyphId16> for GlyphClass {
84 fn from(src: GlyphId16) -> GlyphClass {
85 let slice: &[_] = &[src];
86 GlyphClass(slice.into())
87 }
88}
89
90impl From<GlyphOrClass> for GlyphClass {
91 fn from(src: GlyphOrClass) -> GlyphClass {
92 match src {
93 GlyphOrClass::Class(class) => class,
94 GlyphOrClass::Glyph(id) => id.into(),
95 GlyphOrClass::Null => GlyphClass::EMPTY,
96 }
97 }
98}