From dbfb3d2ced91e56314dfabbb4df9a338926c0a7a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 3 Aug 2020 16:01:23 +0200 Subject: =?UTF-8?q?Formatting,=20documentation=20and=20small=20improvement?= =?UTF-8?q?s=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/font.rs') 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>>>; /// The dynamic font provider type backing the font loader. -pub type DynProvider = dyn FontProvider; +pub type DynProvider = dyn FontProvider; /// 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, i: u32) -> Option { // 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() -- cgit v1.2.3