toga icon indicating copy to clipboard operation
toga copied to clipboard

Rendering Issues with Chinese Characters on Windows

Open albuszheng opened this issue 7 months ago • 7 comments

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.

Image

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)

Image

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.

albuszheng avatar May 19 '25 16:05 albuszheng

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?

freakboy3742 avatar May 19 '25 16:05 freakboy3742

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.

albuszheng avatar May 19 '25 16:05 albuszheng

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 avatar May 20 '25 14:05 mhsmith

@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.

johnzhou721 avatar May 21 '25 02:05 johnzhou721

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...

johnzhou721 avatar May 24 '25 21:05 johnzhou721

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.

freakboy3742 avatar May 27 '25 00:05 freakboy3742

Nice. So maybe when #2248 is resolved, we can have use different fonts depending on the locale.

johnzhou721 avatar May 27 '25 01:05 johnzhou721