diff options
author | 2019-11-14 06:47:43 +0100 | |
---|---|---|
committer | 2019-11-14 06:47:43 +0100 | |
commit | a16dab9cf2e27cb933cc91383ca79ba8e188c4c2 (patch) | |
tree | db844c70cc8fbd2f48b175e97bde50866641a1b4 /wgpu/src/text | |
parent | bc8d347736ec997ec0e0c401289e2bc09e212b8a (diff) | |
parent | 6857829dc3171fd68065498b6cd29f0ef02a8d43 (diff) | |
download | iced-a16dab9cf2e27cb933cc91383ca79ba8e188c4c2.tar.gz iced-a16dab9cf2e27cb933cc91383ca79ba8e188c4c2.tar.bz2 iced-a16dab9cf2e27cb933cc91383ca79ba8e188c4c2.zip |
Merge pull request #54 from hecrj/feature/external-fonts
Custom font support
Diffstat (limited to 'wgpu/src/text')
-rw-r--r-- | wgpu/src/text/font.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/wgpu/src/text/font.rs b/wgpu/src/text/font.rs new file mode 100644 index 00000000..31df5bf4 --- /dev/null +++ b/wgpu/src/text/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()) + } + } + } +} |