-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Search also for user fonts on Windows (#12954) #12957
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
Conversation
lib/matplotlib/font_manager.py
Outdated
@@ -180,24 +184,46 @@ def win32InstalledFonts(directory=None, fontext='ttf'): | |||
|
|||
items = set() | |||
for fontdir in MSFontDirectories: | |||
# System fonts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in this is complicated enough, can you put it in a helper function that we call twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although, I now see there is some subtlety with absolute vs relative paths.
Thanks for your work on this! My comments are mostly directed at the long-term maintainability of this code path, we recently went through a few rounds of edits on those try/except blocks interacting with the registry so I am a bit concerned about having 2 copies of that code path (so if we do still have bugs in it we risk only fixing it in one place). How hard would it be to add a test to appveyor (or to add a test and move the wintests to azure)? |
lib/matplotlib/font_manager.py
Outdated
try: | ||
path = Path(directory, direc).resolve() | ||
path = Path(value).resolve() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should still prepend a sensible base direc
(which gets dropped anyways if value
is absolute) or perhaps better just skip values that are not absolute to start with; otherwise non-absolute values get resolved relative to cwd which is certainly not correct.
lib/matplotlib/font_manager.py
Outdated
directory = win32FontDirectory() | ||
Parameters | ||
---------- | ||
reg_domain : `int` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtin types should not be backquoted in this position
lib/matplotlib/font_manager.py
Outdated
|
||
fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)] | ||
base_dir : `string` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str
Thanks @tacaswell and @anntzer for your reviews. I also considered the duplication of the try blocks not optimal but since In case of the user fonts, I used the user directories in Regarding the tests, I cannot say too much about it. If a test can run in a Windows 1809 image with some user fonts installed, it should be easy to compare the result of One final question: I guess it is a good idea to increase the version number since the behaviour changed and new fonts may now be found. Should I do this or do you match this number with the version of matplotlib somehow? |
You can set the version to e.g. '310', it doesn't have to match exactly the matplotlib version but something approaching it makes sense. |
Just tested, the registry is not updated when a file is moved to the user folder. It has to be installed. However, the test idea may still work since the font should also be detected if it is only stored in the folder and not in the registry (via |
You can lookup |
def test_user_fonts(): | ||
if not os.environ.get('APPVEYOR', False): | ||
pytest.xfail('This test does only work on appveyor since user fonts ' | ||
'are Windows specific') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only that, but you don't even want to run it on a dev's Windows computer to not overwrite their fonts directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that it true. I agree that respecting the user directories of other developers is a thing to keep in mind. Do you want me to change the message or was this only a mere side note?^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do change the note too.
Thanks @Milania1 ! |
lib/matplotlib/font_manager.py
Outdated
'afm'. | ||
""" | ||
import winreg | ||
def win32RegistryFonts(reg_domain, base_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this function private (underscore-prefixed).
Also needs a rebase. |
- Change note - Make function private
31c823a
to
b02905a
Compare
Ok, I applied the changes and rebased. Hopefully, everything is correct :-) |
It's win32RegistryFonts which should be private, not win32InstalledFonts (which should stay public to avoid API breakage...) :) |
and make _win32RegistryFonts private
@Milania1 I took the liberty of pushing a commit that flips which function is private, hope you do not mind! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyone can merge after ci
Thanks @Milania1 ! Congratulations on your first contribution to matplotlib 🎉 Hopefully we will hear from you again! |
PR Summary
This PR fixes #12954, i.e. the fonts installed to the user directory are now also found by matplotlib.