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

Code before:
                psfont = fontmap[self.texname]
            except LookupError as exc:
                try:
                    find_tex_file(f"{self.texname.decode('ascii')}.mf")
                except FileNotFoundError:
                    raise exc from None
                else:
                    self._path = Path(find_tex_file(
                        f"{self.texname.decode('ascii')}.600pk"))
            else:
                if psfont.filename is None:
                    raise ValueError("No usable font file found for {} ({}); "
                                     "the font may lack a Type-1 version"
                                     .format(psfont.psname.decode("ascii"),
                                             psfont.texname.decode("ascii")))
                self._path = Path(psfont.filename)
        return self._path

    @cached_property
    def subfont(self):
        return 0

    @cached_property
    def effects(self):
        return ({} if self.resolve_path().match("*.600pk") else
                PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects)

    def _index_dvi_to_freetype(self, idx):
        """Convert dvi glyph indices to FreeType ones."""
        # Glyphs indices stored in the dvi file map to FreeType glyph indices
        # (i.e., which can be passed to FT_Load_Glyph) in various ways:
        # - for xetex & luatex "native fonts", dvi indices are directly equal
        #   to FreeType indices.
        # - if pdftex.map specifies an ".enc" file for the font, that file maps
        #   dvi indices to Adobe glyph names, which can then be converted to
        #   FreeType glyph indices with FT_Get_Name_Index.
        # - if no ".enc" file is specified, then the font must be a Type 1
        #   font, and dvi indices directly index into the font's CharStrings
        #   vector.
        if self.texname.startswith(b"["):
            return idx
        if self._encoding is None:
            face = font_manager.get_font(self.resolve_path())
            psfont = PsfontsMap(find_tex_file("pdftex.map"))[self.texname]
            if psfont.encoding:
                self._encoding = [face.get_name_index(name)
                                  for name in _parse_enc(psfont.encoding)]
            else:
                self._encoding = face._get_type1_encoding_vector()
        return self._encoding[idx]


Review comment (suggestion):
Very optional: I would not use a ternary operator here because that makes it harder to read. It's rather a return-early situation. 

```suggestion
        if self.resolve_path().match("*.600pk"):
            return {}
        return PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects
```

Code after:
                psfont = fontmap[self.texname]
            except LookupError as exc:
                try:
                    find_tex_file(f"{self.texname.decode('ascii')}.mf")
                except FileNotFoundError:
                    raise exc from None
                else:
                    self._path = Path(find_tex_file(
                        f"{self.texname.decode('ascii')}.600pk"))
            else:
                if psfont.filename is None:
                    raise ValueError("No usable font file found for {} ({}); "
                                     "the font may lack a Type-1 version"
                                     .format(psfont.psname.decode("ascii"),
                                             psfont.texname.decode("ascii")))
                self._path = Path(psfont.filename)
        return self._path

    @cached_property
    def subfont(self):
        return 0

    @cached_property
    def effects(self):
        if self.resolve_path().match("*.600pk"):
            return {}
        return PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects

    def _index_dvi_to_freetype(self, idx):
        """Convert dvi glyph indices to FreeType ones."""
        # Glyphs indices stored in the dvi file map to FreeType glyph indices
        # (i.e., which can be passed to FT_Load_Glyph) in various ways:
        # - for xetex & luatex "native fonts", dvi indices are directly equal
        #   to FreeType indices.
        # - if pdftex.map specifies an ".enc" file for the font, that file maps
        #   dvi indices to Adobe glyph names, which can then be converted to
        #   FreeType glyph indices with FT_Get_Name_Index.
        # - if no ".enc" file is specified, then the font must be a Type 1
        #   font, and dvi indices directly index into the font's CharStrings
        #   vector.
        if self.texname.startswith(b"["):
            return idx
        if self._encoding is None:
            face = font_manager.get_font(self.resolve_path())
            psfont = PsfontsMap(find_tex_file("pdftex.map"))[self.texname]
            if psfont.encoding:
                self._encoding = [face.get_name_index(name)
                                  for name in _parse_enc(psfont.encoding)]
            else:
                self._encoding = face._get_type1_encoding_vector()
        return self._encoding[idx]