From a66b87f544dd78d867f5d6c7c2a35ac753fc7fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Sepp=C3=A4nen?= Date: Sun, 14 Jun 2015 11:36:18 +0300 Subject: [PATCH 1/2] Raise more useful error when tfm file is missing Fixes matplotlib/matplotlib#4475 --- lib/matplotlib/dviread.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index d6b085b2a831..d8ca414e0480 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -396,6 +396,8 @@ def _xxx(self, special): def _fnt_def(self, k, c, s, d, a, l, n): tfm = _tfmfile(n[-l:].decode('ascii')) + if tfm is None: + raise FileNotFoundError("missing font metrics file: %s" % tfm) if c != 0 and tfm.checksum != 0 and c != tfm.checksum: raise ValueError('tfm checksum mismatch: %s'%n) # It seems that the assumption behind the following check is incorrect: From d7edc1cc838451c79d0c474bdecd070993ce5ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Sepp=C3=A4nen?= Date: Sun, 14 Jun 2015 21:22:40 +0300 Subject: [PATCH 2/2] Fix font name in error message --- lib/matplotlib/dviread.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index d8ca414e0480..8b4945eacb31 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -395,9 +395,10 @@ def _xxx(self, special): 'debug') def _fnt_def(self, k, c, s, d, a, l, n): - tfm = _tfmfile(n[-l:].decode('ascii')) + fontname = n[-l:].decode('ascii') + tfm = _tfmfile(fontname) if tfm is None: - raise FileNotFoundError("missing font metrics file: %s" % tfm) + raise FileNotFoundError("missing font metrics file: %s" % fontname) if c != 0 and tfm.checksum != 0 and c != tfm.checksum: raise ValueError('tfm checksum mismatch: %s'%n) # It seems that the assumption behind the following check is incorrect: @@ -405,7 +406,7 @@ def _fnt_def(self, k, c, s, d, a, l, n): # raise ValueError, 'tfm design size mismatch: %d in dvi, %d in %s'%\ # (d, tfm.design_size, n) - vf = _vffile(n[-l:].decode('ascii')) + vf = _vffile(fontname) self.fonts[k] = DviFont(scale=s, tfm=tfm, texname=n, vf=vf)