Lazily call make_shared_face_data

This commit is contained in:
Edgar Geier 2023-03-13 11:15:36 +01:00
parent af4378d753
commit f86acd325c
No known key found for this signature in database
GPG key ID: B022ECD3278A265C

View file

@ -62,26 +62,7 @@ impl FontSystem {
}
/// Create a new [`FontSystem`], manually specifying the current locale and font database.
pub fn new_with_locale_and_db(locale: String, mut db: fontdb::Database) -> Self {
{
#[cfg(not(target_arch = "wasm32"))]
let now = std::time::Instant::now();
//TODO only do this on demand!
for id in db.faces().map(|face| face.id).collect::<Vec<_>>() {
unsafe {
db.make_shared_face_data(id);
}
}
#[cfg(not(target_arch = "wasm32"))]
log::info!(
"Mapped {} font faces in {}ms.",
db.len(),
now.elapsed().as_millis()
);
}
pub fn new_with_locale_and_db(locale: String, db: fontdb::Database) -> Self {
Self {
locale,
db,
@ -150,6 +131,9 @@ fn get_font(
font_cache
.entry(id)
.or_insert_with(|| {
unsafe {
db.make_shared_face_data(id);
}
let face = db.face(id)?;
match Font::new(face) {
Some(font) => Some(Arc::new(font)),