Add layout run iterator

This commit is contained in:
Jeremy Soller 2022-10-25 12:52:46 -06:00
parent 5d7dd59078
commit a9b7b4e914
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
8 changed files with 135 additions and 97 deletions

View file

@ -9,7 +9,7 @@ pub use swash::scale::image::Image as SwashImage;
pub struct SwashCache {
context: ScaleContext,
cache: HashMap<CacheKey, Option<SwashImage>>,
pub image_cache: HashMap<CacheKey, Option<SwashImage>>,
}
impl SwashCache {
@ -17,13 +17,13 @@ impl SwashCache {
pub fn new() -> Self {
Self {
context: ScaleContext::new(),
cache: HashMap::new()
image_cache: HashMap::new()
}
}
/// Create a swash Image from a cache key, caching results
pub fn get_image(&mut self, matches: &FontMatches<'_>, cache_key: CacheKey) -> &Option<SwashImage> {
self.cache.entry(cache_key).or_insert_with(|| {
self.image_cache.entry(cache_key).or_insert_with(|| {
let font = match matches.get_font(&cache_key.font_id) {
Some(some) => some,
None => {