diff options
author | 2019-11-05 21:46:37 +0100 | |
---|---|---|
committer | 2019-11-05 21:46:37 +0100 | |
commit | ae6156f779c24beaabf43ea6110d3ce38e34a998 (patch) | |
tree | 9545408530437eb780ac73c600f7d40968803786 /wgpu/src/font.rs | |
parent | da2717c74dbe3e1123ff41de345a409c1afc2f18 (diff) | |
parent | 0157121038987feb6c2ea3066a21ce25e689888e (diff) | |
download | iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.tar.gz iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.tar.bz2 iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.zip |
Merge pull request #38 from hecrj/feature/performance-metrics
Debug view
Diffstat (limited to 'wgpu/src/font.rs')
-rw-r--r-- | wgpu/src/font.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/wgpu/src/font.rs b/wgpu/src/font.rs new file mode 100644 index 00000000..31df5bf4 --- /dev/null +++ b/wgpu/src/font.rs @@ -0,0 +1,36 @@ +pub use font_kit::error::SelectionError as LoadError; +pub use font_kit::family_name::FamilyName as Family; + +pub struct Source { + raw: font_kit::source::SystemSource, +} + +impl Source { + pub fn new() -> Self { + Source { + raw: font_kit::source::SystemSource::new(), + } + } + + 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, .. } => { + use std::io::Read; + + let mut buf = Vec::new(); + let mut reader = std::fs::File::open(path).expect("Read font"); + let _ = reader.read_to_end(&mut buf); + + Ok(buf) + } + font_kit::handle::Handle::Memory { bytes, .. } => { + Ok(bytes.as_ref().clone()) + } + } + } +} |