From d4743183d40c6044ce6fa39e2a52919a32912cda Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 14:23:28 +0200 Subject: Draft first working version of `iced_glow` :tada: --- glow/src/text/font.rs | 37 +++++++++++++++++++++++++++++++++++++ glow/src/text/icons.ttf | Bin 0 -> 4912 bytes 2 files changed, 37 insertions(+) create mode 100644 glow/src/text/font.rs create mode 100644 glow/src/text/icons.ttf (limited to 'glow/src/text') diff --git a/glow/src/text/font.rs b/glow/src/text/font.rs new file mode 100644 index 00000000..7346ccdb --- /dev/null +++ b/glow/src/text/font.rs @@ -0,0 +1,37 @@ +pub use font_kit::{ + error::SelectionError as LoadError, 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, 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()) + } + } + } +} diff --git a/glow/src/text/icons.ttf b/glow/src/text/icons.ttf new file mode 100644 index 00000000..1c832f86 Binary files /dev/null and b/glow/src/text/icons.ttf differ -- cgit