Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/Profiles.cpp (C++)

Code before:
                com_ptr<::IDWriteLocalizedStrings> localizedFamilyNames;
                THROW_IF_FAILED(fontFamily->GetFamilyNames(localizedFamilyNames.put()));

                // use our current locale to find the correct name
                BOOL exists{ FALSE };
                UINT32 index;
                HRESULT hr;
                wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
                if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH))
                {
                    hr = localizedFamilyNames->FindLocaleName(localeName, &index, &exists);
                }
                if (SUCCEEDED(hr) && !exists)
                {
                    hr = localizedFamilyNames->FindLocaleName(L"en-us", &index, &exists);
                }
                if (!exists)
                {
                    // failed to find the correct locale, using the first one
                    index = 0;
                }

                // get the localized name
                UINT32 nameLength;
                THROW_IF_FAILED(localizedFamilyNames->GetStringLength(index, &nameLength));
                wchar_t* localizedName = new (std::nothrow) wchar_t[nameLength + 1];
                THROW_IF_FAILED(localizedFamilyNames->GetString(index, localizedName, nameLength + 1));

                // get the standard version of that font
                com_ptr<::IDWriteFont> font;
                THROW_IF_FAILED(fontFamily->GetFirstMatchingFont(DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL,
                                                                 DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL,
                                                                 DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL,
                                                                 font.put()));

                // add the font name to our list
                if (font.as<IDWriteFont1>()->IsMonospacedFont())
                {
                    monospaceFontList.emplace_back(localizedName);
                }
                fontList.emplace_back(std::move(localizedName));
            }
            catch (...)
            {
                LOG_CAUGHT_EXCEPTION();
                continue;
            }
        }

        // sort and save the lists
        std::sort(begin(fontList), end(fontList));

Review comment (suggestion):
just reattaching this comment here because moving the source around made it disappear.

![image](https://user-images.githubusercontent.com/189190/109343672-8fb29a00-7822-11eb-97cf-f3c622db1de9.png)


Code after:
                com_ptr<IDWriteLocalizedStrings> localizedFamilyNames;
                THROW_IF_FAILED(fontFamily->GetFamilyNames(localizedFamilyNames.put()));

                // construct a font entry for tracking
                if (const auto fontEntry{ _GetFont(localizedFamilyNames) })
                {
                    // check if the font is monospaced
                    try
                    {
                        com_ptr<IDWriteFont> font;
                        THROW_IF_FAILED(fontFamily->GetFirstMatchingFont(DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL,
                                                                         DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL,
                                                                         DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL,
                                                                         font.put()));

                        // add the font name to our list of monospace fonts
                        const auto castedFont{ font.try_as<IDWriteFont1>() };
                        if (castedFont && castedFont->IsMonospacedFont())
                        {
                            monospaceFontList.emplace_back(fontEntry);
                        }
                    }
                    CATCH_LOG();

                    // add the font name to our list of all fonts
                    fontList.emplace_back(std::move(fontEntry));
                }
            }
            CATCH_LOG();
        }

        // sort and save the lists
        std::sort(begin(fontList), end(fontList));
        _FontList = single_threaded_observable_vector<Editor::Font>(std::move(fontList));

        std::sort(begin(monospaceFontList), end(monospaceFontList));
        _MonospaceFontList = single_threaded_observable_vector<Editor::Font>(std::move(monospaceFontList));
    }
    CATCH_LOG();

    Editor::Font ProfileViewModel::_GetFont(com_ptr<IDWriteLocalizedStrings> localizedFamilyNames)
    {
        // used for the font's name as an identifier (i.e. text block's font family property)
        std::wstring nameID;
        UINT32 nameIDIndex;

        // used for the font's localized name
        std::wstring localizedName;
        UINT32 localizedNameIndex;

        // use our current locale to find the localized name