FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #24655 on branch v3.7.x (Update font_manager to only use registry on Win) by meeseeksmachine · Pull Request #24941 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 15 additions & 0 deletions doc/api/next_api_changes/behavior/24655-AK.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
On Windows only fonts known to the registry will be discovered
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Previously, Matplotlib would recursively walk user and system font directories
to discover fonts, however this lead to a number of undesirable behaviors
including finding deleted fonts. Now Matplotlib will only find fonts that are
known to the Windows registry.

This means that any user installed fonts must go through the Windows font
installer rather than simply being copied to the correct folder.

This only impacts the set of fonts Matplotlib will consider when using
`matplotlib.font_manager.findfont`. To use an arbitrary font, directly pass the
path to a font as shown in
:doc:`/gallery/text_labels_and_annotations/font_file`.
17 changes: 6 additions & 11 deletions lib/matplotlib/font_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,11 @@ def list_fonts(directory, extensions):
recursively under the directory.
"""
extensions = ["." + ext for ext in extensions]
if sys.platform == 'win32' and directory == win32FontDirectory():
return [os.path.join(directory, filename)
for filename in os.listdir(directory)
if os.path.isfile(os.path.join(directory, filename))]
else:
return [os.path.join(dirpath, filename)
# os.walk ignores access errors, unlike Path.glob.
for dirpath, _, filenames in os.walk(directory)
for filename in filenames
if Path(filename).suffix.lower() in extensions]
return [os.path.join(dirpath, filename)
# os.walk ignores access errors, unlike Path.glob.
for dirpath, _, filenames in os.walk(directory)
for filename in filenames
if Path(filename).suffix.lower() in extensions]


def win32FontDirectory():
Expand Down Expand Up @@ -275,7 +270,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
if fontpaths is None:
if sys.platform == 'win32':
installed_fonts = _get_win32_installed_fonts()
fontpaths = MSUserFontDirectories + [win32FontDirectory()]
fontpaths = []
else:
installed_fonts = _get_fontconfig_fonts()
if sys.platform == 'darwin':
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_font_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_user_fonts_win32():
pytest.xfail("This test should only run on CI (appveyor or azure) "
"as the developer's font directory should remain "
"unchanged.")

pytest.xfail("We need to update the registry for this test to work")
font_test_file = 'mpltest.ttf'

# Precondition: the test font should not be available
Expand Down

Back | FazBrowse Home | New Git URL