Fix that font files never pass the test on Win by almarklein · Pull Request #24641 · matplotlib/matplotlib · GitHub
Skip to content

Fix that font files never pass the test on Win - #24641

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
almarklein:patch-1
Dec 6, 2022
Merged

Fix that font files never pass the test on Win#24641
timhoffm merged 1 commit into
matplotlib:mainfrom
almarklein:patch-1

Conversation

@almarklein

Copy link
Copy Markdown
Contributor

Hi! 👋

I am gratefully making use of MPL's font management code for our text rendering in PyGfx. While I was examining the code, I found what I think is a bug.

The isfile() test is applied on the relative pathname and will thus always fail. This PR should fix that. I would expect that it should also test for the extension, but I'm not 100% sure so I did not add this yet.

Diving a bit deeper, this bug has likely gone unnoticed because the code to detect fonts follows two paths on Windows:

  • It checks the registry for known installed fonts in a small set of predefined directories.
  • It detects font files in these same directories using os.listdir or os.walk.

Why are these two paths followed? I can see how the second route can find fonts that are present but not known in the registry, but why check the registry at all then?

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@oscargus oscargus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cannot really tell the background, but realize that this should work. Thanks!

@timhoffm
timhoffm merged commit fedb162 into matplotlib:main Dec 6, 2022
@almarklein
almarklein deleted the patch-1 branch December 6, 2022 14:14
@almarklein

Copy link
Copy Markdown
Contributor Author

@oscargus

oscargus commented Dec 6, 2022

Copy link
Copy Markdown
Member

I think that @anntzer may know more about it.

@anntzer

anntzer commented Dec 7, 2022

Copy link
Copy Markdown
Contributor

I suspect that the fix here is indeed incorrect as it will return files with incorrect extensions. The previous (wrong) code came in in #22909 to fix #22859, but given the discussion at #22859 I suspect that the correct approach on Windows is indeed to only return fonts listed by _get_win32_installed_fonts and not bother calling list_fonts at all. (Can anyone open a new issue with that, if they agree with my analysis?)

@almarklein

almarklein commented Dec 7, 2022

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants