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

Skip to content

fixes #2097, pgf: get scalable system-fonts from fontconfig, rely on builtin fonts for tests #2117

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

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 15 additions & 8 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,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 @@ -29,14 +27,23 @@

# 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 == 'win32':
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(str(f)).family_name)
except RuntimeError:
pass # some fonts on osx are known to fail, print?
# search for scalable (non-bitmap) fonts
fc_list = check_output(["fc-list", ":outline,scalable", "family"])
system_fonts = [f.split(",")[0] for f in fc_list.splitlines()]
system_fonts = list(set(system_fonts))
except:
pass # unknown error, skip this font

pass

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

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False,}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick: the second line is not well align with the first line of the dict.

mpl.rcParams.update(rc_xelatex)

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

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False,}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks, I'll include that in the next fix attempt

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 Down