Ask fontconfig for the menu's CJK font instead of hard-coding five paths

plat_font_path stats five absolute paths for NotoSansCJK-Regular.ttc and takes the first that exists. That covers
SteamOS and the usual distributions, but misses any system where the font lives elsewhere, and fails outright in a
sandbox: under Flatpak /usr is the runtime and ships no CJK font, the app may only write /app, and the host's fonts
appear at /run/host/fonts. All five paths miss, fonts_up merges 0 fonts, and every Chinese character in the settings
menu renders as '?' while English stays correct.

Asking fontconfig fixes all of these at once. It is the same database Tk/Xft and every other Linux toolkit reads; it
knows /app/share/fonts, the XDG data dirs, /run/host/fonts and the per-user directories, so installing the font where
the system looks is enough and no packaging can leave the menu stranded.

libfontconfig is dlopen'd, not linked: a host without it (headless, a bare container) still builds and runs and takes
the fallback, so this adds no build dependency, and the runtime already links -ldl for the NVIDIA libraries. The
result is checked against the character before it is used, because fontconfig returns the closest pattern even when
nothing covers a character -- without that a Latin-only system hands back DejaVu Sans and the menu believes it merged
glyphs when it did not. The pattern names zh-cn and zh-tw rather than zh-hans and zh-hant, which is how Noto CJK and
fontconfig tag the faces.

menu_font_fontconfig defaults to 1 and 0 goes back to the five fixed paths, for a player whose fontconfig resolves to
a font the menu's parser cannot read. TOTK_MENU_FONT names a file directly and wins over both. A system with the font
where the old paths expect it sees no change, and Windows, whose font names are fixed, is untouched.

Verified against the real fontconfig with the host having no CJK font, with fontconfig pointed at a directory holding
only NotoSansCJK-Regular.ttc (the Flatpak case, now resolved), with TOTK_MENU_FONT set and pointing at a missing file,
with menu_font_fontconfig=0, and with libfontconfig made unloadable (falls back quietly, no crash).
This commit is contained in:
jcleng committed 2026-11-11 13:15:39 +00:00
1 parent d8a1d14104
commit 00a0ffc197
4 files changed
+147 -5

No files matched your search

+3 -1
View File
@@ -387,7 +387,9 @@ const char *plat_ui_language(void);
const char *plat_user_locale(void);
uint32_t plat_thread_id(void); // id of the calling thread, for unique file names
// A system font file with the glyphs of a catalog language ("ja", "ko", "zh-Hans", "zh-Hant"): the menu shows each
// language's name in its own script. Copies the UTF-8 path into out; 0 when the system has none.
// language's name in its own script. Copies the UTF-8 path into out; 0 when the system has none. On Linux the file is
// the one fontconfig picks for that language (so a sandbox that installs a font where its fontconfig finds it needs no
// code change), with TOTK_MENU_FONT overriding it and the usual distribution paths as the fallback.
int plat_font_path(const char *lang, char *out, size_t cap);
// The operating system and its build ("Windows 10.0.28000") into out; 0 when unknown.
int plat_os_version(char *out, size_t cap);