Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5466429

Browse filesBrowse files
authored
Merge pull request #24941 from meeseeksmachine/auto-backport-of-pr-24655-on-v3.7.x
Backport PR #24655 on branch v3.7.x (Update font_manager to only use registry on Win)
2 parents 425320f + 73dde94 commit 5466429
Copy full SHA for 5466429

File tree

Expand file treeCollapse file tree

3 files changed

+22
-12
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-12
lines changed
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
On Windows only fonts known to the registry will be discovered
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Previously, Matplotlib would recursively walk user and system font directories
5+
to discover fonts, however this lead to a number of undesirable behaviors
6+
including finding deleted fonts. Now Matplotlib will only find fonts that are
7+
known to the Windows registry.
8+
9+
This means that any user installed fonts must go through the Windows font
10+
installer rather than simply being copied to the correct folder.
11+
12+
This only impacts the set of fonts Matplotlib will consider when using
13+
`matplotlib.font_manager.findfont`. To use an arbitrary font, directly pass the
14+
path to a font as shown in
15+
:doc:`/gallery/text_labels_and_annotations/font_file`.

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,11 @@ def list_fonts(directory, extensions):
186186
recursively under the directory.
187187
"""
188188
extensions = ["." + ext for ext in extensions]
189-
if sys.platform == 'win32' and directory == win32FontDirectory():
190-
return [os.path.join(directory, filename)
191-
for filename in os.listdir(directory)
192-
if os.path.isfile(os.path.join(directory, filename))]
193-
else:
194-
return [os.path.join(dirpath, filename)
195-
# os.walk ignores access errors, unlike Path.glob.
196-
for dirpath, _, filenames in os.walk(directory)
197-
for filename in filenames
198-
if Path(filename).suffix.lower() in extensions]
189+
return [os.path.join(dirpath, filename)
190+
# os.walk ignores access errors, unlike Path.glob.
191+
for dirpath, _, filenames in os.walk(directory)
192+
for filename in filenames
193+
if Path(filename).suffix.lower() in extensions]
199194

200195

201196
def win32FontDirectory():
@@ -275,7 +270,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
275270
if fontpaths is None:
276271
if sys.platform == 'win32':
277272
installed_fonts = _get_win32_installed_fonts()
278-
fontpaths = MSUserFontDirectories + [win32FontDirectory()]
273+
fontpaths = []
279274
else:
280275
installed_fonts = _get_fontconfig_fonts()
281276
if sys.platform == 'darwin':

‎lib/matplotlib/tests/test_font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_font_manager.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_user_fonts_win32():
200200
pytest.xfail("This test should only run on CI (appveyor or azure) "
201201
"as the developer's font directory should remain "
202202
"unchanged.")
203-
203+
pytest.xfail("We need to update the registry for this test to work")
204204
font_test_file = 'mpltest.ttf'
205205

206206
# Precondition: the test font should not be available

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.