linebender / parley

Rich text layout library
Apache License 2.0
158 stars 18 forks source link

Search paths for fonts on Apple platforms #50

Closed waywardmonkeys closed 1 month ago

waywardmonkeys commented 2 months ago

Currently, the CoreText source is searching in "/System/Library/Fonts/" for fonts, but it should probably be searching in more than that.

Fonts can be found in:

The user's home directory might be tricky due to sandboxing and so we shouldn't just put together the paths ourselves, but use the system APIs for this instead. (In sandboxed applications, one doesn't have direct access to ~/Library/ but has access to something in ~/Library/Containers/<application id>/data/Library which contains a symlink to the Fonts directory.)

I think the right thing to do would be to use NSSearchPathForDirectoriesInDomains (https://developer.apple.com/documentation/foundation/1414224-nssearchpathfordirectoriesindoma?language=objc) with NSLibraryDirectory or (NSAllLibrariesDirectory, I don't know which) and a mask of NSAllDomainsMask. We should be able to get this from objc2_foundation (https://docs.rs/objc2-foundation/latest/objc2_foundation/fn.NSSearchPathForDirectoriesInDomains.html)

And finally ... there are ALSO fonts in /System/Library/Fonts/Supplemental which should be scanned.

waywardmonkeys commented 2 months ago

Ends up: /System/Library/Fonts/Supplemental is already scanned while scanning /System/Library/Fonts ... but the rest remains true!