Repository: matplotlib/matplotlib
File: lib/matplotlib/backends/backend_pdf.py (Python)

Code before:
            raise ValueError(
                "No usable font file found for {} (TeX: {}); "
                "the font may lack a Type-1 version"
                .format(psfont.psname, dvifont.texname))

        # The font dictionary is the top-level object describing a font
        fontdictObject = self.reserveObject('font dictionary')
        fontdict = {
            'Type':      Name('Font'),
            'Subtype':   Name('Type1'),
        }

        # Read the font file and apply any encoding changes and effects
        t1font = _type1font.Type1Font(psfont.filename)
        if psfont.encoding is not None:
            t1font = t1font.with_encoding(
                {i: c for i, c in enumerate(dviread._parse_enc(psfont.encoding))}
            )
        if psfont.effects:
            t1font = t1font.transform(psfont.effects)

        # Reduce the font to only the glyphs used in the document, get the encoding
        # for that subset, and compute various properties based on the encoding.
        charmap = self._character_tracker.used[dvifont.fname][0]
        chars = {
            # DVI fonts always map single glyph to single character.
            ord(self._character_tracker.subset_to_unicode(dvifont.fname, 0, ccode))
            for ccode in charmap
        }
        t1font = t1font.subset(chars, self._get_subset_prefix(charmap.values()))
        fontdict['BaseFont'] = Name(t1font.prop['FontName'])
        # createType1Descriptor writes the font data as a side effect
        fontdict['FontDescriptor'] = self.createType1Descriptor(t1font)
        encoding = t1font.prop['Encoding']
        fontdict['Encoding'] = self._generate_encoding(encoding)
        fc = fontdict['FirstChar'] = min(encoding.keys(), default=0)
        lc = fontdict['LastChar'] = max(encoding.keys(), default=255)
        # Convert glyph widths from TeX 12.20 fixed point to 1/1000 text space units
        font_metrics = dvifont._metrics
        widths = [(1000 * glyph_metrics.tex_width) >> 20
                  if (glyph_metrics := font_metrics.get_metrics(char)) else 0
                  for char in range(fc, lc + 1)]
        fontdict['Widths'] = widthsObject = self.reserveObject('glyph widths')
        self.writeObject(widthsObject, widths)
        self.writeObject(fontdictObject, fontdict)
        return fontdictObject

    def _generate_encoding(self, encoding):
        prev = -2
        result = []
        for code, name in sorted(encoding.items()):

Review comment (suggestion):
I guess that should be "type 1 fonts" in the comment (as future xe/luatex support will mean dvi will also be able to embed ttf).

Code after:
            raise ValueError(
                "No usable font file found for {} (TeX: {}); "
                "the font may lack a Type-1 version"
                .format(psfont.psname, dvifont.texname))

        # The font dictionary is the top-level object describing a font
        fontdictObject = self.reserveObject('font dictionary')
        fontdict = {
            'Type':      Name('Font'),
            'Subtype':   Name('Type1'),
        }

        # Read the font file and apply any encoding changes and effects
        t1font = _type1font.Type1Font(psfont.filename)
        if psfont.encoding is not None:
            t1font = t1font.with_encoding(
                {i: c for i, c in enumerate(dviread._parse_enc(psfont.encoding))}
            )
        if psfont.effects:
            t1font = t1font.transform(psfont.effects)

        # Reduce the font to only the glyphs used in the document, get the encoding
        # for that subset, and compute various properties based on the encoding.
        charmap = self._character_tracker.used[dvifont.fname][0]
        chars = {
            # DVI type 1 fonts always map single glyph to single character.
            ord(self._character_tracker.subset_to_unicode(dvifont.fname, 0, ccode))
            for ccode in charmap
        }
        t1font = t1font.subset(chars, self._get_subset_prefix(charmap.values()))
        fontdict['BaseFont'] = Name(t1font.prop['FontName'])
        # createType1Descriptor writes the font data as a side effect
        fontdict['FontDescriptor'] = self.createType1Descriptor(t1font)
        encoding = t1font.prop['Encoding']
        fontdict['Encoding'] = self._generate_encoding(encoding)
        fc = fontdict['FirstChar'] = min(encoding.keys(), default=0)
        lc = fontdict['LastChar'] = max(encoding.keys(), default=255)
        # Convert glyph widths from TeX 12.20 fixed point to 1/1000 text space units
        font_metrics = dvifont._metrics
        widths = [(1000 * glyph_metrics.tex_width) >> 20
                  if (glyph_metrics := font_metrics.get_metrics(char)) else 0
                  for char in range(fc, lc + 1)]
        fontdict['Widths'] = widthsObject = self.reserveObject('glyph widths')
        self.writeObject(widthsObject, widths)
        self.writeObject(fontdictObject, fontdict)
        return fontdictObject

    def _generate_encoding(self, encoding):
        prev = -2
        result = []
        for code, name in sorted(encoding.items()):