fix(app): preload embedded Fira fonts

This commit is contained in:
Michael Aaron Murphy 2024-10-05 01:41:32 +02:00 committed by Michael Murphy
parent 73f0596650
commit 173a9557c2
2 changed files with 26 additions and 8 deletions

View file

@ -45,6 +45,8 @@ pub mod message {
}
}
use std::borrow::Cow;
pub use self::command::Command;
pub use self::core::Core;
pub use self::settings::Settings;
@ -72,6 +74,8 @@ pub(crate) fn iced_settings<App: Application>(
settings: Settings,
flags: App::Flags,
) -> iced::Settings<(Core, App::Flags)> {
preload_fonts();
let mut core = Core::default();
core.debug = settings.debug;
core.icon_theme_override = settings.default_icon_theme.is_some();
@ -882,3 +886,21 @@ fn single_instance_subscription<App: ApplicationExt>() -> Subscription<Message<A
},
)
}
const EMBEDDED_FONTS: &[&[u8]] = &[
include_bytes!("../../res/Fira/FiraSans-Light.otf"),
include_bytes!("../../res/Fira/FiraSans-Regular.otf"),
include_bytes!("../../res/Fira/FiraSans-SemiBold.otf"),
include_bytes!("../../res/Fira/FiraSans-Bold.otf"),
include_bytes!("../../res/Fira/FiraMono-Regular.otf"),
];
fn preload_fonts() {
let mut font_system = iced::advanced::graphics::text::font_system()
.write()
.unwrap();
EMBEDDED_FONTS
.into_iter()
.for_each(move |font| font_system.load_font(Cow::Borrowed(font)));
}

View file

@ -4,11 +4,7 @@
//! Select preferred fonts.
pub use iced::Font;
use iced::{
font::{load, Error},
Command,
};
use iced_core::font::Family;
use iced_core::font::{Family, Weight};
pub fn default() -> Font {
Font::from(crate::config::interface_font())
@ -16,21 +12,21 @@ pub fn default() -> Font {
pub fn light() -> Font {
Font {
weight: iced_core::font::Weight::Light,
weight: Weight::Light,
..default()
}
}
pub fn semibold() -> Font {
Font {
weight: iced_core::font::Weight::Semibold,
weight: Weight::Semibold,
..default()
}
}
pub fn bold() -> Font {
Font {
weight: iced_core::font::Weight::Bold,
weight: Weight::Bold,
..default()
}
}