refactor: make UI localization extensible and integrate upstream
This commit is contained in:
commit
6d4c031090
199 files changed
+31595
-2151
No files matched your search
@@ -1,8 +1,10 @@
|
||||
//! System font loading and fallback setup for multi-language (CJK/Japanese) support.
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Candidate font paths to look for on different operating systems.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const FONT_CANDIDATES: &[&str] = &[
|
||||
// Windows
|
||||
"C:\\Windows\\Fonts\\meiryo.ttc",
|
||||
@@ -11,6 +13,7 @@ const FONT_CANDIDATES: &[&str] = &[
|
||||
"C:\\Windows\\Fonts\\msgothic.ttc",
|
||||
"C:\\Windows\\Fonts\\BIZ-UDGothicR.ttc",
|
||||
// macOS
|
||||
"/System/Library/Fonts/ヒラギノ角ゴシック W3.ttc",
|
||||
"/System/Library/Fonts/Hiragino Sans GB.ttc",
|
||||
"/System/Library/Fonts/PingFang.ttc",
|
||||
"/Library/Fonts/Arial Unicode.ttf",
|
||||
@@ -22,10 +25,13 @@ const FONT_CANDIDATES: &[&str] = &[
|
||||
];
|
||||
|
||||
/// Configure font definitions with system CJK fallback if available.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn setup_fonts(ctx: &egui::Context) {
|
||||
let mut font_bytes: Option<Vec<u8>> = None;
|
||||
for path in FONT_CANDIDATES {
|
||||
if let Ok(bytes) = std::fs::read(path) {
|
||||
if let Ok(bytes) = std::fs::read(path)
|
||||
&& ttf_parser::Face::parse(&bytes, 0).is_ok()
|
||||
{
|
||||
font_bytes = Some(bytes);
|
||||
break;
|
||||
}
|
||||
@@ -44,3 +50,7 @@ pub fn setup_fonts(ctx: &egui::Context) {
|
||||
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
/// Browsers cannot read system font files. A web host can supply licensed fonts through egui.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn setup_fonts(_ctx: &egui::Context) {}
|
||||
Reference in new issue
Block a user