From ae9521e500d97c9495003a727b6fd931671dda8b Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Sat, 30 May 2020 19:23:16 +1200 Subject: [PATCH 1/2] Feature gate `font-kit` behind `"default_system_font"` feature. --- Cargo.toml | 6 +++++- glow/Cargo.toml | 3 ++- glow/src/text.rs | 17 +++++++++++------ wgpu/Cargo.toml | 3 ++- wgpu/src/text.rs | 17 +++++++++++------ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4dd7d1e87a..9ab57bc818 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] [features] -default = ["wgpu"] +default = ["wgpu", "default_system_font"] # Enables the `iced_wgpu` renderer wgpu = ["iced_wgpu"] # Enables the `Image` widget @@ -21,10 +21,14 @@ image = ["iced_wgpu/image"] svg = ["iced_wgpu/svg"] # Enables the `Canvas` widget canvas = ["iced_wgpu/canvas"] +# Enables using system fonts. +default_system_font = ["iced_wgpu/default_system_font"] # Enables the `iced_glow` renderer. Overrides `iced_wgpu` glow = ["iced_glow", "iced_glutin"] # Enables the `Canvas` widget for `iced_glow` glow_canvas = ["iced_glow/canvas"] +# Enables using system fonts for `iced_glow`. +glow_default_system_font = ["iced_glow/default_system_font"] # Enables a debug view in native platforms (press F12) debug = ["iced_winit/debug"] # Enables `tokio` as the `executor::Default` on native platforms diff --git a/glow/Cargo.toml b/glow/Cargo.toml index 262f026430..baf2eb2f0a 100644 --- a/glow/Cargo.toml +++ b/glow/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/hecrj/iced" [features] canvas = ["iced_graphics/canvas"] +default_system_font = ["iced_graphics/font-source"] # Not supported yet! image = [] svg = [] @@ -29,7 +30,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.1" path = "../graphics" -features = ["font-source", "font-fallback", "font-icons", "opengl"] +features = ["font-fallback", "font-icons", "opengl"] [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] diff --git a/glow/src/text.rs b/glow/src/text.rs index 6dc7882c88..925c728784 100644 --- a/glow/src/text.rs +++ b/glow/src/text.rs @@ -12,15 +12,20 @@ pub struct Pipeline { impl Pipeline { pub fn new(gl: &glow::Context, default_font: Option<&[u8]>) -> Self { + let default_font = default_font.map(|slice| slice.to_vec()); + // TODO: Font customization - let font_source = font::Source::new(); + #[cfg(feature = "default_system_font")] + let default_font = { + default_font.or_else(|| { + font::Source::new() + .load(&[font::Family::SansSerif, font::Family::Serif]) + .ok() + }) + }; let default_font = - default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| { - font_source - .load(&[font::Family::SansSerif, font::Family::Serif]) - .unwrap_or_else(|_| font::FALLBACK.to_vec()) - }); + default_font.unwrap_or_else(|| font::FALLBACK.to_vec()); let font = ab_glyph::FontArc::try_from_vec(default_font) .unwrap_or_else(|_| { diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 3bbc57a01f..db3104c438 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/hecrj/iced" [features] svg = ["resvg"] canvas = ["iced_graphics/canvas"] +default_system_font = ["iced_graphics/font-source"] [dependencies] wgpu = "0.5" @@ -32,7 +33,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.1" path = "../graphics" -features = ["font-source", "font-fallback", "font-icons"] +features = ["font-fallback", "font-icons"] [dependencies.image] version = "0.23" diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 5ee7b856ed..a7123d39c0 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -16,15 +16,20 @@ impl Pipeline { format: wgpu::TextureFormat, default_font: Option<&[u8]>, ) -> Self { + let default_font = default_font.map(|slice| slice.to_vec()); + // TODO: Font customization - let font_source = font::Source::new(); + #[cfg(feature = "default_system_font")] + let default_font = { + default_font.or_else(|| { + font::Source::new() + .load(&[font::Family::SansSerif, font::Family::Serif]) + .ok() + }) + }; let default_font = - default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| { - font_source - .load(&[font::Family::SansSerif, font::Family::Serif]) - .unwrap_or_else(|_| font::FALLBACK.to_vec()) - }); + default_font.unwrap_or_else(|| font::FALLBACK.to_vec()); let font = ab_glyph::FontArc::try_from_vec(default_font) .unwrap_or_else(|_| { From 86f0e3d4e244710eb925c8603368d191aa7daff7 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Sat, 30 May 2020 19:23:55 +1200 Subject: [PATCH 2/2] Update `CHANGELOG.md`. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59471abcde..ee650337d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `"system_font"` feature gates reading system fonts. [#370] + +[#370]: https://github.com/hecrj/iced/pull/370 ## [0.1.1] - 2020-04-15 ### Added