Rendering Issues with Chinese Characters on Windows
Describe the bug
Toga is unable to render Chinese characters properly on Windows, specifically when using the default option without setting a custom font family.
The issue is presented when the Windows display language is set to English (United States) while having the Chinese (Simplified, Mainland China) language pack installed.
Expected behavior
If a custom font family with support for Chinese characters is set, the characters can be rendered correctly.
Example: (Using Microsoft YaHei UI)
Environment
- Operating System:
- Edition Windows 11 Pro
- Version 24H2
- Installed on 2/20/2025
- OS build 26100.3194
- Experience Windows Feature Experience Pack 1000.26100.48.0
- Python version: 3.12.0
- Software versions:
- Toga: 0.5.1
Additional context
The issue seems to be related with how Windows handles the fallback font for CJK characters. The rendering seems to be fine when system display language is set to Chinese.
Thanks for the report. I have no idea what the cause for this would be - but we'd definitely like to address the issue.
I wonder if the issue might be as simple as the default Windows system font being incomplete for those code points?
From what I can tell, the default font for Windows system when the display language is set to English is "Segoe UI". It does not support the CJK characters. But Windows default fallback behavior is problematically.
Some application like MS Word will check if the font family support the CJK characters while editing them. But it seems we have to set it manually and not relying on the system default behavior.
For those unfamiliar with Chinese: the issue is that different characters are being rendered with different weights. But all of these are common characters which would exist in every font, so we don't know why Windows would be inconsistent.
@mhsmith Don't know if they're just different weights... they might be different fonts since the character height is not consistent and in Chinese we usually want to make it really so.
https://learn.microsoft.com/en-us/windows/apps/design/signature-experiences/typography#fonts-for-non-latin-languages makes recommendations for those non-latin fonts.
- Any ways to set an explicit "fallback" font for Windows to use?
- Unless under some specific conditions, people usually don't mix languages in apps. Question: Is there any i18n mechanism in Toga? We can change the font based on that if it exists.
EDIT: Not i18n, localization/
EDIT 2: Actually not sure about terminology...
Question: Is there any i18n mechanism in Toga? We can change the font based on that if it exists.
No - we don't have one at present; see #2248.
Nice. So maybe when #2248 is resolved, we can have use different fonts depending on the locale.