diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-10 10:03:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-10 10:03:39 +0100 |
| commit | ed1197a3db0f8e9df4e76ddaa2ab27242053faee (patch) | |
| tree | 6e34b3e871239263d6151fdddffcc4809b753e44 /src/font.rs | |
| parent | 642e149464341e3cf1856dda51d7f7a5b387081e (diff) | |
Don't try to reload faces over and over
Diffstat (limited to 'src/font.rs')
| -rw-r--r-- | src/font.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/font.rs b/src/font.rs index 45cc6be2..d8fc0f45 100644 --- a/src/font.rs +++ b/src/font.rs @@ -34,6 +34,7 @@ impl FaceId { /// Storage for loaded and parsed font faces. pub struct FontStore { loader: Arc<dyn Loader>, + failed: Vec<bool>, faces: Vec<Option<Face>>, families: BTreeMap<String, Vec<FaceId>>, buffers: HashMap<FileHash, Arc<Vec<u8>>>, @@ -43,17 +44,20 @@ impl FontStore { /// Create a new, empty font store. pub fn new(loader: Arc<dyn Loader>) -> Self { let mut faces = vec![]; + let mut failed = vec![]; let mut families = BTreeMap::<String, Vec<FaceId>>::new(); for (i, info) in loader.faces().iter().enumerate() { let id = FaceId(i as u32); faces.push(None); + failed.push(false); families.entry(info.family.to_lowercase()).or_default().push(id); } Self { loader, faces, + failed, families, buffers: HashMap::new(), } @@ -95,12 +99,16 @@ impl FontStore { } let id = best?; - - // Load the face if it's not already loaded. let idx = id.0 as usize; let slot = &mut self.faces[idx]; + if self.failed[idx] { + return None; + } + + // Load the face if it's not already loaded. if slot.is_none() { let FaceInfo { ref path, index, .. } = infos[idx]; + self.failed[idx] = true; // Check the buffer cache since multiple faces may // refer to the same data (font collection). @@ -115,6 +123,7 @@ impl FontStore { let face = Face::new(Arc::clone(buffer), index)?; *slot = Some(face); + self.failed[idx] = false; } Some(id) |
