Add caching of swash rendering, significantly improves layout speed
This commit is contained in:
parent
0b5050e601
commit
a4959bbe7b
5 changed files with 243 additions and 92 deletions
|
|
@ -1,3 +1,11 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
pub use self::cache::*;
|
||||
mod cache;
|
||||
|
||||
pub use self::layout::*;
|
||||
mod layout;
|
||||
|
||||
|
|
@ -10,6 +18,12 @@ mod shape;
|
|||
pub use self::system::*;
|
||||
mod system;
|
||||
|
||||
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct FontCacheKey {
|
||||
glyph_id: u16,
|
||||
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct FontLineIndex(usize);
|
||||
|
||||
|
|
@ -32,6 +46,9 @@ pub struct Font<'a> {
|
|||
pub rusttype: rusttype::Font<'a>,
|
||||
#[cfg(feature = "swash")]
|
||||
pub swash: swash::FontRef<'a>,
|
||||
#[cfg(feature = "swash")]
|
||||
pub scale_context: Mutex<swash::scale::ScaleContext>,
|
||||
pub cache: Mutex<HashMap<CacheKey, CacheItem>>,
|
||||
}
|
||||
|
||||
impl<'a> Font<'a> {
|
||||
|
|
@ -45,6 +62,9 @@ impl<'a> Font<'a> {
|
|||
rusttype: rusttype::Font::try_from_bytes_and_index(data, index)?,
|
||||
#[cfg(feature = "swash")]
|
||||
swash: swash::FontRef::from_index(data, index as usize)?,
|
||||
#[cfg(feature = "swash")]
|
||||
scale_context: Mutex::new(swash::scale::ScaleContext::new()),
|
||||
cache: Mutex::new(HashMap::new()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue