2022-10-12 19:44:44 -07:00
|
|
|
use std::{collections::HashMap, sync::Mutex};
|
2022-10-12 13:42:30 -06:00
|
|
|
|
|
|
|
|
pub use self::cache::*;
|
|
|
|
|
mod cache;
|
|
|
|
|
|
2022-10-05 09:16:51 -06:00
|
|
|
pub use self::layout::*;
|
|
|
|
|
mod layout;
|
|
|
|
|
|
|
|
|
|
pub use self::matches::*;
|
|
|
|
|
mod matches;
|
|
|
|
|
|
|
|
|
|
pub use self::shape::*;
|
|
|
|
|
mod shape;
|
|
|
|
|
|
|
|
|
|
pub use self::system::*;
|
|
|
|
|
mod system;
|
|
|
|
|
|
2022-10-12 13:42:30 -06:00
|
|
|
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
|
|
|
pub struct FontCacheKey {
|
|
|
|
|
glyph_id: u16,
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 11:28:05 -06:00
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
|
|
|
|
|
pub struct FontLineIndex(usize);
|
|
|
|
|
|
|
|
|
|
impl FontLineIndex {
|
|
|
|
|
pub fn new(index: usize) -> Self {
|
|
|
|
|
Self(index)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get(&self) -> usize {
|
|
|
|
|
self.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 09:16:51 -06:00
|
|
|
pub struct Font<'a> {
|
2022-10-12 17:35:23 -06:00
|
|
|
pub name: &'a str,
|
|
|
|
|
pub data: &'a [u8],
|
|
|
|
|
pub index: u32,
|
2022-10-05 09:16:51 -06:00
|
|
|
pub rustybuzz: rustybuzz::Face<'a>,
|
|
|
|
|
#[cfg(feature = "ab_glyph")]
|
|
|
|
|
pub ab_glyph: ab_glyph::FontRef<'a>,
|
|
|
|
|
#[cfg(feature = "rusttype")]
|
|
|
|
|
pub rusttype: rusttype::Font<'a>,
|
2022-10-07 09:41:36 -06:00
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
pub swash: swash::FontRef<'a>,
|
2022-10-12 13:42:30 -06:00
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
pub scale_context: Mutex<swash::scale::ScaleContext>,
|
|
|
|
|
pub cache: Mutex<HashMap<CacheKey, CacheItem>>,
|
2022-10-05 09:16:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Font<'a> {
|
2022-10-12 17:35:23 -06:00
|
|
|
pub fn new(name: &'a str, data: &'a [u8], index: u32) -> Option<Self> {
|
2022-10-05 09:16:51 -06:00
|
|
|
Some(Self {
|
2022-10-12 17:35:23 -06:00
|
|
|
name,
|
2022-10-05 09:16:51 -06:00
|
|
|
data,
|
2022-10-12 17:35:23 -06:00
|
|
|
index,
|
2022-10-05 09:16:51 -06:00
|
|
|
rustybuzz: rustybuzz::Face::from_slice(data, index)?,
|
|
|
|
|
#[cfg(feature = "ab_glyph")]
|
|
|
|
|
ab_glyph: ab_glyph::FontRef::try_from_slice_and_index(data, index).ok()?,
|
|
|
|
|
#[cfg(feature = "rusttype")]
|
|
|
|
|
rusttype: rusttype::Font::try_from_bytes_and_index(data, index)?,
|
2022-10-07 09:41:36 -06:00
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
swash: swash::FontRef::from_index(data, index as usize)?,
|
2022-10-12 13:42:30 -06:00
|
|
|
#[cfg(feature = "swash")]
|
|
|
|
|
scale_context: Mutex::new(swash::scale::ScaleContext::new()),
|
|
|
|
|
cache: Mutex::new(HashMap::new()),
|
2022-10-05 09:16:51 -06:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|