Skip to content

Commit cfe40d3

Browse files
committed
Merge pull request matplotlib#438 from jkseppan/issue-191
Fix multiple-encodings issue in dviread.PsfontsMap
2 parents b0dcaa0 + 3f82c55 commit cfe40d3

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

lib/matplotlib/dviread.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -713,31 +713,33 @@ def _register(self, words):
713713
There is some difference between <foo.pfb and <<bar.pfb in
714714
subsetting, but I have no example of << in my TeX installation.
715715
"""
716+
717+
# If the map file specifies multiple encodings for a font, we
718+
# follow pdfTeX in choosing the last one specified. Such
719+
# entries are probably mistakes but they have occurred.
720+
# http://tex.stackexchange.com/questions/10826/
721+
# http://article.gmane.org/gmane.comp.tex.pdftex/4914
722+
716723
texname, psname = words[:2]
717-
effects, encodings, filename = '', [], None
724+
effects, encoding, filename = '', None, None
718725
for word in words[2:]:
719726
if not word.startswith('<'):
720727
effects = word
721728
else:
722729
word = word.lstrip('<')
723-
if word.startswith('['):
724-
encodings.append(word[1:])
725-
elif word.endswith('.enc'):
726-
encodings.append(word)
730+
if word.startswith('[') or word.endswith('.enc'):
731+
if encoding is not None:
732+
matplotlib.verbose.report(
733+
'Multiple encodings for %s = %s'
734+
% (texname, psname), 'debug')
735+
if word.startswith('['):
736+
encoding = word[1:]
737+
else:
738+
encoding = word
727739
else:
728740
assert filename is None
729741
filename = word
730742

731-
if len(encodings) > 1:
732-
# TODO this is a stopgap workaround, need to handle this correctly
733-
matplotlib.verbose.report('Multiple encodings for %s = %s, skipping'
734-
% (texname, psname), 'debug')
735-
return
736-
elif len(encodings) == 1:
737-
encoding, = encodings
738-
else:
739-
encoding = None
740-
741743
eff = effects.split()
742744
effects = {}
743745
try:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
% used by test_dviread.py
2+
TeXfont1 PSfont1 <font1.pfb <font1.enc
3+
TeXfont2 PSfont2 <font2.enc <font2.pfa
4+
TeXfont3 PSfont3 "1.23 UnknownEffect" <[enc3.foo <font3.pfa
5+
TeXfont4 PSfont4 "-0.1 SlantFont 2.2 ExtendFont" <font4.enc <font4.pfa
6+
TeXfont5 PSfont5 <encoding1.enc <encoding2.enc <font5.pfb
7+
TeXfont6 PSfont6
8+
TeXfont7 PSfont7 <font7.enc
9+
TeXfont8 PSfont8 <font8.pfb
10+
TeXfont9 PSfont9 </absolute/font9.pfb

lib/matplotlib/tests/test_dviread.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from nose.tools import assert_equal
2+
import matplotlib.dviread as dr
3+
import os.path
4+
5+
original_find_tex_file = dr.find_tex_file
6+
7+
def setup():
8+
dr.find_tex_file = lambda x: x
9+
10+
def teardown():
11+
dr.find_tex_file = original_find_tex_file
12+
13+
def test_PsfontsMap():
14+
filename = os.path.join(
15+
os.path.dirname(__file__),
16+
'baseline_images', 'dviread', 'test.map')
17+
fontmap = dr.PsfontsMap(filename)
18+
# Check all properties of a few fonts
19+
for n in [1, 2, 3, 4, 5]:
20+
key = 'TeXfont%d' % n
21+
entry = fontmap[key]
22+
assert_equal(entry.texname, key)
23+
assert_equal(entry.psname, 'PSfont%d' % n)
24+
if n not in [3, 5]:
25+
assert_equal(entry.encoding, 'font%d.enc' % n)
26+
elif n == 3:
27+
assert_equal(entry.encoding, 'enc3.foo')
28+
# We don't care about the encoding of TeXfont5, which specifies
29+
# multiple encodings.
30+
if n not in [1, 5]:
31+
assert_equal(entry.filename, 'font%d.pfa' % n)
32+
else:
33+
assert_equal(entry.filename, 'font%d.pfb' % n)
34+
if n == 4:
35+
assert_equal(entry.effects, {'slant': -0.1, 'extend': 2.2})
36+
else:
37+
assert_equal(entry.effects, {})
38+
# Some special cases
39+
entry = fontmap['TeXfont6']
40+
assert_equal(entry.filename, None)
41+
assert_equal(entry.encoding, None)
42+
entry = fontmap['TeXfont7']
43+
assert_equal(entry.filename, None)
44+
assert_equal(entry.encoding, 'font7.enc')
45+
entry = fontmap['TeXfont8']
46+
assert_equal(entry.filename, 'font8.pfb')
47+
assert_equal(entry.encoding, None)
48+
entry = fontmap['TeXfont9']
49+
assert_equal(entry.filename, '/absolute/font9.pfb')
50+

0 commit comments

Comments
 (0)