Add text attributes

This commit is contained in:
Jeremy Soller 2022-10-25 14:14:23 -06:00
parent bc04887b35
commit 84f4381cdf
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
6 changed files with 83 additions and 88 deletions

View file

@ -2,7 +2,7 @@
use std::ops::Deref;
use super::{Font, FontMatches};
use crate::{Attrs, Font, FontMatches};
/// Access system fonts
pub struct FontSystem {
@ -81,6 +81,33 @@ impl FontSystem {
None
}
}
pub fn matches_attrs(&self, attrs: Attrs) -> Option<FontMatches<'_>> {
self.matches(|info| {
let matched = {
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 {
log::debug!(
"{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}",
info.id,
info.family,
info.post_script_name,
info.style,
info.weight,
info.stretch,
info.monospaced
);
}
matched
})
}
}
impl Default for FontSystem {