Skip to content

Commit

Permalink
#10497: Do not force the font on output codepage change (#10591)
Browse files Browse the repository at this point in the history
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.

## Validation Steps Performed
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.

Closes #10497
  • Loading branch information
alabuzhev authored Jul 8, 2021
1 parent f03cacf commit a0527a1
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/host/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ void SetConsoleCPInfo(const BOOL fOutput)
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
if (fOutput)
{
// If we're changing the output codepage, we want to update the font as well to give the engine an opportunity
// 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 (gci.HasActiveOutputBuffer())
{
SCREEN_INFORMATION& screenInfo = gci.GetActiveOutputBuffer();
const FontInfo& fiOld = screenInfo.GetCurrentFont();

// Use the desired face name when updating the font.
// This ensures that if we had a fall back operation last time (the desired
// face name didn't support the code page and we have a different less-desirable font currently)
// that we'll now give it another shot to use the desired face name in the new code page.
FontInfo fiNew(screenInfo.GetDesiredFont().GetFaceName(),
fiOld.GetFamily(),
fiOld.GetWeight(),
fiOld.GetUnscaledSize(),
gci.OutputCP);
screenInfo.UpdateFont(&fiNew);
}

if (!GetCPInfo(gci.OutputCP, &gci.OutputCPInfo))
{
gci.OutputCPInfo.LeadByte[0] = 0;
Expand Down

0 comments on commit a0527a1

Please sign in to comment.