Skip to content

Commit 976e779

Browse files
committed
Deprecate dviread.Encoding.
In backend_pdf, it previously worked coincidentally because it would create a list of glyph names with a "single" name of the form ``/foo/bar/baz/...`` which gets correctly interpreted as ``/foo /bar /baz``, but we may as well use the correct parser there too.
1 parent 7cbe104 commit 976e779

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
The ``dviread.Encoding`` class, which failed to split lists of glyph names
4+
properly, is deprecated.

lib/matplotlib/backends/backend_pdf.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,11 @@ def _embedTeXFont(self, fontinfo):
745745

746746
# Encoding (if needed)
747747
if fontinfo.encodingfile is not None:
748-
enc = dviread.Encoding(fontinfo.encodingfile)
749-
differencesArray = [Name(ch) for ch in enc]
750-
differencesArray = [0] + differencesArray
751-
fontdict['Encoding'] = \
752-
{'Type': Name('Encoding'),
753-
'Differences': differencesArray}
748+
enc = dviread._parse_enc(fontinfo.encodingfile)
749+
fontdict['Encoding'] = {
750+
'Type': Name('Encoding'),
751+
'Differences': [0, *map(Name, enc)],
752+
}
754753

755754
# If no file is specified, stop short
756755
if fontinfo.fontfile is None:

lib/matplotlib/dviread.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ def _parse(self, file):
923923
encoding=encoding, filename=filename)
924924

925925

926+
@cbook.deprecated("3.1")
926927
class Encoding(object):
927928
r"""
928929
Parses a \*.enc file referenced from a psfonts.map style file.
@@ -971,12 +972,7 @@ def _parse(file):
971972
return re.findall(br'/([^][{}<>\s]+)', data)
972973

973974

974-
# Note: this function should ultimately replace the Encoding class, which
975-
# appears to be mostly broken: because it uses b''.join(), there is no
976-
# whitespace left between glyph names (only slashes) so the final re.findall
977-
# returns a single string with all glyph names. However this does not appear
978-
# to bother backend_pdf, so that needs to be investigated more. (The fixed
979-
# version below is necessary for textpath/backend_svg, though.)
975+
@lru_cache()
980976
def _parse_enc(path):
981977
r"""
982978
Parses a \*.enc file referenced from a psfonts.map style file.

0 commit comments

Comments
 (0)