From 085231c153ba60318f037b0d264aa17f086fe56c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 25 Oct 2022 15:51:28 -0600 Subject: [PATCH] Move font matching to Attrs --- src/attrs.rs | 8 ++++++++ src/font/system.rs | 24 +++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/attrs.rs b/src/attrs.rs index be012ad..1d66161 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -45,4 +45,12 @@ impl<'a> Attrs<'a> { self.weight = weight; 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")) + } } diff --git a/src/font/system.rs b/src/font/system.rs index b8aab78..ff2e652 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -104,25 +104,19 @@ impl<'a> FontSystem<'a> { } pub fn matches_attrs(&'a self, attrs: Attrs) -> Option> { - 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")) - }; + self.matches(|face| { + let matched = attrs.matches(face); 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 + face.id, + face.family, + face.post_script_name, + face.style, + face.weight, + face.stretch, + face.monospaced ); }