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

Skip to content

(fix #2097) PGF: get fonts from fc-list, use builtin fonts for tests #2829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from matplotlib.text import Text
from matplotlib.path import Path
from matplotlib import _png, rcParams
from matplotlib import font_manager
from matplotlib.ft2font import FT2Font
from matplotlib.cbook import is_string_like, is_writable_file_like
from matplotlib.compat import subprocess
from matplotlib.compat.subprocess import check_output
Expand All @@ -33,14 +31,24 @@

# create a list of system fonts, all of these should work with xe/lua-latex
system_fonts = []
for f in font_manager.findSystemFonts():
if sys.platform.startswith('win'):
from matplotlib import font_manager
from matplotlib.ft2font import FT2Font
for f in font_manager.win32InstalledFonts():
try:
system_fonts.append(FT2Font(str(f)).family_name)
except:
pass # unknown error, skip this font
else:
# assuming fontconfig is installed and the command 'fc-list' exists
try:
system_fonts.append(FT2Font(f).family_name)
except RuntimeError:
pass # some fonts on osx are known to fail, print?
# list scalable (non-bitmap) fonts
fc_list = check_output(['fc-list', ':outline,scalable', 'family'])
fc_list = fc_list.decode('utf8')
system_fonts = [f.split(',')[0] for f in fc_list.splitlines()]
system_fonts = list(set(system_fonts))
except:
pass # unknown error, skip this font

warnings.warn('error getting fonts from fc-list', UserWarning)

def get_texcommand():
"""Get chosen TeX system from rc."""
Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def test_pathclip():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)

plt.figure()
plt.plot([0., 1e100], [0., 1e100])
plt.xlim(0, 1)
Expand All @@ -162,6 +166,10 @@ def test_mixedmode():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)

Y, X = np.ogrid[-1:1:40j, -1:1:40j]
plt.figure()
plt.pcolor(X**2 + Y**2).set_rasterized(True)
Expand All @@ -174,6 +182,10 @@ def test_bbox_inches():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)

Y, X = np.ogrid[-1:1:40j, -1:1:40j]
fig = plt.figure()
ax1 = fig.add_subplot(121)
Expand Down