From 655de0af5f6c33e4b69c39436463e4d72d278935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 4 Feb 2023 11:30:41 +0100 Subject: [PATCH] Implement `FontSystem::new_with_fonts` helper This helper is useful to initialize a `FontSystem` with some embedded fonts, for instance. --- src/font/system/std.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/font/system/std.rs b/src/font/system/std.rs index 3efe7eb..8d71d5b 100644 --- a/src/font/system/std.rs +++ b/src/font/system/std.rs @@ -25,6 +25,10 @@ pub struct FontSystem(FontSystemInner); impl FontSystem { /// Create a new [`FontSystem`], that allows access to any installed system fonts pub fn new() -> Self { + Self::new_with_fonts(std::iter::empty()) + } + + pub fn new_with_fonts(fonts: impl Iterator) -> Self { let locale = sys_locale::get_locale().unwrap_or_else(|| { log::warn!("failed to get system locale, falling back to en-US"); String::from("en-US") @@ -37,6 +41,11 @@ impl FontSystem { let now = std::time::Instant::now(); db.load_system_fonts(); + + for source in fonts { + db.load_font_source(source); + } + //TODO: configurable default fonts db.set_monospace_family("Fira Mono"); db.set_sans_serif_family("Fira Sans");