fix: reorder find_fonts_dir to cwd, exe-parent, ../fonts

This commit is contained in:
Developer
2026-05-16 22:26:45 +08:00
parent 4e7768d265
commit 3c54cc1e55

View File

@@ -55,17 +55,10 @@ pub fn setup_fonts(ctx: &egui::Context, selected_name: &str) -> String {
}
fn find_fonts_dir() -> PathBuf {
// 1. CWD + fonts/ (cargo run from project root)
let cwd_fonts = PathBuf::from("fonts");
if cwd_fonts.is_dir() {
return cwd_fonts;
let cwd = PathBuf::from("fonts");
if cwd.is_dir() {
return cwd;
}
// 2. CWD + ../fonts/ (exe running from target/{debug,release})
let parent_fonts = PathBuf::from("../fonts");
if parent_fonts.is_dir() {
return parent_fonts;
}
// 3. Exe parent + fonts/ (deployed, fonts next to exe)
if let Ok(exe) = std::env::current_exe() {
if let Some(parent) = exe.parent() {
let p = parent.join("fonts");
@@ -74,6 +67,9 @@ fn find_fonts_dir() -> PathBuf {
}
}
}
// 4. Fallback (will fail with file-not-found, graceful fallback to bundled font)
let up = PathBuf::from("../fonts");
if up.is_dir() {
return up;
}
PathBuf::from("fonts")
}