diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 0a7c9ce26182..2bc6b818839e 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -307,3 +307,7 @@ The *quality*, *optimize*, and *progressive* keyword arguments to Such options should now be directly passed to Pillow using ``savefig(..., pil_kwargs={"quality": ..., "optimize": ..., "progressive": ...})``. + +``dviread.Encoding`` +~~~~~~~~~~~~~~~~~~~~ +This class was (mostly) broken and is deprecated. diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index e2896b4eaa09..7e3b600196bf 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -763,12 +763,11 @@ def _embedTeXFont(self, fontinfo): # Encoding (if needed) if fontinfo.encodingfile is not None: - enc = dviread.Encoding(fontinfo.encodingfile) - differencesArray = [Name(ch) for ch in enc] - differencesArray = [0] + differencesArray - fontdict['Encoding'] = \ - {'Type': Name('Encoding'), - 'Differences': differencesArray} + fontdict['Encoding'] = { + 'Type': Name('Encoding'), + 'Differences': [ + 0, *map(Name, dviread._parse_enc(fontinfo.encodingfile))], + } # If no file is specified, stop short if fontinfo.fontfile is None: diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index bdb7ee576c13..ecdeb32ed837 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -919,6 +919,7 @@ def _parse(self, file): encoding=encoding, filename=filename) +@cbook.deprecated("3.3") class Encoding: r""" Parses a \*.enc file referenced from a psfonts.map style file. @@ -988,8 +989,7 @@ def _parse_enc(path): The nth entry of the list is the PostScript glyph name of the nth glyph. """ - with open(path, encoding="ascii") as file: - no_comments = "\n".join(line.split("%")[0].rstrip() for line in file) + no_comments = re.sub("%.*", "", Path(path).read_text(encoding="ascii")) array = re.search(r"(?s)\[(.*)\]", no_comments).group(1) lines = [line for line in array.split() if line] if all(line.startswith("/") for line in lines):