From b3d18284308fdbb5bbaefe3d172911afd9134cdb Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 7 Dec 2022 14:47:49 +0100 Subject: [PATCH 1/4] Update font_manager to only use registry on Win --- lib/matplotlib/font_manager.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index c775a09136d6..8a4b52e96f32 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -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(): @@ -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': From f1beb1da268514ca0087c45ebc6f8270fe1f617b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 5 Jan 2023 16:31:00 -0500 Subject: [PATCH 2/4] TST: xfail the windows font test 1. we are moving to registry only for finding fonts on windows 2. our test just drops the font in the correct directory 3. this is not enough to get the registry to agree it is there We will xfail this test for now. --- lib/matplotlib/tests/test_font_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 6fd1097ce196..3724db1e1b43 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -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 From 17fac2e67157a9c30ff1d9839fad7d09c3b53c4f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 5 Jan 2023 17:03:41 -0500 Subject: [PATCH 3/4] DOC: add behavior change note for only considering fonts in registry --- doc/api/next_api_changes/behavior/24655-AK.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/api/next_api_changes/behavior/24655-AK.rst diff --git a/doc/api/next_api_changes/behavior/24655-AK.rst b/doc/api/next_api_changes/behavior/24655-AK.rst new file mode 100644 index 000000000000..840c0e50fb64 --- /dev/null +++ b/doc/api/next_api_changes/behavior/24655-AK.rst @@ -0,0 +1,14 @@ +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. + +This means that any user installed fonts must got 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.find_font`, directly pass the path to a font to use an +arbitrary font (see :doc:`/gallery/text_labels_and_annotations/fonts_file`). From dfec6b309d29e2250c3b19ea2d1ffcbe90cd9668 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 6 Jan 2023 11:03:56 -0500 Subject: [PATCH 4/4] DOC: fix english and cross ref Co-authored-by: Elliott Sales de Andrade Co-authored-by: hannah --- doc/api/next_api_changes/behavior/24655-AK.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/api/next_api_changes/behavior/24655-AK.rst b/doc/api/next_api_changes/behavior/24655-AK.rst index 840c0e50fb64..04b4141e4517 100644 --- a/doc/api/next_api_changes/behavior/24655-AK.rst +++ b/doc/api/next_api_changes/behavior/24655-AK.rst @@ -1,14 +1,15 @@ -On windows only fonts known to the registry will be discovered +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. +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 got through the Windows font +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.find_font`, directly pass the path to a font to use an -arbitrary font (see :doc:`/gallery/text_labels_and_annotations/fonts_file`). +`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`.