Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c820a5d

Browse filesBrowse files
committed
Give a better error message on missing PostScript fonts
For #4167; does not fix the problem, as it would need supporting a whole different kind of font, but gives a more useful error message.
1 parent dcc9eff commit c820a5d
Copy full SHA for c820a5d

File tree

Expand file treeCollapse file tree

4 files changed

+68
-1
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+68
-1
lines changed

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,12 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
18651865
pdfname = self.file.fontName(dvifont.texname)
18661866
if dvifont.texname not in self.file.dviFontInfo:
18671867
psfont = self.tex_font_mapping(dvifont.texname)
1868+
if psfont.filename is None:
1869+
self.file.broken = True
1870+
raise ValueError(
1871+
("No usable font file found for %s (%s). "
1872+
"The font may lack a Type-1 version.")
1873+
% (psfont.psname, dvifont.texname))
18681874
self.file.dviFontInfo[dvifont.texname] = Bunch(
18691875
fontfile=psfont.filename,
18701876
basefont=psfont.psname,

‎lib/matplotlib/tests/test_backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pdf.py
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77

88
import io
99
import os
10+
import tempfile
11+
12+
try:
13+
from unittest.mock import patch
14+
except ImportError:
15+
from mock import patch
16+
from nose.tools import raises
1017

1118
import numpy as np
12-
from matplotlib import cm, rcParams
19+
from matplotlib import checkdep_tex, cm, rcParams
1320
from matplotlib.backends.backend_pdf import PdfPages
1421
from matplotlib import pyplot as plt
1522
from matplotlib.testing.decorators import (image_comparison, knownfailureif,
1623
cleanup)
24+
from matplotlib import dviread
1725

1826
if 'TRAVIS' not in os.environ:
1927
@image_comparison(baseline_images=['pdf_use14corefonts'],
@@ -29,6 +37,10 @@ def test_use14corefonts():
2937
and containing some French characters and the euro symbol:
3038
"Merci pépé pour les 10 €"'''
3139

40+
needs_tex = knownfailureif(
41+
not checkdep_tex(),
42+
"This test needs a TeX installation")
43+
3244

3345
@cleanup
3446
def test_type42():
@@ -132,3 +144,19 @@ def test_grayscale_alpha():
132144
ax.imshow(dd, interpolation='none', cmap='gray_r')
133145
ax.set_xticks([])
134146
ax.set_yticks([])
147+
148+
149+
@cleanup
150+
@needs_tex
151+
@raises(ValueError)
152+
@patch('matplotlib.dviread.PsfontsMap.__getitem__')
153+
def test_missing_psfont(mock):
154+
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
155+
psfont = dviread.PsFont(texname='texfont', psname='Some Font',
156+
effects=None, encoding=None, filename=None)
157+
mock.configure_mock(return_value=psfont)
158+
rcParams['text.usetex'] = True
159+
fig, ax = plt.subplots()
160+
ax.text(0.5, 0.5, 'hello')
161+
with tempfile.TemporaryFile() as tmpfile:
162+
fig.savefig(tmpfile, format='pdf')

‎lib/matplotlib/tests/test_backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_svg.py
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55

66
import numpy as np
77
from io import BytesIO
8+
import os
9+
import tempfile
810
import xml.parsers.expat
911

12+
try:
13+
from unittest.mock import patch
14+
except ImportError:
15+
from mock import patch
16+
from nose.tools import raises
17+
1018
import matplotlib.pyplot as plt
1119
from matplotlib.testing.decorators import cleanup
1220
from matplotlib.testing.decorators import image_comparison, knownfailureif
1321
import matplotlib
22+
from matplotlib import dviread
23+
1424

1525
needs_tex = knownfailureif(
1626
not matplotlib.checkdep_tex(),
@@ -183,6 +193,23 @@ def test_determinism_tex():
183193
_test_determinism('determinism_tex.svg', usetex=True)
184194

185195

196+
@cleanup
197+
@needs_tex
198+
@raises(ValueError)
199+
@patch('matplotlib.dviread.PsfontsMap.__getitem__')
200+
def test_missing_psfont(mock):
201+
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
202+
from matplotlib import rc
203+
psfont = dviread.PsFont(texname='texfont', psname='Some Font',
204+
effects=None, encoding=None, filename=None)
205+
mock.configure_mock(return_value=psfont)
206+
rc('text', usetex=True)
207+
fig, ax = plt.subplots()
208+
ax.text(0.5, 0.5, 'hello')
209+
with tempfile.NamedTemporaryFile(suffix='.svg') as tmpfile:
210+
fig.savefig(tmpfile.name)
211+
212+
186213
if __name__ == '__main__':
187214
import nose
188215
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

‎lib/matplotlib/textpath.py

Copy file name to clipboardExpand all lines: lib/matplotlib/textpath.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
335335
font_bunch = self.tex_font_map[dvifont.texname]
336336

337337
if font_and_encoding is None:
338+
if font_bunch.filename is None:
339+
raise ValueError(
340+
("No usable font file found for %s (%s). "
341+
"The font may lack a Type-1 version.")
342+
% (font_bunch.psname, dvifont.texname))
343+
338344
font = get_font(font_bunch.filename)
339345

340346
for charmap_name, charmap_code in [("ADOBE_CUSTOM",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.