Font: fall back to a host CJK font so Chinese text is not drawn as '?' #1754
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1754
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1754"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ccxp on GitHub · 2026-10-20 08:11 UTC · original
ccxp:main→main· +205 −23 · 3 files · 1 commits · openWith the console language set to Chinese, some in-game text showed up as "??". This is not an encoding bug: libFont draws '?' on purpose for any character it cannot find in the font.
Root cause:
The system overlay already merges a per-language CJK font through AddSystemFontFallbacks(), so it is not changed here.
Changes:
Testing: this is the same change, on the same base commit (
1a053f9e), that was built successfully and verified in Astro Bot with the console language set to Chinese: text that used to show as "??" renders correctly.With the console language set to Chinese, some in-game text showed up as "??". This is not an encoding bug: libFont draws '?' on purpose for any character it cannot find in the font. Root cause: - The game opens the PS5 system font sets (SC/TC/JP/KR) through FontOpenFontSet. Those fonts don't exist on the host, so libFont falls back to Roboto (3rdparty/tracy), which only has Latin glyphs. - stb_supported_codepoint() replaced every code point missing from the font with '?'. - The font format check only accepted .ttf/.otf, so TrueType collections (.ttc), which most Windows CJK fonts are (e.g. msyh.ttc), were rejected. - FontGetKerning() returned FONT_ERROR_NO_SUPPORT_CODE for any character missing from the primary face, including CJK characters. The system overlay already merges a per-language CJK font through AddSystemFontFallbacks(), so it is not changed here. Changes: - Add Common::FindCjkFontFiles(locale) (src/common/systemFonts.{h,cpp}). It tries KYTY_CJK_FONT first, then the installed system CJK fonts, ordered by the console locale so shared Han characters use the regional glyph forms: zh-Hans prefers Microsoft YaHei, zh-Hant Microsoft JhengHei, ja-JP Yu Gothic/Meiryo, ko-KR Malgun Gothic. macOS (PingFang, Hiragino, Apple SD Gothic Neo) and Linux (Noto Sans CJK, WenQuanYi, Droid Sans Fallback) paths are included too. - libFont: accept .ttc files and load face 0 through stbtt_GetFontOffsetForIndex(). - libFont: add resolve_stb_glyph(), which picks the face per character: the font's own face first, then the host CJK fallback, and '?' only if neither has the glyph. Glyph metrics and bitmaps are computed with the face that was actually picked, using its own em scale. - libFont: FontGetKerning() returns OK with zero kerning when a character is drawn from the CJK fallback face, instead of FONT_ERROR_NO_SUPPORT_CODE. - libFont: log which CJK fallback font is used, or warn when none is found. Testing: this is the same change, on the same base commit (1a053f9e), that was built successfully and verified in Astro Bot with the console language set to Chinese: text that used to show as "??" renders correctly. This checkout has not been built or tested separately.@coderabbitai[bot] on GitHub · 2026-10-20 08:17 UTC · original
📝 Walkthrough
The change adds
Common::FindCjkFontFilesto locate existing CJK font files through an environment override and platform-specific paths. Font initialization now supports.ttcfiles and loads a CJK fallback face based on the console language and locale. Glyph metrics and bitmap rendering use the primary face when possible, then the CJK fallback face, and finally?. Kerning validation also checks glyph availability in the fallback face.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
aa759Some CJK characters may still appear as question marks, and Linux users may see incorrect regional glyph forms. These are bounded cases, but both fallback gaps should be addressed.
Pre-merge checks:
4 ·
1
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -0,0 +73,4 @@AppendIfFile(result, path);}(void)locale;#endif@coderabbitai[bot] on GitHub · 2026-10-20 08:17 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7352
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9678
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4174
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5026
Honor the console locale in the Linux CJK fallback order.
FindCjkFontFiles()discardslocaleon Linux and always returns the same list.cjk_fallback_face()selects the first usable file, andinit_stb_info()always loads face 0. Therefore, when multiple regional fonts are installed,ja-JP,zh-Hant, andzh-Hanscan all select a non-matching face and render shared Han glyphs with the wrong regional forms. The locale-aware ordering inAddSystemFontFallbacks()does not affect thislibFont.cpppath. Add Linux locale-specific candidate or face selection before the generic fallback list.@ -788,0 +849,4 @@const auto& cjk = cjk_fallback_face();return cjk.ok && stbtt_FindGlyphIndex(&cjk.info, static_cast<int>(code)) != 0;}@coderabbitai[bot] on GitHub · 2026-10-20 08:17 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9976
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21199
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10648
Search all initialized fallback faces per code point.
When
KYTY_CJK_FONTpoints to a structurally valid font that lacks a requested CJK glyph,cjk_fallback_face()selects it and stops. It never checks later files fromFindCjkFontFiles(). If the primary font also lacks the glyph,resolve_stb_glyph()returns?even when a later host font contains the glyph. Retain all initialized fallback faces and test them in order fromresolve_stb_glyph().@coderabbitai[bot] on GitHub · 2026-10-20 08:17 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
6acb6ab1-bc3b-4609-b657-2f69b57cec72📥 Commits
Reviewing files that changed from the base of the PR and between
1a053f9e13andaa759ad391.📒 Files selected for processing: 3
src/common/systemFonts.cppsrc/common/systemFonts.hsrc/libs/libFont.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.