Repository navigation
Keep the requested font on East Asian code pages in GdiEngine - #21027
Open
Jiayu Hu (hjy271828) wants to merge 1 commit into
Open
Jiayu Hu (hjy271828) wants to merge 1 commit into
Jiayu Hu (hjy271828) wants to merge 1 commit into
Conversation
GdiEngine::_GetProposedFont sets lfCharSet from the console code page, e.g. GB2312_CHARSET for 936. GDI's font mapper prefers a matching charset over a matching face name, so fonts that don't cover that charset (Consolas, Cascadia Mono, Nerd Fonts, ...) were silently replaced with the code page's default font (NSimSun for 936, MS Gothic for 932). This happened at startup and when the font was changed at runtime. If the realized face doesn't match the requested one, retry with DEFAULT_CHARSET and keep it only if that yields the requested face. Fonts that support the code page charset, and fonts that aren't installed, behave as before. Characters the font lacks (e.g. CJK text) still render through GDI's font fallback. Closes microsoft#21018
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🔵 Needs a closer look
The LOGFONT-, locale-, and installed-font-sensitive mapper needs human runtime checks on code page 932 and Monofur/Iosevka Extralight beyond the reported code page 936 validation.
No open issues 🎉
What changed in this PR
Addresses #21018 by preserving requested fonts in conhost’s GDI renderer when East Asian code-page charsets cause unwanted font substitution.
Changes:
- Retry mismatched fonts with
DEFAULT_CHARSET, accepting the retry only when it realizes the requested face. - Add
NSimSunto the spelling allow list.
| File | Description |
|---|---|
| src/renderer/gdi/state.cpp | Add conditional charset retry while preserving fallback for missing fonts. |
| .github/actions/spelling/allow/fonts.txt | Allow the font name used in the new comments. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GdiEngine::_GetProposedFont sets lfCharSet from the console code page, e.g. GB2312_CHARSET for 936. GDI's font mapper prefers a matching charset over a matching face name, so fonts that don't cover that charset (Consolas, Cascadia Mono, Nerd Fonts, ...) were silently replaced with the code page's default font (NSimSun for 936, MS Gothic for 932). This happened at startup and when the font was changed at runtime.
If the realized face doesn't match the requested one, retry with DEFAULT_CHARSET and keep it only if that yields the requested face. Fonts that support the code page charset, and fonts that aren't installed, behave as before. Characters the font lacks (e.g. CJK text) still render through GDI's font fallback.
Closes #21018
Summary of the Pull Request
On East Asian console code pages (e.g. 936, 932), conhost's GDI renderer silently replaces TrueType fonts that don't cover the code page's charset (Consolas, Cascadia Mono, Nerd Fonts, ...) with the code page's default font (NSimSun, MS Gothic). This PR makes GdiEngine keep the requested font in that case.
References and Relevant Issues
Closes #21018
Detailed Description of the Pull Request / Additional comments
GdiEngine::_GetProposedFontsetslfCharSetfrom the console code page (936 →GB2312_CHARSET). GDI's font mapper prefers a matching charset over a matching face name, soCreateFontIndirectWreturns a GB2312-capable font instead of the requested one. This happens at startup and whenever the font is changed at runtime.The fix: when the code-page charset isn't
OEM_CHARSET,ANSI_CHARSETorDEFAULT_CHARSET, and the realized face (GetTextFaceW) differs from the requested face, retry withDEFAULT_CHARSET. The retry is only kept if it yields the requested face.The change is limited to
src/renderer/gdi/state.cpp.NSimSunis added to the spelling allow list.Validation Steps Performed
Code page 936 (Chinese Simplified locale),
HKCU\Console\FaceName = MesloLGL Nerd Font Mono, OpenConsole Release x64 launched withOpenConsole.exe cmd.exe. Left:main(cbfe97a), right: this PR.chcp 437CJK text renders correctly in all cases.
Invoke-OpenConsoleTests -Test hostand-Test interactivityWin32pass,Invoke-CodeFormatproduces no changes.PR Checklist
AI disclosure: I used an AI assistant (Claude Code) to help investigate the issue and draft the initial patch. I reviewed the full change, built it, and performed the validation above myself.