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

Code before:
//   ignore the user set weight, otherwise setting the bold font axis
//   breaks the bold font attribute
// Arguments:
// - useUserWeight: boolean that tells us if we should use the user set weight
//   in the font axes
void DxFontRenderData::UseUserWeight(bool useUserWeight) noexcept
{
    _useUserWeight = useUserWeight;
}

// Routine Description:
// - Returns whether the set italic in the font axes
// Return Value:
// - True if the user set the italic axis to 1,
//   false if the italic axis is not present or the italic axis is set to 0
bool DxFontRenderData::DidUserSetItalic() const noexcept
{
    for (const auto& axisVal : _axesVector)
    {
        if (axisVal.axisTag == DWRITE_FONT_AXIS_TAG_ITALIC && axisVal.value == 1)
        {
            return true;
        }
    }
    return false;
}

// Routine Description:
// - Updates our internal map of font features with the given features
// - NOTE TO CALLER: Make sure to call _BuildFontRenderData after calling this for the feature changes
//   to take place
// Arguments:
// - features - the features to update our map with
void DxFontRenderData::_SetFeatures(const std::unordered_map<std::wstring_view, uint32_t>& features)
{
    // Populate the feature map with the standard list first
    std::unordered_map<DWRITE_FONT_FEATURE_TAG, uint32_t> featureMap{
        { DWRITE_MAKE_FONT_FEATURE_TAG('c', 'a', 'l', 't'), 1 }, // Contextual Alternates
        { DWRITE_MAKE_FONT_FEATURE_TAG('l', 'i', 'g', 'a'), 1 }, // Standard Ligatures
        { DWRITE_MAKE_FONT_FEATURE_TAG('c', 'l', 'i', 'g'), 1 }, // Contextual Ligatures
        { DWRITE_MAKE_FONT_FEATURE_TAG('k', 'e', 'r', 'n'), 1 } // Kerning
    };

    // Update our feature map with the provided features
    if (!features.empty())
    {
        for (const auto [tag, param] : features)
        {
            if (tag.length() == TAG_LENGTH)
            {
                featureMap.insert_or_assign(DWRITE_MAKE_FONT_FEATURE_TAG(til::at(tag, 0), til::at(tag, 1), til::at(tag, 2), til::at(tag, 3)), param);

Review comment (suggestion):
Consider eagerly computing and then caching this when the `_axesVector` is changed.

Code after:
//   ignore the user set weight, otherwise setting the bold font axis
//   breaks the bold font attribute
// Arguments:
// - inhibitUserWeight: boolean that tells us if we should use the user set weight
//   in the font axes
void DxFontRenderData::InhibitUserWeight(bool inhibitUserWeight) noexcept
{
    _inhibitUserWeight = inhibitUserWeight;
}

// Routine Description:
// - Returns whether the set italic in the font axes
// Return Value:
// - True if the user set the italic axis to 1,
//   false if the italic axis is not present or the italic axis is set to 0
bool DxFontRenderData::DidUserSetItalic() const noexcept
{
    return _didUserSetItalic;
}

// Routine Description:
// - Updates our internal map of font features with the given features
// - NOTE TO CALLER: Make sure to call _BuildFontRenderData after calling this for the feature changes
//   to take place
// Arguments:
// - features - the features to update our map with
void DxFontRenderData::_SetFeatures(const std::unordered_map<std::wstring_view, uint32_t>& features)
{
    // Populate the feature map with the standard list first
    std::unordered_map<DWRITE_FONT_FEATURE_TAG, uint32_t> featureMap{
        { DWRITE_MAKE_FONT_FEATURE_TAG('c', 'a', 'l', 't'), 1 }, // Contextual Alternates
        { DWRITE_MAKE_FONT_FEATURE_TAG('l', 'i', 'g', 'a'), 1 }, // Standard Ligatures
        { DWRITE_MAKE_FONT_FEATURE_TAG('c', 'l', 'i', 'g'), 1 }, // Contextual Ligatures
        { DWRITE_MAKE_FONT_FEATURE_TAG('k', 'e', 'r', 'n'), 1 } // Kerning
    };

    // Update our feature map with the provided features
    if (!features.empty())
    {
        for (const auto [tag, param] : features)
        {
            if (tag.length() == TAG_LENGTH)
            {
                featureMap.insert_or_assign(DWRITE_MAKE_FONT_FEATURE_TAG(til::at(tag, 0), til::at(tag, 1), til::at(tag, 2), til::at(tag, 3)), param);
            }
        }
        _didUserSetFeatures = true;
    }
    else
    {
        _didUserSetFeatures = false;