Move font matching to Attrs

This commit is contained in:
Jeremy Soller 2022-10-25 15:51:28 -06:00
parent 324c8837fd
commit 085231c153
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
2 changed files with 17 additions and 15 deletions

View file

@ -45,4 +45,12 @@ impl<'a> Attrs<'a> {
self.weight = weight; self.weight = weight;
self self
} }
pub fn matches(&self, face: &fontdb::FaceInfo) -> bool {
face.style == self.style &&
face.weight == self.weight &&
face.stretch == self.stretch &&
//TODO: smarter way of including emoji
(face.monospaced == self.monospaced || face.post_script_name.contains("Emoji"))
}
} }

View file

@ -104,25 +104,19 @@ impl<'a> FontSystem<'a> {
} }
pub fn matches_attrs(&'a self, attrs: Attrs) -> Option<FontMatches<'_>> { pub fn matches_attrs(&'a self, attrs: Attrs) -> Option<FontMatches<'_>> {
self.matches(|info| { self.matches(|face| {
let matched = { let matched = attrs.matches(face);
info.style == attrs.style &&
info.weight == attrs.weight &&
info.stretch == attrs.stretch &&
//TODO: smarter way of including emoji
(info.monospaced == attrs.monospaced || info.post_script_name.contains("Emoji"))
};
if matched { if matched {
log::debug!( log::debug!(
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}", "{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
info.id, face.id,
info.family, face.family,
info.post_script_name, face.post_script_name,
info.style, face.style,
info.weight, face.weight,
info.stretch, face.stretch,
info.monospaced face.monospaced
); );
} }