René's URL Explorer Experiment


Title: [MNT]: findSystemFonts - Use system API instead to look into folder · Issue #24001 · matplotlib/matplotlib · GitHub

Open Graph Title: [MNT]: findSystemFonts - Use system API instead to look into folder · Issue #24001 · matplotlib/matplotlib

X Title: [MNT]: findSystemFonts - Use system API instead to look into folder · Issue #24001 · matplotlib/matplotlib

Description: Summary Currently, findSystemFonts look at all the file in the specified folders for macos and windows. This is not a very good method, because a font in a "Font folder" does not necessarily need to be picked up. A very good example of t...

Open Graph Description: Summary Currently, findSystemFonts look at all the file in the specified folders for macos and windows. This is not a very good method, because a font in a "Font folder" does not necessarily need t...

X Description: Summary Currently, findSystemFonts look at all the file in the specified folders for macos and windows. This is not a very good method, because a font in a "Font folder" does not necessar...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24001

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: findSystemFonts - Use system API instead to look into folder","articleBody":"### Summary\r\n\r\nCurrently, [findSystemFonts](https://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L348-L378) look at all the file in the [specified folders](https://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L130-L167) for macos and windows.\r\n\r\nThis is not a very good method, because a font in a \"Font folder\" does not necessarily need to be picked up.\r\nA very good example of that is in this issue: #22859\r\n\r\nThis is why I propose to use CoreText (for mac) and DirectWrite (for Windows).\r\nThese are API provided by Apple and Microsoft.\r\n\r\n### Proposed fix\r\n\r\n### CoreText - For MAC\r\n\r\nIn this example, I use this library: https://pypi.org/project/pyobjc-framework-CoreText/\r\n```py\r\nimport CoreText\r\n\r\nfontURLs = CoreText.CTFontManagerCopyAvailableFontURLs()\r\nfontPath = set()\r\n\r\nfor i in range(CoreText.CFArrayGetCount(fontURLs)):\r\n    url = CoreText.CFArrayGetValueAtIndex(fontURLs, i)\r\n\r\n    fontPath.add(str(url.path()))\r\n```\r\n\r\n### DirectWrite - For Windows\r\n\r\nI don't know much C/C++, so I can't give an good example.\r\nOn recent Windows build, it is pretty simple to get the font path with DirectWrite, but since matplotlib seems to support Windows 7, we would maybe need to use the \"complex\" solution.\r\n\r\nBut, here is how I understand it (I have no proof that it works):\r\n\r\n#### Logic for to support only Windows 10:\r\n- [GetSystemFontCollection](https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefactory3-getsystemfontcollection)\r\n- [GetFontSet](https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontcollection1-getfontset)\r\n- For loop with [GetFontCount](https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontcount)\r\n    - [GetFontFaceReference ](https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontfacereference)\r\n    - [GetFontFile](https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontfacereference-getfontfile)\r\n    - [GetReferenceKey](https://learn.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfile-getreferencekey)\r\n    - [GetFilePathFromKey](https://learn.microsoft.com/en-us/windows/win32/directwrite/idwritelocalfontfileloader-getfilepathfromkey)\r\n\r\nHere is an \"pseudo-code\" of how I see it.\r\n```py\r\nfont_collection = GetSystemFontCollection()\r\nfont_set = font_collection.GetFontSet()\r\n\r\nfor i in range(font_set.GetFontCount()):\r\n\tfont_face_reference = font_set.GetFontFaceReference(i)\r\n\tfont_file = font_face_reference.GetFontFile()\r\n\treference_key, reference_key_size = font_file.GetReferenceKey()\r\n\tpath = GetFilePathFromKey(reference_key, reference_key_size)\r\n```\r\n\r\n#### Logic for Windows Vista to this day:\r\n- [GetSystemFontCollection](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefactory-getsystemfontcollection)\r\n- Do a for loop with [GetFontFamilyCount](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontcollection-getfontfamilycount)\r\n\t- [GetFontFamily](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontcollection-getfontfamily)\r\n\t- [GetMatchingFonts](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfamily-getmatchingfonts) - The param weight, stretch, style can be anything. These param seems to only change the order or the return list.\r\n\t- Do a for loop with [GetFontCount](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontlist-getfontcount)\r\n\t\t- [GetFont](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontlist-getfont)\r\n\t\t- [CreateFontFace](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefont-createfontface)\r\n\t\t- [GetFiles](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontface-getfiles)\r\n\t\t- [GetReferenceKey](https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfile-getreferencekey)\r\n\t\t- [GetFilePathFromKey](https://docs.microsoft.com/en-us/windows/win32/directwrite/idwritelocalfontfileloader-getfilepathfromkey)\r\n\r\n```py\r\nfont_collection = GetSystemFontCollection()\r\n \r\nfor i in range(font_collection.GetFontFamilyCount()):\r\n\tfont_family = font_collection.GetFontFamily(i)\r\n\tmatching_fonts = GetMatchingFonts(ANY_WEIGHT, ANY_STRETCH, ANY_STYLE)\r\n\t\r\n\tfor j in range(matching_fonts.GetFontCount()):\r\n\t\tfont = matching_fonts.GetFont(j)\r\n\t\tfont_face = font.CreateFontFace()\r\n\t\t\r\n\t\tfor file in font_face.GetFiles():\r\n\t\t\treference_key, reference_key_size = font_file.GetReferenceKey()\r\n\t\t\tpath = GetFilePathFromKey(reference_key, reference_key_size)\r\n```\r\n\r\nI have try to see if the GDI api could help us to get the path of the fonts, but from what I can see, it is not an available feature: https://learn.microsoft.com/en-us/windows/win32/gdi/font-and-text-functions\r\n\r\n### FontConfig (Bonus) - For Linux\r\nCurrently, [matplotlib parse the result from subprocess](https://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L327-L337).\r\n\r\nIt would be an good idea to directly use FontConfig. See this answer from stackoverflow to know how to do it: https://stackoverflow.com/a/14634033\r\n\r\nI did not found any FontConfig bindings library that are still maintained, so it would need to be implemented with Cython.","author":{"url":"https://github.com/moi15moi","@type":"Person","name":"moi15moi"},"datePublished":"2022-09-24T23:05:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/24001/matplotlib/issues/24001"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e2c09c81-b3f6-9ae8-bd08-3d80bb59b0f9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8442:32982F:282D50:364155:6A51BA96
html-safe-nonce21aedc202eb27a2e5e0d6bcc9ad5c1a73b80e3520ecb5ee5a4ac3ae91aafe7a6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDQyOjMyOTgyRjoyODJENTA6MzY0MTU1OjZBNTFCQTk2IiwidmlzaXRvcl9pZCI6IjYwNTY3NzA5NDQyNTY1NTU2NzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac19a1ea89a1a7ee7639c6d7a1b1385d909122234dc6379bcea9d5b28d94834e9f
hovercard-subject-tagissue:1384836230
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/24001/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1c99784d0a1da5fb2ca6bf1614c2fcbe1c0be07f3de9652a82920c2c4a3187bd/matplotlib/matplotlib/issues/24001
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1c99784d0a1da5fb2ca6bf1614c2fcbe1c0be07f3de9652a82920c2c4a3187bd/matplotlib/matplotlib/issues/24001
og:image:altSummary Currently, findSystemFonts look at all the file in the specified folders for macos and windows. This is not a very good method, because a font in a "Font folder" does not necessarily need t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemoi15moi
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/24001#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F24001
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F24001
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/24001
Reloadhttps://github.com/matplotlib/matplotlib/issues/24001
Reloadhttps://github.com/matplotlib/matplotlib/issues/24001
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/24001
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/24001
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
[MNT]: findSystemFonts - Use system API instead to look into folderhttps://github.com/matplotlib/matplotlib/issues/24001#top
Maintenancehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Maintenance%22
status: inactiveMarked by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20inactive%22
topic: text/fontshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Ffonts%22
https://github.com/moi15moi
moi15moihttps://github.com/moi15moi
on Sep 24, 2022https://github.com/matplotlib/matplotlib/issues/24001#issue-1384836230
findSystemFontshttps://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L348-L378
specified foldershttps://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L130-L167
#22859https://github.com/matplotlib/matplotlib/issues/22859
https://pypi.org/project/pyobjc-framework-CoreText/https://pypi.org/project/pyobjc-framework-CoreText/
GetSystemFontCollectionhttps://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefactory3-getsystemfontcollection
GetFontSethttps://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontcollection1-getfontset
GetFontCounthttps://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontcount
GetFontFaceReference https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontfacereference
GetFontFilehttps://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontfacereference-getfontfile
GetReferenceKeyhttps://learn.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfile-getreferencekey
GetFilePathFromKeyhttps://learn.microsoft.com/en-us/windows/win32/directwrite/idwritelocalfontfileloader-getfilepathfromkey
GetSystemFontCollectionhttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefactory-getsystemfontcollection
GetFontFamilyCounthttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontcollection-getfontfamilycount
GetFontFamilyhttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontcollection-getfontfamily
GetMatchingFontshttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfamily-getmatchingfonts
GetFontCounthttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontlist-getfontcount
GetFonthttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontlist-getfont
CreateFontFacehttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefont-createfontface
GetFileshttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontface-getfiles
GetReferenceKeyhttps://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfile-getreferencekey
GetFilePathFromKeyhttps://docs.microsoft.com/en-us/windows/win32/directwrite/idwritelocalfontfileloader-getfilepathfromkey
https://learn.microsoft.com/en-us/windows/win32/gdi/font-and-text-functionshttps://learn.microsoft.com/en-us/windows/win32/gdi/font-and-text-functions
matplotlib parse the result from subprocesshttps://github.com/matplotlib/matplotlib/blob/36f27457d7781c0dbb6da3b875e98f0a3fac0f64/lib/matplotlib/font_manager.py#L327-L337
https://stackoverflow.com/a/14634033https://stackoverflow.com/a/14634033
Maintenancehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Maintenance%22
status: inactiveMarked by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20inactive%22
topic: text/fontshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Ffonts%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.