diff options
author | 2019-11-05 03:57:13 +0100 | |
---|---|---|
committer | 2019-11-05 03:57:13 +0100 | |
commit | 0157121038987feb6c2ea3066a21ce25e689888e (patch) | |
tree | 9545408530437eb780ac73c600f7d40968803786 /wgpu/src/font.rs | |
parent | 40e9a2f6ae8a9d8576531c79fb57bc53fe5a0acf (diff) | |
download | iced-0157121038987feb6c2ea3066a21ce25e689888e.tar.gz iced-0157121038987feb6c2ea3066a21ce25e689888e.tar.bz2 iced-0157121038987feb6c2ea3066a21ce25e689888e.zip |
Improve default font loading
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/font.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/wgpu/src/font.rs b/wgpu/src/font.rs index 9bba9b22..31df5bf4 100644 --- a/wgpu/src/font.rs +++ b/wgpu/src/font.rs @@ -1,3 +1,4 @@ +pub use font_kit::error::SelectionError as LoadError; pub use font_kit::family_name::FamilyName as Family; pub struct Source { @@ -11,14 +12,11 @@ impl Source { } } - pub fn load(&self, families: &[Family]) -> Vec<u8> { - let font = self - .raw - .select_best_match( - families, - &font_kit::properties::Properties::default(), - ) - .expect("Find font"); + pub fn load(&self, families: &[Family]) -> Result<Vec<u8>, LoadError> { + let font = self.raw.select_best_match( + families, + &font_kit::properties::Properties::default(), + )?; match font { font_kit::handle::Handle::Path { path, .. } => { @@ -28,10 +26,10 @@ impl Source { let mut reader = std::fs::File::open(path).expect("Read font"); let _ = reader.read_to_end(&mut buf); - buf + Ok(buf) } font_kit::handle::Handle::Memory { bytes, .. } => { - bytes.as_ref().clone() + Ok(bytes.as_ref().clone()) } } } |