Embed Fira Sans font on Wasm builds by default

This commit is contained in:
Héctor Ramón Jiménez 2024-02-20 03:20:58 +01:00
parent 0c7f4eaab5
commit 35e2049ee6
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 18 additions and 1 deletions

View file

@ -18,7 +18,7 @@ all-features = true
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[features] [features]
default = ["wgpu"] default = ["wgpu", "fira-sans"]
# Enable the `wgpu` GPU-accelerated renderer backend # Enable the `wgpu` GPU-accelerated renderer backend
wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"] wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"]
# Enables the `Image` widget # Enables the `Image` widget
@ -53,6 +53,8 @@ highlighter = ["iced_highlighter"]
multi-window = ["iced_winit/multi-window"] multi-window = ["iced_winit/multi-window"]
# Enables the advanced module # Enables the advanced module
advanced = [] advanced = []
# Enables embedding Fira Sans as the default font on Wasm builds
fira-sans = ["iced_renderer/fira-sans"]
[dependencies] [dependencies]
iced_core.workspace = true iced_core.workspace = true

View file

@ -18,6 +18,7 @@ all-features = true
geometry = ["lyon_path"] geometry = ["lyon_path"]
image = ["dep:image", "kamadak-exif"] image = ["dep:image", "kamadak-exif"]
web-colors = [] web-colors = []
fira-sans = []
[dependencies] [dependencies]
iced_core.workspace = true iced_core.workspace = true

Binary file not shown.

View file

@ -17,6 +17,15 @@ use once_cell::sync::OnceCell;
use std::borrow::Cow; use std::borrow::Cow;
use std::sync::{Arc, RwLock, Weak}; use std::sync::{Arc, RwLock, Weak};
/// The regular variant of the [Fira Sans] font.
///
/// It is loaded as part of the default fonts in Wasm builds.
///
/// [Fira Sans]: https://mozilla.github.io/Fira/
#[cfg(all(target_arch = "wasm32", feature = "fira-sans"))]
pub const FIRA_SANS_REGULAR: &'static [u8] =
include_bytes!("../fonts/FiraSans-Regular.ttf").as_slice();
/// Returns the global [`FontSystem`]. /// Returns the global [`FontSystem`].
pub fn font_system() -> &'static RwLock<FontSystem> { pub fn font_system() -> &'static RwLock<FontSystem> {
static FONT_SYSTEM: OnceCell<RwLock<FontSystem>> = OnceCell::new(); static FONT_SYSTEM: OnceCell<RwLock<FontSystem>> = OnceCell::new();
@ -27,6 +36,10 @@ pub fn font_system() -> &'static RwLock<FontSystem> {
cosmic_text::fontdb::Source::Binary(Arc::new( cosmic_text::fontdb::Source::Binary(Arc::new(
include_bytes!("../fonts/Iced-Icons.ttf").as_slice(), include_bytes!("../fonts/Iced-Icons.ttf").as_slice(),
)), )),
#[cfg(all(target_arch = "wasm32", feature = "fira-sans"))]
cosmic_text::fontdb::Source::Binary(Arc::new(
include_bytes!("../fonts/FiraSans-Regular.ttf").as_slice(),
)),
]), ]),
version: Version::default(), version: Version::default(),
}) })

View file

@ -18,6 +18,7 @@ geometry = ["iced_graphics/geometry", "iced_tiny_skia/geometry", "iced_wgpu?/geo
tracing = ["iced_wgpu?/tracing"] tracing = ["iced_wgpu?/tracing"]
web-colors = ["iced_wgpu?/web-colors"] web-colors = ["iced_wgpu?/web-colors"]
webgl = ["iced_wgpu?/webgl"] webgl = ["iced_wgpu?/webgl"]
fira-sans = ["iced_graphics/fira-sans"]
[dependencies] [dependencies]
iced_graphics.workspace = true iced_graphics.workspace = true