Skip to content

Commit aa8e129

Browse files
committed
dviread: Ignore font maps for subset TrueType w/o encoding.
As noted in the pdftex manual, > The *encodingfile* field may be omitted if you are sure that the font > resource has the correct built-in encoding. In general this option is > highly recommended, and it is *required* when subsetting a TrueType > font. This can be confirmed in a similar way to the previous commits, though instead of ignoring the line, pdflatex quits while attempting to embed the font.
1 parent 06270c9 commit aa8e129

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/matplotlib/dviread.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ def _parse_and_cache_line(self, line):
884884
if not line or line.startswith((b" ", b"%", b"*", b";", b"#")):
885885
return
886886
tfmname = basename = special = encodingfile = fontfile = None
887+
is_subsetted = is_t1 = is_truetype = False
887888
matches = re.finditer(br'"([^"]*)(?:"|$)|(\S+)', line)
888889
for match in matches:
889890
quoted, unquoted = match.groups()
@@ -902,6 +903,7 @@ def _parse_and_cache_line(self, line):
902903
encodingfile = word
903904
else:
904905
fontfile = word
906+
is_subsetted = True
905907
elif tfmname is None:
906908
tfmname = unquoted
907909
elif basename is None:
@@ -919,12 +921,15 @@ def _parse_and_cache_line(self, line):
919921

920922
# Verify some properties of the line that would cause it to be ignored
921923
# otherwise.
922-
is_t1 = False
923924
if fontfile is not None:
924-
if not fontfile.endswith((b".ttf", b".ttc", b".otf"):
925+
if fontfile.endswith((b".ttf", b".ttc")):
926+
is_truetype = True
927+
elif not fontfile.endswith(b".otf"):
925928
is_t1 = True
926929
elif basename is not None:
927930
is_t1 = True
931+
if is_truetype and is_subsetted and encodingfile is None:
932+
return
928933
if not is_t1 and ("slant" in effects or "extend" in effects):
929934
return
930935
if abs(effects.get("slant", 0)) > 1:

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ TeXfontA PSfontA2
1515
% Check SlantFont/ExtendFont
1616
%
1717
% Options are only allowed on T1 fonts (3 TrueType, 1 bitmap, and 1 T1 below).
18-
TeXfontB PSfontB1 "-0.1 SlantFont 1.2 ExtendFont" <fontB1.ttf
19-
TeXfontB PSfontB2 "-0.1 SlantFont" <fontB1.ttc
20-
TeXfontB PSfontB3 "1.2 ExtendFont" <fontB1.otf
18+
TeXfontB PSfontB1 "-0.1 SlantFont 1.2 ExtendFont" <fontB1.enc <fontB1.ttf
19+
TeXfontB PSfontB2 "-0.1 SlantFont" <fontB2.enc <fontB2.ttc
20+
TeXfontB PSfontB3 "1.2 ExtendFont" <fontB3.enc <fontB3.otf
2121
TeXfontB "0.1 SlantFont 1.2 ExtendFont"
2222
% Also, only within range ±1 / ±2.
2323
TeXfontB PSfontB4 "1.1 SlantFont 1.2 ExtendFont"
2424
TeXfontB PSfontB5 "0.1 SlantFont 2.2 ExtendFont"
2525
% This is the only one that works:
2626
TeXfontB PSfontB6
27+
%
28+
% Invalid TrueType entry.
29+
%
30+
% Must have encodingfile if subsetted.
31+
TeXfontC PSfontC1 <fontC1.ttf
32+
TeXfontC PSfontC2 <fontC2.ttc
33+
TeXfontC PSfontC3 <fontC3.ttf <8r.enc

lib/matplotlib/tests/test_dviread.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def test_PsfontsMap(monkeypatch):
5050
# Slant/Extend only works for T1 fonts.
5151
entry = fontmap[b'TeXfontB']
5252
assert entry.psname == b'PSfontB6'
53+
# Subsetted TrueType must have encoding.
54+
entry = fontmap[b'TeXfontC']
55+
assert entry.psname == b'PSfontC3'
5356
# Missing font
5457
with pytest.raises(KeyError, match='no-such-font'):
5558
fontmap[b'no-such-font']

0 commit comments

Comments
 (0)