Repository: microsoft/terminal (language: cpp)

Issue:
Font rendering changes font look after typing i or j
### Windows Terminal version

1.14.1962.0

### Windows build number

10.0.19043.0

### Other Software

Not relevant.

### Steps to reproduce

1. Open a PowerShell or Debian/Ubuntu terminal
2. Type something without `i` or `j`, say `Th`
3. Look closely and type an `i` or `j`, say `This`


### Expected Behavior

No change in the font rendering.

### Actual Behavior

After typing the `i` or `j` you will notice a change in the rendering of the text.

![image](https://user-images.githubusercontent.com/610865/183110361-2bf0815c-fac1-4722-a879-a4627527cb5b.png)

In the zoomed in view you can see how some letters change, for example, the `l` is now 1 pixel taller and contains red subpixel rendering on the right. But you can also see some changes with the dash, a, and s. As if they all got bolded. This was on a Debian prompt with a Monokai colourscheme. But using a `settings.json` reset to default to make sure it wasn't a configuration issue on my side, you can as easily see this happen on a PowerShell 7 or Ubuntu prompt.

PowerShell:
![image](https://user-images.githubusercontent.com/610865/183112033-bb57b1b2-fa77-4002-83bf-f474bd2e6fef.png)

Interestingly enough, Command Prompt does not seem to exhibit this issue.

Also when you remove all the `i`s and `j`s in the sentence, the rendering reverts back.

Edit: Did some digging, thus far `Cascadia Mono` can reproduce this. Using `Consolas` or `Fira Code` does *not* trigger this behaviour.


Discussion / hints:
I'm having trouble reproducing this behavior.
Long term we're currently planning to replace the default text renderer with a new one. It can be found in the Preview version of Windows Terminal and enabled in the settings menu by selecting any profile (including the "Defaults" one), navigating to "Advanced" and enabling "Enable experimental text rendering engine".
That newer text renderer should theoretically not have this issue.
I'll test the preview. Anything else I can do to help provide more details/background?
I can replicate this with default `1.15.2002.0` as well.

Using the experimental text rendering engine option in `1.15.2002.0`, however, seems to have eliminated the issue and renders similarly to what Command Prompt does, i.e. when you type `T` with Cascadia Mono, it immediately renders it at full height instead of the slightly taller height until you type that `i` or `j`.

Default vs experimental renderer:
![image](https://user-images.githubusercontent.com/610865/183246732-0bbabee3-1e83-4039-8f68-3bc926355820.png)


> Anything else I can do to help provide more details/background?

If this is fixed by the new experimental text renderer, then I'd say - to be entirely frank - it might not be worth it to fix it in the old default text renderer anymore. It's only a matter of time until we start rolling out the new one gradually to everyone after all.

But still, it might be helpful to be able to reproduce the issue. In order to do so I'd need to know what font size you're using, if you have any font features/axes set and what display scale you're using.
Default, so Cascadia Mono at 12. Everything is at default Terminal settings.

2 QHD displays (2560x1440) with scale and layout (under display) set to 100%
Apparently Cascadia Mono has a localized variant for Dutch: https://github.com/microsoft/cascadia-code/blob/017bde551af6af419cc5554c37bbdffa4f9388ed/sources/features/locl.fea#L29-L34

The new engine not handling this correctly might rather be a bug. 🤔
I'll have to investigate that...
Oh wow, that makes sense and at the same time doesn't. I don't use my OSes in Dutch as I prefer English given the settings I have to work in. I do, however have this IME list configured:
![image](https://user-images.githubusercontent.com/610865/183584041-86c0f762-b633-4564-b232-62f6c2a7bab9.png)
![image](https://user-images.githubusercontent.com/610865/183584431-a401dd2e-fde9-4ef1-afb7-02e3189ac61c.png)

I wonder if it somehow sees that English (Netherlands) and tries to kick off ligature combining when typing the i or j (despite it never doing that), which causes the change?


Fix patch:
diff --git a/src/renderer/atlas/AtlasEngine.cpp b/src/renderer/atlas/AtlasEngine.cpp
index a5f8a95cb6a..fc6fdfbccfd 100644
--- a/src/renderer/atlas/AtlasEngine.cpp
+++ b/src/renderer/atlas/AtlasEngine.cpp
@@ -534,6 +534,17 @@ void AtlasEngine::_recreateFontDependentResources()
     _api.replacementCharacterGlyphIndex = 0;
     _api.replacementCharacterLookedUp = false;
 
+    {
+        wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
+
+        if (FAILED(GetUserDefaultLocaleName(&localeName[0], LOCALE_NAME_MAX_LENGTH)))
+        {
+            memcpy(&localeName[0], L"en-US", 12);
+        }
+
+        _api.userLocaleName = std::wstring{ &localeName[0] };
+    }
+
     if (_p.s->font->fontAxisValues.empty())
     {
         for (auto& axes : _api.textFormatAxes)
@@ -799,7 +810,7 @@ void AtlasEngine::_mapComplex(IDWriteFontFace2* mappedFontFace, u32 idx, u32 len
                 /* isSideways          */ false,
                 /* isRightToLeft       */ 0,
                 /* scriptAnalysis      */ &a.analysis,
-                /* localeName          */ nullptr,
+                /* localeName          */ _api.userLocaleName.c_str(),
                 /* numberSubstitution  */ nullptr,
                 /* features            */ &features,
                 /* featureRangeLengths */ &featureRangeLengths,
@@ -851,7 +862,7 @@ void AtlasEngine::_mapComplex(IDWriteFontFace2* mappedFontFace, u32 idx, u32 len
             /* isSideways          */ false,
             /* isRightToLeft       */ 0,
             /* scriptAnalysis      */ &a.analysis,
-            /* localeName          */ nullptr,
+            /* localeName          */ _api.userLocaleName.c_str(),
             /* features            */ &features,
             /* featureRangeLengths */ &featureRangeLengths,
             /* featureRanges       */ featureRanges,
diff --git a/src/renderer/atlas/AtlasEngine.h b/src/renderer/atlas/AtlasEngine.h
index 7e38fae5b5c..c627a7de43b 100644
--- a/src/renderer/atlas/AtlasEngine.h
+++ b/src/renderer/atlas/AtlasEngine.h
@@ -131,6 +131,8 @@ namespace Microsoft::Console::Render::Atlas
             std::vector<wchar_t> bufferLine;
             std::vector<u16> bufferLineColumn;
 
+            std::wstring userLocaleName;
+
             std::array<Buffer<DWRITE_FONT_AXIS_VALUE>, 4> textFormatAxes;
             std::vector<TextAnalysisSinkResult> analysisResults;
             Buffer<u16> clusterMap;


Test patch: