Repository: matplotlib/matplotlib
File: lib/matplotlib/_mathtext.py (Python)

Code before:

# Maps font family names to the FontConstantBase subclass to use
_font_constant_mapping = {
    'DejaVu Sans': DejaVuSansFontConstants,
    'DejaVu Sans Mono': DejaVuSansFontConstants,
    'DejaVu Serif': DejaVuSerifFontConstants,
    'cmb10': ComputerModernFontConstants,
    'cmex10': ComputerModernFontConstants,
    'cmmi10': ComputerModernFontConstants,
    'cmr10': ComputerModernFontConstants,
    'cmss10': ComputerModernFontConstants,
    'cmsy10': ComputerModernFontConstants,
    'cmtt10': ComputerModernFontConstants,
    'STIXGeneral': STIXFontConstants,
    'STIXNonUnicode': STIXFontConstants,
    'STIXSizeFiveSym': STIXFontConstants,
    'STIXSizeFourSym': STIXFontConstants,
    'STIXSizeThreeSym': STIXFontConstants,
    'STIXSizeTwoSym': STIXFontConstants,
    'STIXSizeOneSym': STIXFontConstants,
    # Map the fonts we used to ship, just for good measure
    'Bitstream Vera Sans': DejaVuSansFontConstants,
    'Bitstream Vera': DejaVuSansFontConstants,
    }


def _get_font_constant_set(state: ParserState) -> type[FontConstantsBase]:
    constants = _font_constant_mapping.get(
        state.fontset._get_font(state.font).family_name, FontConstantsBase)
    # STIX sans isn't really its own fonts, just different code points
    # in the STIX fonts, so we have to detect this one separately.
    if (constants is STIXFontConstants and
            isinstance(state.fontset, StixSansFonts)):
        return STIXSansFontConstants
    return constants


class Node:
    """A node in the TeX box model."""

    def __init__(self) -> None:
        self.size = 0

    def __repr__(self) -> str:
        return type(self).__name__

    def get_kerning(self, next: Node | None) -> float:
        return 0.0

    def shrink(self) -> None:
        """

Review comment (suggestion):
This should have said FontForge, not FreeType; I'll fix it in a followup.

Code after:
    # have been increased by the same factor to compensate.
    script_space = 0.132861328125
    delta = 0.132861328125
    delta_slanted = 0.3
    delta_integral = 0.3
    _x_height = 451470
    # These all come from the cmsy10.tfm metrics, divided by the design xheight from
    # there, since we multiply these values by the scaled xheight later.
    supdrop = 404864 / _x_height
    subdrop = 52429 / _x_height
    sup1 = 432949 / _x_height
    sub1 = 157286 / _x_height
    sub2 = 259226 / _x_height
    num1 = 709370 / _x_height
    num2 = 412858 / _x_height
    num3 = 465286 / _x_height
    denom1 = 719272 / _x_height
    denom2 = 361592 / _x_height


class STIXFontConstants(FontConstantsBase):
    script_space = 0.1
    delta = 0.05
    delta_slanted = 0.3
    delta_integral = 0.3
    # These values are extracted from the TeX table of STIXGeneral.ttf using FreeType,
    # and then divided by design xheight, since we multiply these values by the scaled
    # xheight later.
    _x_height = 450
    supdrop = 386 / _x_height
    subdrop = 50.0002 / _x_height
    sup1 = 413 / _x_height
    sub1 = 150 / _x_height
    sub2 = 309 / _x_height
    num1 = 747 / _x_height
    num2 = 424 / _x_height
    num3 = 474 / _x_height
    denom1 = 756 / _x_height
    denom2 = 375 / _x_height


class STIXSansFontConstants(STIXFontConstants):
    script_space = 0.05
    delta_slanted = 0.6
    delta_integral = 0.3


class DejaVuSerifFontConstants(FontConstantsBase):
    # These values are extracted from the TeX table of DejaVuSerif.ttf using FreeType,
    # and then divided by design xheight, since we multiply these values by the scaled
    # xheight later.