Skip to content

Commit 017922c

Browse files
committed
Small style fix + microoptimization of _parse_enc.
1 parent 1330753 commit 017922c

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lib/matplotlib/backends/backend_pdf.py

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

764764
# Encoding (if needed)
765765
if fontinfo.encodingfile is not None:
766-
enc = dviread._parse_enc(fontinfo.encodingfile)
767-
differencesArray = [Name(ch) for ch in enc]
768-
differencesArray = [0] + differencesArray
769-
fontdict['Encoding'] = \
770-
{'Type': Name('Encoding'),
771-
'Differences': differencesArray}
766+
fontdict['Encoding'] = {
767+
'Type': Name('Encoding'),
768+
'Differences': [
769+
0, *map(Name, dviread._parse_enc(fontinfo.encodingfile))],
770+
}
772771

773772
# If no file is specified, stop short
774773
if fontinfo.fontfile is None:

lib/matplotlib/dviread.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,7 @@ def _parse_enc(path):
989989
The nth entry of the list is the PostScript glyph name of the nth
990990
glyph.
991991
"""
992-
with open(path, encoding="ascii") as file:
993-
no_comments = "\n".join(line.split("%")[0].rstrip() for line in file)
992+
no_comments = re.sub("%.*", "", Path(path).read_text(encoding="ascii"))
994993
array = re.search(r"(?s)\[(.*)\]", no_comments).group(1)
995994
lines = [line for line in array.split() if line]
996995
if all(line.startswith("/") for line in lines):

0 commit comments

Comments
 (0)