Skip to content

Commit ab74d64

Browse files
committed
Use the first valid line when parsing pdftex.map.
This can be tested by placing two lines with the same `tfmname`, but different `psname` in a `pdftex.map`: ``` cmr12 CMR10 <cmr12.pfb cmr12 CMR12 <cmr12.pfb ``` and then running `TEXFONTMAPS=/path/to/pdftex.map pdflatex` on a file using Computer Modern. It will warn about the second line, and embed `CMR10` as the name in the resulting PDF.
1 parent f4c518e commit ab74d64

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/matplotlib/dviread.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,19 @@ def __new__(cls, filename):
828828
# store the unparsed lines (keyed by the first word, which is the
829829
# texname) and parse them on-demand.
830830
with open(filename, 'rb') as file:
831-
self._unparsed = {line.split(b' ', 1)[0]: line for line in file}
831+
self._unparsed = {}
832+
for line in file:
833+
tfmname = line.split(b' ', 1)[0]
834+
self._unparsed.setdefault(tfmname, []).append(line)
832835
self._parsed = {}
833836
return self
834837

835838
def __getitem__(self, texname):
836839
assert isinstance(texname, bytes)
837840
if texname in self._unparsed:
838-
self._parse_and_cache_line(self._unparsed.pop(texname))
841+
for line in self._unparsed.pop(texname):
842+
if self._parse_and_cache_line(line):
843+
break
839844
try:
840845
return self._parsed[texname]
841846
except KeyError:
@@ -920,6 +925,7 @@ def _parse_and_cache_line(self, line):
920925
self._parsed[tfmname] = PsFont(
921926
texname=tfmname, psname=basename, effects=effects,
922927
encoding=encodingfile, filename=fontfile)
928+
return True
923929

924930

925931
# Note: this function should ultimately replace the Encoding class, which

lib/matplotlib/tests/baseline_images/dviread/test.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ TeXfont6 PSfont6
88
TeXfont7 PSfont7 < font7.enc
99
TeXfont8 PSfont8 <<font8.pfb
1010
TeXfont9 </absolute/font9.pfb
11+
% Only the first of a duplicate key is used.
12+
TeXfontA PSfontA1
13+
TeXfontA PSfontA2

lib/matplotlib/tests/test_dviread.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def test_PsfontsMap(monkeypatch):
4444
entry = fontmap[b'TeXfont9']
4545
assert entry.psname == b'TeXfont9'
4646
assert entry.filename == b'/absolute/font9.pfb'
47+
# First of duplicates only.
48+
entry = fontmap[b'TeXfontA']
49+
assert entry.psname == b'PSfontA1'
4750
# Missing font
4851
with pytest.raises(KeyError, match='no-such-font'):
4952
fontmap[b'no-such-font']

0 commit comments

Comments
 (0)