{{ message }}
Use CoreText to find macOS fonts#31977
Open
iccir wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #28249
Closes #31965
Why is this change necessary?
Prior to this change,
findSystemFonts()in font_manager.py calledsystem_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_profileruses the privatekCTFontCollectionIncludeInvisibleFontsOptionoption 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":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