Call get_font lazily

This commit is contained in:
Edgar Geier 2023-03-14 00:39:50 +01:00
parent f86acd325c
commit d297a6a48a
No known key found for this signature in database
GPG key ID: B022ECD3278A265C
5 changed files with 97 additions and 99 deletions

View file

@ -51,19 +51,15 @@ impl FontSystem {
get_font(&self.db, id)
}
pub fn get_font_matches(&mut self, attrs: Attrs) -> Arc<Vec<Arc<Font>>> {
let mut fonts = Vec::new();
for face in self.db.faces() {
if !attrs.matches(face) {
continue;
}
pub fn get_font_matches(&mut self, attrs: Attrs) -> Arc<Vec<fontdb::ID>> {
let ids = self
.db
.faces()
.filter(|face| attrs.matches(face))
.map(|face| face.id)
.collect::<Vec<_>>();
if let Some(font) = get_font(&self.db, face.id) {
fonts.push(font);
}
}
Arc::new(fonts)
Arc::new(ids)
}
}