|
33 | 33 | import numpy as np |
34 | 34 | import struct |
35 | 35 | import sys |
| 36 | +import textwrap |
36 | 37 | import os |
37 | 38 |
|
38 | 39 | if six.PY3: |
@@ -798,16 +799,33 @@ class PsfontsMap(object): |
798 | 799 | while the pdf-related files perhaps only avoid the "Base 14" pdf |
799 | 800 | fonts. But the user may have configured these files differently. |
800 | 801 | """ |
801 | | - __slots__ = ('_font',) |
| 802 | + __slots__ = ('_font', '_filename') |
802 | 803 |
|
803 | 804 | def __init__(self, filename): |
804 | 805 | self._font = {} |
| 806 | + self._filename = filename |
| 807 | + if six.PY3 and isinstance(filename, bytes): |
| 808 | + self._filename = filename.decode('ascii', errors='replace') |
805 | 809 | with open(filename, 'rt') as file: |
806 | 810 | self._parse(file) |
807 | 811 |
|
808 | 812 | def __getitem__(self, texname): |
809 | 813 | assert(isinstance(texname, bytes)) |
810 | | - result = self._font[texname] |
| 814 | + try: |
| 815 | + result = self._font[texname] |
| 816 | + except KeyError: |
| 817 | + matplotlib.verbose.report(textwrap.fill |
| 818 | + ('A PostScript file for the font whose TeX name is "%s" ' |
| 819 | + 'could not be found in the file "%s". The dviread module ' |
| 820 | + 'can only handle fonts that have an associated PostScript ' |
| 821 | + 'font file. ' |
| 822 | + 'This problem can often be solved by installing ' |
| 823 | + 'a suitable PostScript font package in your (TeX) ' |
| 824 | + 'package manager.' % (texname.decode('ascii'), |
| 825 | + self._filename), |
| 826 | + break_on_hyphens=False, break_long_words=False), |
| 827 | + 'helpful') |
| 828 | + raise |
811 | 829 | fn, enc = result.filename, result.encoding |
812 | 830 | if fn is not None and not fn.startswith(b'/'): |
813 | 831 | fn = find_tex_file(fn) |
|
0 commit comments