pub mod prelude;
mod util;
mod builder;
pub mod context;
mod fallback;
mod family;
mod index;
mod index_data;
mod library;
mod shared_data;
mod system;
mod types;
pub(crate) mod internal {
pub use super::context::{FontContext, FontGroupId};
}
use std::sync::{Arc, OnceLock};
pub use builder::{FontLibraryBuilder, MmapHint};
pub use context::{FontCache, FontContext};
pub use family::{parse_families, FamilyList};
pub use index::{FamilyEntry, FontEntry, SourceEntry, StaticIndex as FontIndex};
pub use index_data::SourceKind;
pub use library::FontLibrary;
pub use shared_data::SharedData;
pub use types::{FamilyId, FamilyKey, FontId, FontKey, GenericFamily, SourceId};
use swash::{CacheKey, iter::*, *};
#[derive(Clone)]
pub struct Font {
data: shared_data::SharedData,
offset: u32,
attributes: Attributes,
key: CacheKey,
}
impl Font {
pub fn attributes(&self) -> Attributes {
self.as_ref().attributes()
}
pub fn requested_attributes(&self) -> Attributes {
self.attributes
}
pub fn localized_strings(&self) -> LocalizedStrings {
self.as_ref().localized_strings()
}
pub fn variations(&self) -> Variations {
self.as_ref().variations()
}
pub fn instances(&self) -> Instances {
self.as_ref().instances()
}
pub fn writing_systems(&self) -> WritingSystems {
self.as_ref().writing_systems()
}
pub fn features(&self) -> Features {
self.as_ref().features()
}
pub fn metrics(&self, coords: &[NormalizedCoord]) -> Metrics {
self.as_ref().metrics(coords)
}
pub fn glyph_metrics<'a>(&'a self, coords: &'a [NormalizedCoord]) -> GlyphMetrics<'a> {
self.as_ref().glyph_metrics(coords)
}
pub fn charmap(&self) -> Charmap {
self.as_ref().charmap()
}
pub fn color_palettes(&self) -> ColorPalettes {
self.as_ref().color_palettes()
}
pub fn alpha_strikes(&self) -> BitmapStrikes {
self.as_ref().alpha_strikes()
}
pub fn color_strikes(&self) -> BitmapStrikes {
self.as_ref().color_strikes()
}
pub fn cache_key(&self) -> CacheKey {
self.key
}
pub fn as_ref<'a>(&'a self) -> FontRef<'a> {
FontRef {
data: self.data.as_bytes(),
offset: self.offset,
key: self.key,
}
}
}
impl PartialEq for Font {
fn eq(&self, other: &Self) -> bool {
self.key == other.key
}
}
impl Eq for Font {}
impl<'a> From<&'a Font> for FontRef<'a> {
fn from(f: &'a Font) -> FontRef<'a> {
f.as_ref()
}
}
static FONT_LIBRARY: OnceLock<FontLibrary> = OnceLock::new();
impl FontIndex {
pub fn global() -> Arc<FontIndex> {
let library = FONT_LIBRARY.get_or_init(|| FontLibrary::default());
library.inner.index.read().unwrap().clone()
}
}