fix(app): preload embedded Fira fonts
This commit is contained in:
parent
73f0596650
commit
173a9557c2
2 changed files with 26 additions and 8 deletions
|
|
@ -45,6 +45,8 @@ pub mod message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub use self::command::Command;
|
pub use self::command::Command;
|
||||||
pub use self::core::Core;
|
pub use self::core::Core;
|
||||||
pub use self::settings::Settings;
|
pub use self::settings::Settings;
|
||||||
|
|
@ -72,6 +74,8 @@ pub(crate) fn iced_settings<App: Application>(
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
flags: App::Flags,
|
flags: App::Flags,
|
||||||
) -> iced::Settings<(Core, App::Flags)> {
|
) -> iced::Settings<(Core, App::Flags)> {
|
||||||
|
preload_fonts();
|
||||||
|
|
||||||
let mut core = Core::default();
|
let mut core = Core::default();
|
||||||
core.debug = settings.debug;
|
core.debug = settings.debug;
|
||||||
core.icon_theme_override = settings.default_icon_theme.is_some();
|
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)));
|
||||||
|
}
|
||||||
|
|
|
||||||
12
src/font.rs
12
src/font.rs
|
|
@ -4,11 +4,7 @@
|
||||||
//! Select preferred fonts.
|
//! Select preferred fonts.
|
||||||
|
|
||||||
pub use iced::Font;
|
pub use iced::Font;
|
||||||
use iced::{
|
use iced_core::font::{Family, Weight};
|
||||||
font::{load, Error},
|
|
||||||
Command,
|
|
||||||
};
|
|
||||||
use iced_core::font::Family;
|
|
||||||
|
|
||||||
pub fn default() -> Font {
|
pub fn default() -> Font {
|
||||||
Font::from(crate::config::interface_font())
|
Font::from(crate::config::interface_font())
|
||||||
|
|
@ -16,21 +12,21 @@ pub fn default() -> Font {
|
||||||
|
|
||||||
pub fn light() -> Font {
|
pub fn light() -> Font {
|
||||||
Font {
|
Font {
|
||||||
weight: iced_core::font::Weight::Light,
|
weight: Weight::Light,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn semibold() -> Font {
|
pub fn semibold() -> Font {
|
||||||
Font {
|
Font {
|
||||||
weight: iced_core::font::Weight::Semibold,
|
weight: Weight::Semibold,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bold() -> Font {
|
pub fn bold() -> Font {
|
||||||
Font {
|
Font {
|
||||||
weight: iced_core::font::Weight::Bold,
|
weight: Weight::Bold,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue