From 6b3f6cb95ee3e839aecb1cb19169ea8e5ab143d4 Mon Sep 17 00:00:00 2001 From: Joshix-1 <57299889+Joshix-1@users.noreply.github.com> Date: Wed, 2 Jul 2025 18:32:01 +0200 Subject: [PATCH] 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. --- src/font/system.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/font/system.rs b/src/font/system.rs index d3a91d9..1930f47 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -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();