viewer: pick a CJK-capable font for the HUD (#219)

The HUD rasterizes text with a single font and has no per-character
fallback. On systems where fontconfig strongly prefers a Latin-only
sans-serif (e.g. Liberation Sans on Omarchy), 'sans-serif:lang=zh-cn'
resolves to a face without Han glyphs and the Chinese labels render as
empty boxes.

Require U+63A7 (控, from 控制中心) in the fc-match pattern so coverage
influences selection while still respecting the system's font families.

Co-authored-by: zhuwangqi <[email protected]>
This commit is contained in:
Onekkiandzhuwangqi authored and GitHub committed 2026-11-12 18:17:13 +08:00
1 parent 50a7447b7b
commit 4649149ff5
1 file changed
+3 -1
+3 -1
View File
@@ -67,7 +67,9 @@ pub fn load_font() -> Option<FontVec> {
let (path, index) = match std::env::var("UU_VIEWER_FONT") {
Ok(p) if !p.is_empty() => (p, 0),
_ => {
let out = std::process::Command::new("fc-match").args(["-f", "%{file}\t%{index}", "sans-serif:lang=zh-cn"]).output().ok()?;
// Request U+63A7 (控, from 控制中心) to prefer a CJK-capable font;
// the HUD uses a single font without per-glyph fallback.
let out = std::process::Command::new("fc-match").args(["-f", "%{file}\t%{index}", "sans-serif:lang=zh-cn:charset=63a7"]).output().ok()?;
let line = String::from_utf8(out.stdout).ok()?;
let (file, index) = line.split_once('\t').unwrap_or((line.as_str(), "0"));
// fontconfig puts the variable-font named instance in the upper 16 bits; the face is below.