FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix multiple-encodings issue in dviread.PsfontsMap by jkseppan · Pull Request #438 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .map  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
32 changes: 17 additions & 15 deletions lib/matplotlib/dviread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -713,31 +713,33 @@ def _register(self, words):
There is some difference between <foo.pfb and <<bar.pfb in
subsetting, but I have no example of << in my TeX installation.
"""

# If the map file specifies multiple encodings for a font, we
# follow pdfTeX in choosing the last one specified. Such
# entries are probably mistakes but they have occurred.
# http://tex.stackexchange.com/questions/10826/
# http://article.gmane.org/gmane.comp.tex.pdftex/4914

texname, psname = words[:2]
effects, encodings, filename = '', [], None
effects, encoding, filename = '', None, None
for word in words[2:]:
if not word.startswith('<'):
effects = word
else:
word = word.lstrip('<')
if word.startswith('['):
encodings.append(word[1:])
elif word.endswith('.enc'):
encodings.append(word)
if word.startswith('[') or word.endswith('.enc'):
if encoding is not None:
matplotlib.verbose.report(
'Multiple encodings for %s = %s'
% (texname, psname), 'debug')
if word.startswith('['):
encoding = word[1:]
else:
encoding = word
else:
assert filename is None
filename = word

if len(encodings) > 1:
# TODO this is a stopgap workaround, need to handle this correctly
matplotlib.verbose.report('Multiple encodings for %s = %s, skipping'
% (texname, psname), 'debug')
return
elif len(encodings) == 1:
encoding, = encodings
else:
encoding = None

eff = effects.split()
effects = {}
try:
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/baseline_images/dviread/test.map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
% used by test_dviread.py
TeXfont1 PSfont1 <font1.pfb <font1.enc
TeXfont2 PSfont2 <font2.enc <font2.pfa
TeXfont3 PSfont3 "1.23 UnknownEffect" <[enc3.foo <font3.pfa
TeXfont4 PSfont4 "-0.1 SlantFont 2.2 ExtendFont" <font4.enc <font4.pfa
TeXfont5 PSfont5 <encoding1.enc <encoding2.enc <font5.pfb
TeXfont6 PSfont6
TeXfont7 PSfont7 <font7.enc
TeXfont8 PSfont8 <font8.pfb
TeXfont9 PSfont9 </absolute/font9.pfb
50 changes: 50 additions & 0 deletions lib/matplotlib/tests/test_dviread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from nose.tools import assert_equal
import matplotlib.dviread as dr
import os.path

original_find_tex_file = dr.find_tex_file

def setup():
dr.find_tex_file = lambda x: x

def teardown():
dr.find_tex_file = original_find_tex_file

def test_PsfontsMap():
filename = os.path.join(
os.path.dirname(__file__),
'baseline_images', 'dviread', 'test.map')
fontmap = dr.PsfontsMap(filename)
# Check all properties of a few fonts
for n in [1, 2, 3, 4, 5]:
key = 'TeXfont%d' % n
entry = fontmap[key]
assert_equal(entry.texname, key)
assert_equal(entry.psname, 'PSfont%d' % n)
if n not in [3, 5]:
assert_equal(entry.encoding, 'font%d.enc' % n)
elif n == 3:
assert_equal(entry.encoding, 'enc3.foo')
# We don't care about the encoding of TeXfont5, which specifies
# multiple encodings.
if n not in [1, 5]:
assert_equal(entry.filename, 'font%d.pfa' % n)
else:
assert_equal(entry.filename, 'font%d.pfb' % n)
if n == 4:
assert_equal(entry.effects, {'slant': -0.1, 'extend': 2.2})
else:
assert_equal(entry.effects, {})
# Some special cases
entry = fontmap['TeXfont6']
assert_equal(entry.filename, None)
assert_equal(entry.encoding, None)
entry = fontmap['TeXfont7']
assert_equal(entry.filename, None)
assert_equal(entry.encoding, 'font7.enc')
entry = fontmap['TeXfont8']
assert_equal(entry.filename, 'font8.pfb')
assert_equal(entry.encoding, None)
entry = fontmap['TeXfont9']
assert_equal(entry.filename, '/absolute/font9.pfb')


Back | FazBrowse Home | New Git URL