diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-03 16:01:23 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-03 16:04:55 +0200 |
| commit | dbfb3d2ced91e56314dfabbb4df9a338926c0a7a (patch) | |
| tree | 678264cb18f8abc81ebe28077f5aef2df4e5a4bd /src/font.rs | |
| parent | 5a8f2fb73ddafba9fdbe952385ae2676126183ae (diff) | |
Formatting, documentation and small improvements 🧽
Diffstat (limited to 'src/font.rs')
| -rw-r--r-- | src/font.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/font.rs b/src/font.rs index 5d81b6fc..c37c913e 100644 --- a/src/font.rs +++ b/src/font.rs @@ -3,14 +3,15 @@ use std::cell::RefCell; use std::ops::Deref; use std::rc::Rc; + +use fontdock::{ContainsChar, FaceFromVec, FontLoader, FontProvider}; use ttf_parser::Face; -use fontdock::{FontLoader, FontProvider, ContainsChar, FaceFromVec}; /// A referenced-count shared font loader backed by a dynamic provider. pub type SharedFontLoader = Rc<RefCell<FontLoader<Box<DynProvider>>>>; /// The dynamic font provider type backing the font loader. -pub type DynProvider = dyn FontProvider<Face=OwnedFace>; +pub type DynProvider = dyn FontProvider<Face = OwnedFace>; /// An owned font face. pub struct OwnedFace { @@ -18,6 +19,13 @@ pub struct OwnedFace { face: Face<'static>, } +impl OwnedFace { + /// The raw face data. + pub fn data(&self) -> &[u8] { + &self.data + } +} + impl FaceFromVec for OwnedFace { fn from_vec(vec: Vec<u8>, i: u32) -> Option<Self> { // The vec's location is stable in memory since we don't touch it and @@ -26,20 +34,13 @@ impl FaceFromVec for OwnedFace { std::slice::from_raw_parts(vec.as_ptr(), vec.len()) }; - Some(OwnedFace { + Some(Self { data: vec, face: Face::from_slice(slice, i).ok()?, }) } } -impl OwnedFace { - /// The raw face data. - pub fn data(&self) -> &[u8] { - &self.data - } -} - impl ContainsChar for OwnedFace { fn contains_char(&self, c: char) -> bool { self.glyph_index(c).is_some() |
