Skip to content

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

Merge #1973: Fix incomplete system font coverage in the Chinese interface (@yuraizmailov)

aionggbc8ddfa5ea4d
diff --cc crates/ui-egui/src/i18n/ui.rs
index 0a4c7b4ce,79a8c8a52..b9cc3eb9e
--- a/crates/ui-egui/src/i18n/ui.rs
+++ b/crates/ui-egui/src/i18n/ui.rs
@@@ -75,15 -60,13 +75,22 @@@ fn catalog(language: &str) -> Option<&'
Some(index.get_or_init(|| rows.iter().copied().collect()))
}
+/// The panel strings `language` has no row for (every English source any catalog lists), in
+/// catalog order, for the missing-strings report.
+#[cfg(test)]
+pub(super) fn missing(language: &str) -> Vec<&'static str> {
+ let table = catalog(language);
+ let mut seen = std::collections::HashSet::new();
+ ROWS.iter().flat_map(|(_, rows)| rows.iter().map(|(en, _)| *en)).filter(|en| seen.insert(*en) && !table.is_some_and(|c| c.contains_key(en))).collect()
+}
+
+ /// Characters required by the fixed panel catalog, for system-font coverage selection.
+ /// Sorted and deduplicated so fallback registration is deterministic.
+ #[cfg(not(target_arch = "wasm32"))]
+ pub(crate) fn catalog_characters(language: &str) -> Vec<char> {
+ catalog(language).into_iter().flat_map(|c| c.values()).flat_map(|s| s.chars()).collect::<std::collections::BTreeSet<_>>().into_iter().collect()
+ }
+
/// Translate one interface string: the current language's row for `text`, or `text` itself.
pub(crate) fn tr(text: &str) -> &str {
catalog(current()).and_then(|c| c.get(text)).copied().unwrap_or(text)
diff --cc crates/ui-egui/src/theme.rs
index 290e3d4e9,7f9018fc7..eca8b2fb2
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@@ -408,18 -408,15 +408,25 @@@ fn install_script_fallbacks(family_font
let cjk = if is_chinese(language) { [han, KANA] } else { [KANA, han] };
let mut names = Vec::new();
let mut seen = Vec::new();
- for &(probe, name) in cjk.iter().chain(SCRIPT_PROBES).chain(std::iter::once(&HANGUL)) {
+ // A font covering one Han probe may be a sparse subset. Register additional faces
+ // needed by the actual interface catalog instead of assuming whole-script coverage.
+ let extra = if is_chinese(language) { crate::i18n::catalog_characters(language) } else { Vec::new() };
+ let extra: Vec<_> = extra.into_iter().filter(|ch| *ch >= '\u{2e80}').map(|ch| (ch, "catalog-system")).collect();
+ for &(probe, name) in cjk.iter().chain(SCRIPT_PROBES).chain(std::iter::once(&HANGUL)).chain(&extra) {
+ if name == "catalog-system" && seen.iter().any(|&id| fonts::face(id).has_char(probe)) {
+ continue;
+ }
- let id = fonts::fallback_for(probe, base);
+ // 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. 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_locale(probe, base, cjk_locale(language)));
if seen.contains(&id) {
continue;
}