Repository: microsoft/terminal
File: src/buffer/out/textBuffer.cpp (C++)

Code before:
            if (inserted)
            {
                const auto red = static_cast<int>(GetRValue(color));
                const auto green = static_cast<int>(GetGValue(color));
                const auto blue = static_cast<int>(GetBValue(color));
                fmt::format_to(std::back_inserter(colorTableBuilder), FMT_COMPILE("\\red{}\\green{}\\blue{};"), red, green, blue);
            }
            return it->second;
        };

        // content
        std::string contentBuilder;

        // \viewkindN: View mode of the document to be used. N=4 specifies that the document is in Normal view. (maybe unnecessary?)
        // \ucN: Number of unicode fallback characters after each codepoint. (global)
        contentBuilder += "\\viewkind4\\uc1";

        // paragraph styles
        // \pard: paragraph description
        // \slmultN: line-spacing multiple
        // \fN: font to be used for the paragraph, where N is the font index in the font table
        contentBuilder += "\\pard\\slmult1\\f0";

        // \fsN: specifies font size in half-points. E.g. \fs20 results in a font
        // size of 10 pts. That's why, font size is multiplied by 2 here.
        fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\fs{}"), std::to_string(2 * fontHeightPoints));

        // Set the background color for the page. But the standard way (\cbN) to do
        // this isn't supported in Word. However, the following control words sequence
        // works in Word (and other RTF editors also) for applying the text background
        // color. See: Spec 1.9.1, Pg. 23.
        fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\chshdng0\\chcbpat{}"), getColorTableIndex(backgroundColor));

        for (auto iRow = req.beg.y; iRow <= req.end.y; ++iRow)
        {
            const auto& row = GetRowByOffset(iRow);
            const auto [rowBeg, rowEnd, addLineBreak] = _RowCopyHelper(req, iRow, row);
            const auto rowBegU16 = gsl::narrow_cast<uint16_t>(rowBeg);
            const auto rowEndU16 = gsl::narrow_cast<uint16_t>(rowEnd);
            const auto runs = row.Attributes().slice(rowBegU16, rowEndU16).runs();

            auto x = rowBegU16;
            for (auto& [attr, length] : runs)
            {
                const auto nextX = gsl::narrow_cast<uint16_t>(x + length);
                const auto [fg, bg, ul] = GetAttributeColors(attr);
                const auto fgIdx = getColorTableIndex(fg);
                const auto bgIdx = getColorTableIndex(bg);
                const auto ulIdx = getColorTableIndex(ul);
                const auto ulStyle = attr.GetUnderlineStyle();


Review comment (suggestion):
FYI the type of `fontHeightPoints` is `int`, so there should be no difference in behavior here.

Code after:
            if (inserted)
            {
                const auto red = static_cast<int>(GetRValue(color));
                const auto green = static_cast<int>(GetGValue(color));
                const auto blue = static_cast<int>(GetBValue(color));
                fmt::format_to(std::back_inserter(colorTableBuilder), FMT_COMPILE("\\red{}\\green{}\\blue{};"), red, green, blue);
            }
            return it->second;
        };

        // content
        std::string contentBuilder;

        // \viewkindN: View mode of the document to be used. N=4 specifies that the document is in Normal view. (maybe unnecessary?)
        // \ucN: Number of unicode fallback characters after each codepoint. (global)
        contentBuilder += "\\viewkind4\\uc1";

        // paragraph styles
        // \pard: paragraph description
        // \slmultN: line-spacing multiple
        // \fN: font to be used for the paragraph, where N is the font index in the font table
        contentBuilder += "\\pard\\slmult1\\f0";

        // \fsN: specifies font size in half-points. E.g. \fs20 results in a font
        // size of 10 pts. That's why, font size is multiplied by 2 here.
        fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\fs{}"), 2 * fontHeightPoints);

        // Set the background color for the page. But the standard way (\cbN) to do
        // this isn't supported in Word. However, the following control words sequence
        // works in Word (and other RTF editors also) for applying the text background
        // color. See: Spec 1.9.1, Pg. 23.
        fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\chshdng0\\chcbpat{}"), getColorTableIndex(backgroundColor));

        for (auto iRow = req.beg.y; iRow <= req.end.y; ++iRow)
        {
            const auto& row = GetRowByOffset(iRow);
            const auto [rowBeg, rowEnd, addLineBreak] = _RowCopyHelper(req, iRow, row);
            const auto rowBegU16 = gsl::narrow_cast<uint16_t>(rowBeg);
            const auto rowEndU16 = gsl::narrow_cast<uint16_t>(rowEnd);
            const auto runs = row.Attributes().slice(rowBegU16, rowEndU16).runs();

            auto x = rowBegU16;
            for (auto& [attr, length] : runs)
            {
                const auto nextX = gsl::narrow_cast<uint16_t>(x + length);
                const auto [fg, bg, ul] = GetAttributeColors(attr);
                const auto fgIdx = getColorTableIndex(fg);
                const auto bgIdx = getColorTableIndex(bg);
                const auto ulIdx = getColorTableIndex(ul);
                const auto ulStyle = attr.GetUnderlineStyle();