fix: 添加中文字体支持,解决中文显示乱码
This commit is contained in:
@@ -20,6 +20,39 @@ fn main() -> eframe::Result {
|
||||
eframe::run_native(
|
||||
"AI优化",
|
||||
options,
|
||||
Box::new(|cc| Ok(Box::new(FlomoAiApp::new(cc)))),
|
||||
Box::new(|cc| {
|
||||
setup_fonts(&cc.egui_ctx);
|
||||
Ok(Box::new(FlomoAiApp::new(cc)))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn setup_fonts(ctx: &egui::Context) {
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
|
||||
let font_paths = [
|
||||
"C:/Windows/Fonts/msyh.ttc",
|
||||
"C:/Windows/Fonts/msyhbd.ttc",
|
||||
"C:/Windows/Fonts/simsun.ttc",
|
||||
"C:/Windows/Fonts/simhei.ttf",
|
||||
];
|
||||
|
||||
for (i, path) in font_paths.iter().enumerate() {
|
||||
if let Ok(data) = std::fs::read(path) {
|
||||
let name = format!("chinese_{}", i);
|
||||
fonts.font_data.insert(name.clone(), egui::FontData::from_owned(data));
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Proportional)
|
||||
.or_default()
|
||||
.push(name.clone());
|
||||
fonts
|
||||
.families
|
||||
.entry(egui::FontFamily::Monospace)
|
||||
.or_default()
|
||||
.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user