[fix/3505] Chinese character rendering problem#9924
Conversation
On Linux/FreeBSD, the cosmic_text FontSystem was hardcoded to use "en" locale, which prevented proper CJK (Chinese/Japanese/Korean) font fallback. The system LANG environment variable contains the user's locale (e.g., zh_CN.UTF-8, ja_JP.UTF-8), which cosmic_text uses to determine which fallback fonts to use for non-Latin characters. This fix reads the LANG environment variable at TextLayoutSystem initialization and uses it to configure the FontSystem locale, ensuring CJK characters display correctly on first render instead of requiring a keypress to trigger re-rendering. Fixes warpdotdev#3505
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Dr. Alex Mitre.
|
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR changes the winit text layout font system initialization to derive the cosmic-text locale from LANG instead of hardcoding en.
Concerns
- The new code uses a
cosmic_text::LocaleAPI, but the lockedcosmic-textAPI takes aStringlocale forFontSystem::new_with_locale_and_db, so this hunk will not compile as written.
Verdict
Found: 1 critical, 0 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| let locale = std::env::var("LANG") | ||
| .ok() | ||
| .filter(|lang| !lang.is_empty()) | ||
| .map(cosmic_text::Locale::new) | ||
| .unwrap_or_else(|| cosmic_text::Locale::new("en").expect("en is a valid locale")); |
There was a problem hiding this comment.
🚨 [CRITICAL] This does not type-check with the locked cosmic-text API: FontSystem::new_with_locale_and_db expects a String, and cosmic_text::Locale is not part of that API. Keep this as a String and normalize the POSIX LANG value before passing it through.
| let locale = std::env::var("LANG") | |
| .ok() | |
| .filter(|lang| !lang.is_empty()) | |
| .map(cosmic_text::Locale::new) | |
| .unwrap_or_else(|| cosmic_text::Locale::new("en").expect("en is a valid locale")); | |
| let locale = std::env::var("LANG") | |
| .ok() | |
| .and_then(|lang| lang.split('.').next().map(str::to_string)) | |
| .filter(|lang| !lang.is_empty()) | |
| .map(|lang| lang.replace('_', "-")) | |
| .unwrap_or_else(|| "en".to_string()); |
|
Closing this to keep my open PR queue focused on contributions that are currently reviewable and likely to proceed. This one has a blocking signal (changes-requested-cla) and would need a deeper rework before it is worth maintainer time. Thanks for the review/context. |
Problem
Chinese characters do not render correctly on first display. After any button press, they display correctly.
Root Cause
On Linux/FreeBSD, the cosmic_text FontSystem was initialized with a hardcoded 'en' locale. The locale is used by cosmic_text to determine which fallback fonts to use for non-Latin characters like CJK.
Fix
Read the LANG environment variable at TextLayoutSystem initialization and use it to configure the FontSystem locale. This ensures CJK characters display correctly on first render.
Fixes #3505