Fix #386 do not ignore font family (#399)

Font family know gets used when querying the font.
Not sure if this solution is good, if the old code is even needed.
This works for me, which makes it good enough for me.
This commit is contained in:
Joshix-1 2025-07-02 18:32:01 +02:00 committed by GitHub
parent f9e43cf355
commit 6b3f6cb95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ use alloc::sync::Arc;
use alloc::vec::Vec;
use core::fmt;
use core::ops::{Deref, DerefMut};
use fontdb::Query;
// re-export fontdb and rustybuzz
pub use fontdb;
@ -334,6 +335,37 @@ impl FontSystem {
// Sort so we get the keys with weight_offset=0 first
font_match_keys.sort();
// db.query is better than above, but returns just one font
let query = Query {
families: &[attrs.family],
weight: attrs.weight,
stretch: attrs.stretch,
style: attrs.style,
};
if let Some(id) = self.db.query(&query) {
if let Some(i) = font_match_keys
.iter()
.enumerate()
.find(|(_i, key)| key.id == id)
.map(|(i, _)| i)
{
// if exists move to front
let match_key = font_match_keys.remove(i);
font_match_keys.insert(0, match_key);
} else if let Some(face) = self.db.face(id) {
// else insert in front
let match_key = FontMatchKey {
font_weight_diff: attrs.weight.0.abs_diff(face.weight.0),
font_weight: face.weight.0,
id,
};
font_match_keys.insert(0, match_key);
} else {
log::error!("Could not get face from db, that should've been there.");
}
}
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
{
let elapsed = now.elapsed();