Repository: microsoft/terminal
File: src/renderer/base/FontInfoBase.cpp (C++)

Code before:
           _fDefaultRasterSetFromEngine == other._fDefaultRasterSetFromEngine;
}

unsigned char FontInfoBase::GetFamily() const noexcept
{
    return _family;
}

// When the default raster font is forced set from the engine, this is how we differentiate it from a simple apply.
// Default raster font is internally represented as a blank face name and zeros for weight, family, and size. This is
// the hint for the engine to use whatever comes back from GetStockObject(OEM_FIXED_FONT) (at least in the GDI world).
bool FontInfoBase::WasDefaultRasterSetFromEngine() const noexcept
{
    return _fDefaultRasterSetFromEngine;
}

unsigned int FontInfoBase::GetWeight() const noexcept
{
    return _weight;
}

const std::wstring& FontInfoBase::GetFaceName() const noexcept
{
    return _faceName;
}

unsigned int FontInfoBase::GetCodePage() const noexcept
{
    return _codePage;
}

// Method Description:
// - Populates a fixed-length **null-terminated** buffer with the name of this font, truncating it as necessary.
//   Positions within the buffer that are not filled by the font name are zeroed.
// Arguments:
// - buffer: the buffer into which to copy characters
// - size: the size of buffer
void FontInfoBase::FillLegacyNameBuffer(wchar_t (&buffer)[LF_FACESIZE]) const noexcept
{
    const auto toCopy = std::min(std::size(buffer) - 1, _faceName.size());
    const auto last = std::copy_n(_faceName.data(), toCopy, &buffer[0]);
    *last = L'\0';
}

// NOTE: this method is intended to only be used from the engine itself to respond what font it has chosen.
void FontInfoBase::SetFromEngine(const std::wstring_view& faceName, const unsigned char family, const unsigned int weight, const bool fSetDefaultRasterFont) noexcept
{
    _faceName = faceName;
    _family = family;
    _weight = weight;
    _fDefaultRasterSetFromEngine = fSetDefaultRasterFont;

Review comment (suggestion):
This change allows you to call the technically more correct and safer `.c_str()` on the return value instead of hoping that the string_view refers to a null terminated string. (This could be changed in the UIA and GDI renderers. I'm making direct use of this safety in the AtlasEngine.)

Code after:
    return _faceName == other._faceName &&
           _weight == other._weight &&
           _family == other._family &&
           _codePage == other._codePage &&
           _fDefaultRasterSetFromEngine == other._fDefaultRasterSetFromEngine;
}

unsigned char FontInfoBase::GetFamily() const noexcept
{
    return _family;
}

// When the default raster font is forced set from the engine, this is how we differentiate it from a simple apply.
// Default raster font is internally represented as a blank face name and zeros for weight, family, and size. This is
// the hint for the engine to use whatever comes back from GetStockObject(OEM_FIXED_FONT) (at least in the GDI world).
bool FontInfoBase::WasDefaultRasterSetFromEngine() const noexcept
{
    return _fDefaultRasterSetFromEngine;
}

unsigned int FontInfoBase::GetWeight() const noexcept
{
    return _weight;
}

const std::wstring& FontInfoBase::GetFaceName() const noexcept
{
    return _faceName;
}

unsigned int FontInfoBase::GetCodePage() const noexcept
{
    return _codePage;
}

// Method Description:
// - Populates a fixed-length **null-terminated** buffer with the name of this font, truncating it as necessary.
//   Positions within the buffer that are not filled by the font name are zeroed.
// Arguments:
// - buffer: the buffer into which to copy characters
// - size: the size of buffer
void FontInfoBase::FillLegacyNameBuffer(wchar_t (&buffer)[LF_FACESIZE]) const noexcept
{
    const auto toCopy = std::min(std::size(buffer) - 1, _faceName.size());
    const auto last = std::copy_n(_faceName.data(), toCopy, &buffer[0]);
    *last = L'\0';
}

// NOTE: this method is intended to only be used from the engine itself to respond what font it has chosen.
void FontInfoBase::SetFromEngine(const std::wstring_view& faceName,
                                 const unsigned char family,