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

Skip to content

Search for fonts in XDG directory as well. #13766

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 3 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
# common application, not really useful
"/usr/lib/openoffice/share/fonts/truetype/",
# user fonts
str(Path(os.environ.get('XDG_DATA_HOME',
Path.home() / ".local/share")) / "fonts"),
str(Path.home() / ".fonts"),
]

Expand Down
30 changes: 28 additions & 2 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from matplotlib.font_manager import (
findfont, findSystemFonts, FontProperties, fontManager, json_dump,
json_load, get_font, get_fontconfig_fonts, is_opentype_cff_font,
MSUserFontDirectories)
MSUserFontDirectories, _call_fc_list)
from matplotlib import pyplot as plt, rc_context

has_fclist = shutil.which('fc-list') is not None
Expand Down Expand Up @@ -131,7 +131,33 @@ def test_find_ttc():
fig.savefig(BytesIO(), format="ps")


def test_user_fonts():
@pytest.mark.skipif(sys.platform != 'linux', reason='Linux only')
def test_user_fonts_linux(tmpdir, monkeypatch):
font_test_file = 'mpltest.ttf'

# Precondition: the test font should not be available
fonts = findSystemFonts()
assert not any(font_test_file in font for font in fonts)
Copy link
Member

Choose a reason for hiding this comment

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

This is only to make sure that the test can run. It’s not part of the actual test condition. Shouldn‘t this better be a pytest.fail or pytest.skip?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, possibly. I just copied this test from the one below.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've added a skip if this condition isn't met.


# Prepare a temporary user font directory
user_fonts_dir = tmpdir.join('fonts')
user_fonts_dir.ensure(dir=True)
shutil.copyfile(Path(__file__).parent / font_test_file,
user_fonts_dir.join(font_test_file))

with monkeypatch.context() as m:
m.setenv('XDG_DATA_HOME', str(tmpdir))
_call_fc_list.cache_clear()
# Now, the font should be available
fonts = findSystemFonts()
assert any(font_test_file in font for font in fonts)

# Make sure the temporary directory is no longer cached.
_call_fc_list.cache_clear()


@pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
def test_user_fonts_win32():
if not os.environ.get('APPVEYOR', False):
pytest.xfail('This test does only work on appveyor since user fonts '
'are Windows specific and the developer\'s font '
Expand Down