use crate::display_list::DisplayElement;
use crate::graphics_state::PathSegment;
use crate::object::{EntityId, NameId};
use rustc_hash::FxHashMap;
use std::sync::Arc;
#[derive(Clone)]
pub struct CachedGlyph {
pub segments: Arc<Vec<PathSegment>>,
pub width_x: f64,
pub width_y: f64,
}
#[derive(Clone)]
pub struct CachedType3Glyph {
pub elements: Vec<DisplayElement>,
pub origin_dev_x: f64,
pub origin_dev_y: f64,
pub width: (f64, f64),
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Type3CacheMode {
Cache,
NoCache,
}
#[derive(Default)]
pub struct GlyphCache {
pub by_name: FxHashMap<NameId, CachedGlyph>,
pub by_cid: FxHashMap<i32, CachedGlyph>,
pub by_gid: FxHashMap<u16, CachedGlyph>,
pub by_charcode: FxHashMap<u8, CachedType3Glyph>,
pub by_type3_name: FxHashMap<NameId, CachedType3Glyph>,
}
impl GlyphCache {
pub fn new() -> Self {
Self {
by_name: FxHashMap::default(),
by_cid: FxHashMap::default(),
by_gid: FxHashMap::default(),
by_charcode: FxHashMap::default(),
by_type3_name: FxHashMap::default(),
}
}
}
#[inline]
pub fn get_or_create_cache(
caches: &mut FxHashMap<EntityId, GlyphCache>,
font_entity: EntityId,
) -> &mut GlyphCache {
caches.entry(font_entity).or_default()
}