Only use relevant info from Attrs as a key in font_matches_cache

`Attrs` contains info like color and metadata which are not relevant
 to font matching.

 So, add a new struct `FontMatchAttrs` which only contains the relevant
 info, and use it as a key in `FontSystem`'s `font_matches_cache`.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-01-24 08:42:10 +03:00 committed by Jeremy Soller
parent 235ec02a20
commit e0ae465f91
2 changed files with 23 additions and 3 deletions

View file

@ -191,6 +191,26 @@ impl<'a> Attrs<'a> {
}
}
/// Font-specific part of [`Attrs`] to be used for matching
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct FontMatchAttrs {
family: FamilyOwned,
stretch: Stretch,
style: Style,
weight: Weight,
}
impl<'a> From<Attrs<'a>> for FontMatchAttrs {
fn from(attrs: Attrs<'a>) -> Self {
Self {
family: FamilyOwned::new(attrs.family),
stretch: attrs.stretch,
style: attrs.style,
weight: attrs.weight,
}
}
}
/// An owned version of [`Attrs`]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct AttrsOwned {