Repository: microsoft/terminal (language: cpp)

Issue:
warning popup "Cascadia Mono font is not found" (unpackaged version)
### Windows Terminal version

1.18.3181.0 (unpackaged 1.18.231114001)

### Windows build number

10.0.19045.0

### Other Software

_No response_

### Steps to reproduce

It looks like the bug fix for "The regression where "Cascadia Mono" (or "... Code") would not be found on upgrade has been un-regressed (https://github.com/microsoft/terminal/pull/16196)" introduced a regression for the unpackaged version

Launch WindowsTerminal.exe from unpackaged version
- https://github.com/microsoft/terminal/releases/download/v1.18.3181.0/Microsoft.WindowsTerminal_1.18.3181.0_x64.zip
- https://github.com/microsoft/terminal/releases/download/v1.18.2822.0/Microsoft.WindowsTerminal_1.18.2822.0_x64.zip


### Expected Behavior

- no warning popup from WindowsTerminal.exe unpackaged version 1.18.3181.0 (unpackaged 1.18.231114001)
- no warning popup from WindowsTerminal.exe unpackaged version 1.18.2822.0 (unpackaged 1.18.231009002-preview)

### Actual Behavior

- a warning popup: "Cascadia Mono font is not found, Consolas is used instead" from WindowsTerminal.exe unpackaged version 1.18.3181.0 (unpackaged 1.18.231114001) is displayed 
- no warning popup from WindowsTerminal.exe unpackaged version 1.18.2822.0 (unpackaged 1.18.231009002-preview)

with the same default profile from C:\...\AppData\Local\Microsoft\Windows Terminal\settings.json settings
```json
{
    "altGrAliasing": true,
    "antialiasingMode": "grayscale",
    "closeOnExit": "automatic",
    "colorScheme": "Campbell",
    "commandline": "C:\\...\\PowerShell-7.3\\pwsh.exe",
    "cursorShape": "bar",
    "font":
    {
        "face": "Cascadia Mono",
        "size": 10.0
    },
    "guid": "....",
    "hidden": false,
    "historySize": 9001,
    "icon": "C:\\...\\PowerShell-7.3\\assets\\Square44x44Logo.png",
    "name": "Pwsh 7.3",
    "padding": "8, 8, 8, 8",
    "snapOnInput": true,
    "startingDirectory": "%USERPROFILE%",
    "useAcrylic": false
},



Discussion / hints:
@lhecker did we somehow break this for unpackaged in #16196
Yes. 🤦 You see, because DxEngine modifies the *only* copy of the chosen face name to do a variant search (i.e. "Arial Bold" -> "Arial", if the former doesn't exist). So by moving the nearby search after the variant search, I broke the lookup because now it searches for "Cascadia".

FYI the code for "AtlasEngine" works correctly. You can enable it in the "Rendering" settings and enable it, as it'll be the default in the near term anyways.

Fix patch:
diff --git a/src/renderer/dx/DxFontInfo.cpp b/src/renderer/dx/DxFontInfo.cpp
index b1d4844a601..b0f79cde39a 100644
--- a/src/renderer/dx/DxFontInfo.cpp
+++ b/src/renderer/dx/DxFontInfo.cpp
@@ -126,44 +126,52 @@ void DxFontInfo::SetFromEngine(const std::wstring_view familyName,
     try
     {
         face = _FindFontFace(localeName);
+    }
+    CATCH_LOG();
 
-        if (!face)
+    if constexpr (Feature_NearbyFontLoading::IsEnabled())
+    {
+        try
         {
-            // If we missed, try looking a little more by trimming the last word off the requested family name a few times.
-            // Quite often, folks are specifying weights or something in the familyName and it causes failed resolution and
-            // an unexpected error dialog. We theoretically could detect the weight words and convert them, but this
-            // is the quick fix for the majority scenario.
-            // The long/full fix is backlogged to GH#9744
-            // Also this doesn't count as a fallback because we don't want to annoy folks with the warning dialog over
-            // this resolution.
-            while (!face && !_familyName.empty())
+            if (!face)
             {
-                const auto lastSpace = _familyName.find_last_of(UNICODE_SPACE);
-
-                // value is unsigned and npos will be greater than size.
-                // if we didn't find anything to trim, leave.
-                if (lastSpace >= _familyName.size())
-                {
-                    break;
-                }
-
-                // trim string down to just before the found space
-                // (space found at 6... trim from 0 for 6 length will give us 0-5 as the new string)
-                _familyName = _familyName.substr(0, lastSpace);
-
-                // Try to find it with the shortened family name
+                _fontCollection = FontCache::GetCached();
                 face = _FindFontFace(localeName);
             }
         }
+        CATCH_LOG();
     }
-    CATCH_LOG();
 
-    if constexpr (Feature_NearbyFontLoading::IsEnabled())
+    if (!face)
     {
-        if (!face)
+        // If we missed, try looking a little more by trimming the last word off the requested family name a few times.
+        // Quite often, folks are specifying weights or something in the familyName and it causes failed resolution and
+        // an unexpected error dialog. We theoretically could detect the weight words and convert them, but this
+        // is the quick fix for the majority scenario.
+        // The long/full fix is backlogged to GH#9744
+        // Also this doesn't count as a fallback because we don't want to annoy folks with the warning dialog over
+        // this resolution.
+        while (!face && !_familyName.empty())
         {
-            _fontCollection = FontCache::GetCached();
-            face = _FindFontFace(localeName);
+            const auto lastSpace = _familyName.find_last_of(UNICODE_SPACE);
+
+            // value is unsigned and npos will be greater than size.
+            // if we didn't find anything to trim, leave.
+            if (lastSpace >= _familyName.size())
+            {
+                break;
+            }
+
+            // trim string down to just before the found space
+            // (space found at 6... trim from 0 for 6 length will give us 0-5 as the new string)
+            _familyName = _familyName.substr(0, lastSpace);
+
+            try
+            {
+                // Try to find it with the shortened family name
+                face = _FindFontFace(localeName);
+            }
+            CATCH_LOG();
         }
     }
 
@@ -176,7 +184,12 @@ void DxFontInfo::SetFromEngine(const std::wstring_view familyName,
         {
             _familyName = fallbackFace;
 
-            face = _FindFontFace(localeName);
+            try
+            {
+                face = _FindFontFace(localeName);
+            }
+            CATCH_LOG();
+
             if (face)
             {
                 _didFallback = true;


Test patch: