use write_fonts::{read::collections::IntSet, types::GlyphId16};
use super::GlyphOrClass;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct GlyphClass(Vec<GlyphId16>);
pub type GlyphSet = IntSet<GlyphId16>;
impl GlyphClass {
pub const EMPTY: Self = GlyphClass(Vec::new());
pub(crate) fn items(&self) -> &[GlyphId16] {
&self.0
}
pub(crate) fn to_glyph_set(&self) -> GlyphSet {
self.iter().collect()
}
pub(crate) fn iter(&self) -> impl Iterator<Item = GlyphId16> + '_ {
self.items().iter().copied()
}
pub(crate) fn len(&self) -> usize {
self.0.len()
}
}
impl std::iter::FromIterator<GlyphId16> for GlyphClass {
fn from_iter<T: IntoIterator<Item = GlyphId16>>(iter: T) -> Self {
GlyphClass(iter.into_iter().collect())
}
}
impl<'a> std::iter::IntoIterator for &'a GlyphClass {
type Item = &'a GlyphId16;
type IntoIter = std::slice::Iter<'a, GlyphId16>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl From<Vec<GlyphId16>> for GlyphClass {
fn from(src: Vec<GlyphId16>) -> GlyphClass {
GlyphClass(src)
}
}
impl From<GlyphClass> for GlyphSet {
fn from(value: GlyphClass) -> Self {
value.iter().collect()
}
}
impl From<GlyphId16> for GlyphClass {
fn from(src: GlyphId16) -> GlyphClass {
let slice: &[_] = &[src];
GlyphClass(slice.into())
}
}
impl From<GlyphOrClass> for GlyphClass {
fn from(src: GlyphOrClass) -> GlyphClass {
match src {
GlyphOrClass::Class(class) => class,
GlyphOrClass::Glyph(id) => id.into(),
GlyphOrClass::Null => GlyphClass::EMPTY,
}
}
}