| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| @@ -1,5 +1,6 @@ | |||
| def display_is_valid() -> bool: ... | |||
| def xdisplay_is_valid() -> bool: ... | |||
| def find_available_fonts() -> set[str] | None: ... | |||
There was a problem hiding this comment.
| def find_available_fonts() -> set[str] | None: ... | |
| def get_available_fonts() -> set[str] | None: ... |
Sorry, something went wrong.
| } | ||
| return fonts; | ||
| #else | ||
| return py::none(); |
There was a problem hiding this comment.
should this be a py::set() call so that you can iterate it on the returning item even on a non macos platform? It is private, so probably not a big deal either way, but you are calling it as for x in None in the _get_macos helper above which would raise instead of returning empty.
Sorry, something went wrong.
There was a problem hiding this comment.
I was trying to mimic the "on other platforms, returns None" in Win32_GetCurrentProcessExplicitAppUserModelID and Win32_GetForegroundWindow.
I think _get_macos_fonts() should be changed to check for None rather than returning an empty set. To me, an empty set would indicate that the platform-specific code ran but found no fonts.
I think raising NotImplementedError might be the proper solution if the other functions in that file would do the same? I'm not sure (still learning!) :)
Sorry, something went wrong.
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
I happened across foliojs/font-manager#19 while looking at these functions. Is that also a problem in this implementation (and was it something that we supported before)? |
Sorry, something went wrong.
I'm not sure what is going on in the linked bug. ~/Library/Fonts is being checked on my test devices: >>> pprint.pp([x for x in _c_internal_utils.get_available_fonts() if "iccir" in x]) ['/Users/iccir/Library/Fonts/SF-Mono-Light.otf', '/Users/iccir/Library/Fonts/SF-Mono-Bold.otf', '/Users/iccir/Library/Fonts/DINishCondensed-Heavy.ttf', '/Users/iccir/Library/Fonts/DINish-Italic.otf', … My suspicion is one of the following:
I'm leaning towards 1. In any case, our previous implemented ran system_profiler as a subprocess, which also uses CTFontCollectionCreateFromAvailableFonts() internally. It's possible that ~/Library/Fonts isn't being accessed on some versions of macOS, but I wouldn't expect that to be a regression from the previous implementation. |
Sorry, something went wrong.
|
I did some more digging last night. system_profiler calls CTFontCollectionCreateFromAvailableFonts() with kCTFontCollectionIncludeDisabledFontsOption turned on. This means that fonts explicitly deactivated/disabled by the user were being included in _get_macos_fonts(). The new code calls CTFontCollectionCreateFromAvailableFonts() with NULL, so deactivated/disabled fonts will not be included. This is a subtle change of behavior, but I'm not sure if the old behavior is correct. There are situations where a user may have multiple user-level fonts installed with the same name and wants to deactivate one of them. Assuming we want to change this behavior, should the version number of the font cache be bumped in font_manager.py? It's currently: __version__ = '3.11.0' |
Sorry, something went wrong.
|
Hmm, yes, I think that is correct, as we did the same thing for Windows: #22859 You can bump the cache key to 3.12.0a1 or similar. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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":
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