Title: Use CoreText to find macOS fonts by iccir · Pull Request #31977 · matplotlib/matplotlib · GitHub
Open Graph Title: Use CoreText to find macOS fonts by iccir · Pull Request #31977 · matplotlib/matplotlib
X Title: Use CoreText to find macOS fonts by iccir · Pull Request #31977 · matplotlib/matplotlib
Description: Closes #28249 Closes #31965 Why is this change necessary? Prior to this change, findSystemFonts() in font_manager.py called system_profiler -xml SPFontsDataType. This subprocess would load 1000+ font files in order to parse localized names. As we only need font paths, we can instead query CoreText directly. This finishes in ~63ms on my machine instead of ~7 seconds. Differences in found fonts system_profiler uses the private kCTFontCollectionIncludeInvisibleFontsOption option to find "invisible" fonts. These are fonts with names starting with '.'. These fonts are typically unavailable using the standard macOS font APIs. On my machine (macOS 14.8), the following fonts are "invisible": /System/Library/Fonts/ADTNumeric.ttc /System/Library/Fonts/AquaKana.ttc /System/Library/Fonts/HelveLTMM /System/Library/Fonts/Keyboard.ttf /System/Library/Fonts/LastResort.otf /System/Library/Fonts/NewYork.ttf /System/Library/Fonts/NewYorkItalic.ttf /System/Library/Fonts/SFArabic.ttf /System/Library/Fonts/SFArabicRounded.ttf /System/Library/Fonts/SFArmenian.ttf /System/Library/Fonts/SFArmenianRounded.ttf /System/Library/Fonts/SFCamera.ttf /System/Library/Fonts/SFCompact.ttf /System/Library/Fonts/SFCompactItalic.ttf /System/Library/Fonts/SFCompactRounded.ttf /System/Library/Fonts/SFGeorgian.ttf /System/Library/Fonts/SFGeorgianRounded.ttf /System/Library/Fonts/SFHebrew.ttf /System/Library/Fonts/SFHebrewRounded.ttf /System/Library/Fonts/SFNS.ttf /System/Library/Fonts/SFNSItalic.ttf /System/Library/Fonts/SFNSMono.ttf /System/Library/Fonts/SFNSMonoItalic.ttf /System/Library/Fonts/SFNSRounded.ttf /System/Library/Fonts/ThonburiUI.ttc /System/Library/Fonts/TimesLTMM My change uses the CTFontCollectionCreateFromAvailableFonts() without this private option; hence, these fonts will be missing from the list returned by _get_macos_fonts(). However, font_manager.py later re-scans the "/System/Library/Fonts" path, so it should discover these invisible fonts at that time. I tested this change on macOS Mojave (10.14) and macOS Sonoma (14.8). I was unable to test on 10.12 or 10.13 as I updated my 10.12 test device to 10.14. The CoreText API used has been available since 10.5, so I do not foresee any compatibility issues. AI Disclosure The original C-based implementation in #31965 is my own without any usage of AI. I used AI to help me convert it to C++ and return a py::set (my original implementation printed the paths). I used AI to check the resulting files and verify that I was following the correct formatting guidelines. PR checklist "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested [N/A] Plotting related features are demonstrated in an example [N/A] New Features and API Changes are noted with a directive and release note Documentation complies with general and docstring guidelines
Open Graph Description: Closes #28249 Closes #31965 Why is this change necessary? Prior to this change, findSystemFonts() in font_manager.py called system_profiler -xml SPFontsDataType. This subprocess would load 1000+ fo...
X Description: Closes #28249 Closes #31965 Why is this change necessary? Prior to this change, findSystemFonts() in font_manager.py called system_profiler -xml SPFontsDataType. This subprocess would load 1000+ fo...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31977
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c2accf1d-ff5b-4a8b-e9f7-be38f8164843 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9AA0:1FFDFF:63E7E6B:8C43183:6A503F45 |
| html-safe-nonce | f4c9c8e7c15a40bdc4c727b39d8126e88d2704a76f267c4e0633b31fbd60b7c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUEwOjFGRkRGRjo2M0U3RTZCOjhDNDMxODM6NkE1MDNGNDUiLCJ2aXNpdG9yX2lkIjoiMzk0MDc2NzQ0MzczNjA4NDI5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d8bbff095b597f96f36191d71c30a013037077184e67d2fda5bb848c201b7c41 |
| hovercard-subject-tag | pull_request:3973000585 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/31977/files |
| twitter:image | https://avatars.githubusercontent.com/u/1097294?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1097294?s=400&v=4 |
| og:image:alt | Closes #28249 Closes #31965 Why is this change necessary? Prior to this change, findSystemFonts() in font_manager.py called system_profiler -xml SPFontsDataType. This subprocess would load 1000+ fo... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d90666eaf032b7eb8975a378efe38e37f4ebb96c |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width