Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c64c73c

Browse files
committed
Merge pull request #2829 from pwuertz/fix_2097
(fix #2097) PGF: get fonts from fc-list, use builtin fonts for tests
2 parents a429c41 + 9bccac2 commit c64c73c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from matplotlib.text import Text
2323
from matplotlib.path import Path
2424
from matplotlib import _png, rcParams
25-
from matplotlib import font_manager
26-
from matplotlib.ft2font import FT2Font
2725
from matplotlib.cbook import is_string_like, is_writable_file_like
2826
from matplotlib.compat import subprocess
2927
from matplotlib.compat.subprocess import check_output
@@ -33,14 +31,24 @@
3331

3432
# create a list of system fonts, all of these should work with xe/lua-latex
3533
system_fonts = []
36-
for f in font_manager.findSystemFonts():
34+
if sys.platform.startswith('win'):
35+
from matplotlib import font_manager
36+
from matplotlib.ft2font import FT2Font
37+
for f in font_manager.win32InstalledFonts():
38+
try:
39+
system_fonts.append(FT2Font(str(f)).family_name)
40+
except:
41+
pass # unknown error, skip this font
42+
else:
43+
# assuming fontconfig is installed and the command 'fc-list' exists
3744
try:
38-
system_fonts.append(FT2Font(f).family_name)
39-
except RuntimeError:
40-
pass # some fonts on osx are known to fail, print?
45+
# list scalable (non-bitmap) fonts
46+
fc_list = check_output(['fc-list', ':outline,scalable', 'family'])
47+
fc_list = fc_list.decode('utf8')
48+
system_fonts = [f.split(',')[0] for f in fc_list.splitlines()]
49+
system_fonts = list(set(system_fonts))
4150
except:
42-
pass # unknown error, skip this font
43-
51+
warnings.warn('error getting fonts from fc-list', UserWarning)
4452

4553
def get_texcommand():
4654
"""Get chosen TeX system from rc."""
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def test_pathclip():
148148
if not check_for('xelatex'):
149149
raise SkipTest('xelatex + pgf is required')
150150

151+
rc_xelatex = {'font.family': 'serif',
152+
'pgf.rcfonts': False}
153+
mpl.rcParams.update(rc_xelatex)
154+
151155
plt.figure()
152156
plt.plot([0., 1e100], [0., 1e100])
153157
plt.xlim(0, 1)
@@ -162,6 +166,10 @@ def test_mixedmode():
162166
if not check_for('xelatex'):
163167
raise SkipTest('xelatex + pgf is required')
164168

169+
rc_xelatex = {'font.family': 'serif',
170+
'pgf.rcfonts': False}
171+
mpl.rcParams.update(rc_xelatex)
172+
165173
Y, X = np.ogrid[-1:1:40j, -1:1:40j]
166174
plt.figure()
167175
plt.pcolor(X**2 + Y**2).set_rasterized(True)
@@ -174,6 +182,10 @@ def test_bbox_inches():
174182
if not check_for('xelatex'):
175183
raise SkipTest('xelatex + pgf is required')
176184

185+
rc_xelatex = {'font.family': 'serif',
186+
'pgf.rcfonts': False}
187+
mpl.rcParams.update(rc_xelatex)
188+
177189
Y, X = np.ogrid[-1:1:40j, -1:1:40j]
178190
fig = plt.figure()
179191
ax1 = fig.add_subplot(121)

0 commit comments

Comments
 (0)