Replies: 6 comments 15 replies
-
Automatically loading the system font (at least as a falback for non latin characters) would be a very nice feature of eframe. Feel free to work on it! |
Beta Was this translation helpful? Give feedback.
-
Load system font let font = std::fs::read("c:/Windows/Fonts/msyh.ttc").unwrap();
fonts.font_data.insert(
"my_font".to_owned(),
egui::FontData::from_owned(font)
); |
Beta Was this translation helpful? Give feedback.
-
Others have gotten Chinese to work, e.g. with https://github.com/emilk/egui/files/7739412/sarasa-mono-sc-nerd-regular.zip Are you adding it like shown in https://github.com/emilk/egui/blob/master/examples/custom_font/src/main.rs / https://github.com/emilk/egui/blob/0.17.0/eframe/examples/custom_font.rs ? |
Beta Was this translation helpful? Give feedback.
-
After reading about the source of druid,I found that piet-direct2d maybe would load the fonts from system according to the input characters dynamically. |
Beta Was this translation helpful? Give feedback.
-
Expect this function. |
Beta Was this translation helpful? Give feedback.
-
An example using use std::fs::read;
use eframe::{
egui::{Context, FontData, FontDefinitions},
epaint::FontFamily,
};
use font_kit::{
family_name::FamilyName, handle::Handle, properties::Properties, source::SystemSource,
};
fn load_system_font(ctx: &Context) {
let mut fonts = FontDefinitions::default();
let handle = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap();
let buf: Vec<u8> = match handle {
Handle::Memory { bytes, .. } => bytes.to_vec(),
Handle::Path { path, .. } => read(path).unwrap(),
};
const FONT_SYSTEM_SANS_SERIF: &'static str = "System Sans Serif";
fonts
.font_data
.insert(FONT_SYSTEM_SANS_SERIF.to_owned(), FontData::from_owned(buf));
if let Some(vec) = fonts.families.get_mut(&FontFamily::Proportional) {
vec.push(FONT_SYSTEM_SANS_SERIF.to_owned());
}
if let Some(vec) = fonts.families.get_mut(&FontFamily::Monospace) {
vec.push(FONT_SYSTEM_SANS_SERIF.to_owned());
}
ctx.set_fonts(fonts);
} |
Beta Was this translation helpful? Give feedback.
-
I don't know why we must specify a font file to load while develop in egui?It's very annoyed to specify a font while i am a non-native english speaker.While we developing a gui program with gtk or qt,we never need to think what font we should use.
Maybe we could automatically find a local font file by get the system default language and the system default font storage position in Windows,Linux and Mac.If we can't find it,then we could use default font embed in egui.
If my suggestion is valuable,please let me know.I'd glad to make a PR.
Beta Was this translation helpful? Give feedback.
All reactions