diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-25 11:16:03 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-25 11:16:03 +0200 |
| commit | 3309ff9fe5ea36134e8ddf11ac2c84613b569856 (patch) | |
| tree | b3eb48d444a5dee7273a76c548a64be96d76f0b9 /src/font.rs | |
| parent | 362a7f2a8ac76f944efa05eabcab0960817777c5 (diff) | |
Slim down context
Diffstat (limited to 'src/font.rs')
| -rw-r--r-- | src/font.rs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/font.rs b/src/font.rs index 9280ff8d..34ce6389 100644 --- a/src/font.rs +++ b/src/font.rs @@ -73,6 +73,32 @@ impl FontStore { } } + /// An ordered iterator over all font families this loader knows and details + /// about the faces that are part of them. + pub fn families( + &self, + ) -> impl Iterator<Item = (&str, impl Iterator<Item = &FaceInfo>)> + '_ { + // Since the keys are lowercased, we instead use the family field of the + // first face's info. + let faces = self.loader.faces(); + self.families.values().map(|ids| { + let family = faces[ids[0].0 as usize].family.as_str(); + let infos = ids.iter().map(|&id| &faces[id.0 as usize]); + (family, infos) + }) + } + + /// Get a reference to a loaded face. + /// + /// This panics if the face with this `id` was not loaded. This function + /// should only be called with ids returned by this store's + /// [`select()`](Self::select) and + /// [`select_fallback()`](Self::select_fallback) methods. + #[track_caller] + pub fn get(&self, id: FaceId) -> &Face { + self.faces[id.0 as usize].as_ref().expect("font face was not loaded") + } + /// Try to find and load a font face from the given `family` that matches /// the given `variant` as closely as possible. pub fn select(&mut self, family: &str, variant: FontVariant) -> Option<FaceId> { @@ -200,32 +226,6 @@ impl FontStore { Some(id) } - - /// Get a reference to a loaded face. - /// - /// This panics if the face with this `id` was not loaded. This function - /// should only be called with ids returned by this store's - /// [`select()`](Self::select) and - /// [`select_fallback()`](Self::select_fallback) methods. - #[track_caller] - pub fn get(&self, id: FaceId) -> &Face { - self.faces[id.0 as usize].as_ref().expect("font face was not loaded") - } - - /// An ordered iterator over all font families this loader knows and details - /// about the faces that are part of them. - pub fn families( - &self, - ) -> impl Iterator<Item = (&str, impl Iterator<Item = &FaceInfo>)> + '_ { - // Since the keys are lowercased, we instead use the family field of the - // first face's info. - let faces = self.loader.faces(); - self.families.values().map(|ids| { - let family = faces[ids[0].0 as usize].family.as_str(); - let infos = ids.iter().map(|&id| &faces[id.0 as usize]); - (family, infos) - }) - } } /// How many words the two strings share in their prefix. |
