linux: fix wrong font selection

With the switch to font-kit for finding the best matching font we
started to actually use the result of `load_font`, which, as it
turns out, had a bug all along :)

The problem was that `FontSystem::get_font_matches` *ignores* the
family of the passed in attribute set, so the returned candidate
set always always contained *all* fonts. This lead to a seemingly
random font being selected.

Signed-off-by: Niklas Wimmer <mail@nwimmer.me>
This commit is contained in:
Niklas Wimmer 2024-03-20 16:16:41 +01:00
parent d5e0817fbc
commit 5003504031
No known key found for this signature in database
GPG Key ID: 021F630DD880CAF6

View File

@ -217,11 +217,17 @@ impl LinuxTextSystemState {
_features: FontFeatures,
) -> Result<SmallVec<[FontId; 4]>> {
let mut font_ids = SmallVec::new();
let family = self
.font_system
.get_font_matches(Attrs::new().family(cosmic_text::Family::Name(name)));
for font in family.as_ref() {
let font = self.font_system.get_font(*font).unwrap();
.db()
.faces()
.filter(|face| face.families.iter().any(|family| *name == family.0))
.map(|face| face.id)
.collect::<SmallVec<[_; 4]>>();
for font in family {
let font = self.font_system.get_font(font).unwrap();
if font.as_swash().charmap().map('m') == 0 {
self.font_system.db_mut().remove_face(font.id());
continue;