Do we still need to force the font on output codepage change? #14317

Open
opened 2026-01-31 04:07:01 +00:00 by claunia · 0 comments
Owner

Originally created by @alabuzhev on GitHub (Jun 22, 2021).

Description of the new feature/enhancement

Currently, when the user changes the console codepage (manually or via a script) the GDI engine tries to find and set the "best possible" font. The "best possible" here is charset-wise, it doesn't mean that the font is actually better or more eye-candy for the user.

Example:

  • Open cmd
  • Set the font to Consolas
  • Enter chcp 932
  • Suddenly, a wild MS Gothic appears!

This kind of makes sense ("if I'm changing the codepage I probably want to see the national characters") but it doesn't happen anywhere else - all other apps just substitute the missing glyphs.

After #10472 / #10478 this magic should finally work here as well. So, do we still need to change the whole font? Terminal doesn't do that after all.

Proposed technical implementation details

A quick and dirty hack, I'm sure there are better ways:

diff --git a/src/host/misc.cpp b/src/host/misc.cpp
index a89c982b..64f602d1 100644
--- a/src/host/misc.cpp
+++ b/src/host/misc.cpp
@@ -38,6 +38,7 @@ void SetConsoleCPInfo(const BOOL fOutput)
         // to pick a more appropriate font should the current one be unable to render in the new codepage.
         // To do this, we create a copy of the existing font but we change the codepage value to be the new one that was just set in the global structures.
         // NOTE: We need to do this only if everything is set up. This can get called while we're still initializing, so carefully check things for nullptr.
+#if 0
         if (gci.HasActiveOutputBuffer())
         {
             SCREEN_INFORMATION& screenInfo = gci.GetActiveOutputBuffer();
@@ -54,6 +55,7 @@ void SetConsoleCPInfo(const BOOL fOutput)
                            gci.OutputCP);
             screenInfo.UpdateFont(&fiNew);
         }
+#endif
 
         if (!GetCPInfo(gci.OutputCP, &gci.OutputCPInfo))
         {

Testing

Download 932.cmd.txt, rename to 932.cmd, run it, check if the output is still readable.

Originally created by @alabuzhev on GitHub (Jun 22, 2021). # Description of the new feature/enhancement Currently, when the user changes the console codepage (manually or via a script) the GDI engine tries to find and set the "best possible" font. The "best possible" here is charset-wise, it doesn't mean that the font is actually better or more eye-candy for the user. Example: - Open cmd - Set the font to Consolas - Enter `chcp 932` - Suddenly, a wild MS Gothic appears! This kind of makes sense (*"if I'm changing the codepage I probably want to see the national characters"*) but it doesn't happen anywhere else - all other apps just substitute the missing glyphs. After #10472 / #10478 this magic should finally work here as well. So, do we still need to change the whole font? Terminal doesn't do that after all. # Proposed technical implementation details A quick and dirty hack, I'm sure there are better ways: ```DIFF diff --git a/src/host/misc.cpp b/src/host/misc.cpp index a89c982b..64f602d1 100644 --- a/src/host/misc.cpp +++ b/src/host/misc.cpp @@ -38,6 +38,7 @@ void SetConsoleCPInfo(const BOOL fOutput) // to pick a more appropriate font should the current one be unable to render in the new codepage. // To do this, we create a copy of the existing font but we change the codepage value to be the new one that was just set in the global structures. // NOTE: We need to do this only if everything is set up. This can get called while we're still initializing, so carefully check things for nullptr. +#if 0 if (gci.HasActiveOutputBuffer()) { SCREEN_INFORMATION& screenInfo = gci.GetActiveOutputBuffer(); @@ -54,6 +55,7 @@ void SetConsoleCPInfo(const BOOL fOutput) gci.OutputCP); screenInfo.UpdateFont(&fiNew); } +#endif if (!GetCPInfo(gci.OutputCP, &gci.OutputCPInfo)) { ``` # Testing Download [932.cmd.txt](https://github.com/microsoft/terminal/files/6697577/932.cmd.txt), rename to 932.cmd, run it, check if the output is still readable.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14317