use super::buffer::MARK_ATTACH;
use crate::font_introspector::text::cluster::{ClusterInfo, SourceRange, UserData};
use crate::font_introspector::GlyphId;
#[allow(unused)]
#[derive(Copy, Clone, Default, Debug)]
pub struct GlyphInfo(pub u16);
impl GlyphInfo {
#[allow(unused)]
pub fn is_mark(self) -> bool {
self.0 & MARK_ATTACH != 0
}
}
#[derive(Copy, Clone, Default, Debug)]
pub struct Glyph {
pub id: GlyphId,
#[allow(unused)]
pub info: GlyphInfo,
pub x: f32,
pub y: f32,
pub advance: f32,
pub data: UserData,
}
#[derive(Copy, Clone, Debug)]
pub struct GlyphCluster<'a> {
pub source: SourceRange,
pub info: ClusterInfo,
pub glyphs: &'a [Glyph],
pub components: &'a [SourceRange],
pub data: UserData,
}
#[derive(Clone, Debug)]
pub struct OwnedGlyphCluster {
pub source: SourceRange,
pub info: ClusterInfo,
pub glyphs: Vec<Glyph>,
pub components: Vec<SourceRange>,
pub data: UserData,
}
impl<'a> From<&GlyphCluster<'a>> for OwnedGlyphCluster {
fn from(glyph_cluster: &GlyphCluster<'a>) -> Self {
OwnedGlyphCluster {
source: glyph_cluster.source,
info: glyph_cluster.info,
data: glyph_cluster.data,
components: glyph_cluster.components.to_vec(),
glyphs: glyph_cluster.glyphs.to_vec(),
}
}
}
#[allow(unused)]
impl<'a> GlyphCluster<'a> {
pub fn is_empty(&self) -> bool {
self.glyphs.is_empty()
}
pub fn is_simple(&self) -> bool {
self.glyphs.len() == 1
}
pub fn is_ligature(&self) -> bool {
!self.components.is_empty()
}
pub fn is_complex(&self) -> bool {
self.glyphs.len() > 1
}
pub fn advance(&self) -> f32 {
let mut advance = 0.;
for g in self.glyphs {
advance += g.advance;
}
advance
}
}