Repository: microsoft/terminal
File: src/renderer/dx/DxFontRenderData.cpp (C++)

Code before:
}

[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> DxFontRenderData::TextFormatWithAttribute(DWRITE_FONT_WEIGHT weight,
                                                                                                  DWRITE_FONT_STYLE style,
                                                                                                  DWRITE_FONT_STRETCH stretch)
{
    const auto textFormatIt = _textFormatMap.find(_ToMapKey(weight, style, stretch));
    if (textFormatIt == _textFormatMap.end())
    {
        DxFontInfo fontInfo = _defaultFontInfo;
        fontInfo.SetWeight(weight);
        fontInfo.SetStyle(style);
        fontInfo.SetStretch(stretch);

        // Create the font with the fractional pixel height size.
        // It should have an integer pixel width by our math.
        // Then below, apply the line spacing to the format to position the floating point pixel height characters
        // into a cell that has an integer pixel height leaving some padding above/below as necessary to round them out.
        std::wstring localeName = UserLocaleName();
        Microsoft::WRL::ComPtr<IDWriteTextFormat> textFormat;
        THROW_IF_FAILED(_BuildTextFormat(fontInfo, localeName).As(&textFormat));
        THROW_IF_FAILED(textFormat->SetLineSpacing(_lineSpacing.method, _lineSpacing.height, _lineSpacing.baseline));
        THROW_IF_FAILED(textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR));
        THROW_IF_FAILED(textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP));

        _textFormatMap.emplace(_ToMapKey(weight, style, stretch), std::move(textFormat));
        return textFormat;
    }
    else
    {
        return textFormatIt->second;
    }
}

[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> DxFontRenderData::FontFaceWithAttribute(DWRITE_FONT_WEIGHT weight,
                                                                                               DWRITE_FONT_STYLE style,
                                                                                               DWRITE_FONT_STRETCH stretch)
{
    const auto fontFaceIt = _fontFaceMap.find(_ToMapKey(weight, style, stretch));
    if (fontFaceIt == _fontFaceMap.end())
    {
        DxFontInfo fontInfo = _defaultFontInfo;
        fontInfo.SetWeight(weight);
        fontInfo.SetStyle(style);
        fontInfo.SetStretch(stretch);

        std::wstring fontLocaleName = UserLocaleName();
        Microsoft::WRL::ComPtr<IDWriteFontFace1> fontFace = fontInfo.ResolveFontFaceWithFallback(_dwriteFactory.Get(), fontLocaleName);

        _fontFaceMap.emplace(_ToMapKey(weight, style, stretch), std::move(fontFace));
        return fontFace;

Review comment (suggestion):
```suggestion
        _textFormatMap.emplace(_ToMapKey(weight, style, stretch), textFormat);
```

Code after:
}

[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteTextFormat> DxFontRenderData::TextFormatWithAttribute(DWRITE_FONT_WEIGHT weight,
                                                                                                  DWRITE_FONT_STYLE style,
                                                                                                  DWRITE_FONT_STRETCH stretch)
{
    const auto textFormatIt = _textFormatMap.find(_ToMapKey(weight, style, stretch));
    if (textFormatIt == _textFormatMap.end())
    {
        DxFontInfo fontInfo = _defaultFontInfo;
        fontInfo.SetWeight(weight);
        fontInfo.SetStyle(style);
        fontInfo.SetStretch(stretch);

        // Create the font with the fractional pixel height size.
        // It should have an integer pixel width by our math.
        // Then below, apply the line spacing to the format to position the floating point pixel height characters
        // into a cell that has an integer pixel height leaving some padding above/below as necessary to round them out.
        std::wstring localeName = UserLocaleName();
        Microsoft::WRL::ComPtr<IDWriteTextFormat> textFormat;
        THROW_IF_FAILED(_BuildTextFormat(fontInfo, localeName).As(&textFormat));
        THROW_IF_FAILED(textFormat->SetLineSpacing(_lineSpacing.method, _lineSpacing.height, _lineSpacing.baseline));
        THROW_IF_FAILED(textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR));
        THROW_IF_FAILED(textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP));

        _textFormatMap.emplace(_ToMapKey(weight, style, stretch), textFormat);
        return textFormat;
    }
    else
    {
        return textFormatIt->second;
    }
}

[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> DxFontRenderData::FontFaceWithAttribute(DWRITE_FONT_WEIGHT weight,
                                                                                               DWRITE_FONT_STYLE style,
                                                                                               DWRITE_FONT_STRETCH stretch)
{
    const auto fontFaceIt = _fontFaceMap.find(_ToMapKey(weight, style, stretch));
    if (fontFaceIt == _fontFaceMap.end())
    {
        DxFontInfo fontInfo = _defaultFontInfo;
        fontInfo.SetWeight(weight);
        fontInfo.SetStyle(style);
        fontInfo.SetStretch(stretch);

        std::wstring fontLocaleName = UserLocaleName();
        Microsoft::WRL::ComPtr<IDWriteFontFace1> fontFace = fontInfo.ResolveFontFaceWithFallback(_dwriteFactory.Get(), fontLocaleName);

        _fontFaceMap.emplace(_ToMapKey(weight, style, stretch), fontFace);
        return fontFace;