Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge #1322: ui: the interface prefers the platform's UI faces, rendered text keeps the print ones (@FeiLiuEM)

aiongg966f9d9894a3
diff --cc crates/ui-egui/src/theme.rs
index fa1bfdcf1,76d699ae9..290e3d4e9
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@@ -409,9 -409,15 +409,17 @@@ fn install_script_fallbacks(family_font
let mut names = Vec::new();
let mut seen = Vec::new();
for &(probe, name) in cjk.iter().chain(SCRIPT_PROBES).chain(std::iter::once(&HANGUL)) {
- // Another context may install a different language concurrently. Its global
- // request must not choose the faces registered into this context.
- let id = fonts::fallback_for_locale(probe, base, cjk_locale(language));
+ // The interface asks for the platform's UI face first; the order a composed frame
- // renders with is `fonts::fallback_for`'s and is not touched here.
++ // renders with is `fonts::fallback_for`'s and is not touched here. Another context may
++ // install a different language concurrently, so the shared fallback is asked with this
++ // context's own locale rather than the global request.
+ let id = interface_fallback_candidates(name, language)
+ .iter()
+ .find_map(|family| {
+ let r = fonts::resolve(family, "Regular");
+ (!r.missing && fonts::face(r.face).has_char(probe)).then_some(r.face)
+ })
- .unwrap_or_else(|| fonts::fallback_for(probe, base));
++ .unwrap_or_else(|| fonts::fallback_for_locale(probe, base, cjk_locale(language)));
if seen.contains(&id) {
continue;
}
@@@ -597,9 -630,24 +631,24 @@@ mod script_font_tests
}
}
+ #[test]
+ fn the_interface_asks_for_the_platforms_ui_faces() {
+ // The face a window draws its own chrome with, which is not the one a composed frame
+ // renders with: the two orders are deliberately separate.
+ let ja = &["Meiryo UI", "Yu Gothic UI", "MS UI Gothic"][..];
+ assert_eq!(interface_fallback_candidates("japanese-system", "ja"), ja);
+ assert_eq!(interface_fallback_candidates("chinese-system", "ja"), ja);
+ assert_eq!(interface_fallback_candidates("chinese-system", "zh-hans"), &["Microsoft YaHei UI"][..]);
+ assert_eq!(interface_fallback_candidates("chinese-system", "zh-hant"), &["Microsoft JhengHei UI", "PMingLiU"][..]);
+ // Every other script the install probes has no UI variant, so it keeps the shared order.
+ for &(_, name) in SCRIPT_PROBES.iter() {
+ assert!(interface_fallback_candidates(name, "en").is_empty(), "{name} asked for a UI face");
+ }
+ }
+
- /// #1141: switching the interface to Simplified Chinese drew most labels as boxes. The English
- /// interface had already loaded a Japanese face for kana, and that face covers the Han probe,
- /// so it became the Chinese fallback too, without the simplified-only hanzi.
+ /// #1141: switching the interface to Simplified Chinese drew most labels as boxes. A Japanese face
+ /// can cover the Han probe while lacking other catalog characters. The context must keep its
+ /// own language policy even when another context installs Japanese fallbacks concurrently.
#[test]
fn simplified_chinese_interface_draws_simplified_hanzi_after_another_language() {
let ctx = egui::Context::default();