linebender / parley

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

Search correct paths for fonts on Apple platforms. #71

Closed waywardmonkeys closed 1 month ago

waywardmonkeys commented 1 month ago

Use the Foundation API to get the list of "Library" directories and look in each of them for a "Fonts" directory.

This handles the need to search a variety of paths on macOS to find fonts in the various standard locations like "~/Library/Fonts", "/System/Library/Fonts", "/Library/Fonts", "/Network/Library/Fonts", etc.

Fixes #50.

waywardmonkeys commented 1 month ago

I'm not sure about a couple of things here, like using string concatenation, the use of as_ref on the NonNull, and using to_string to convert the NSString into a String.

When I run this locally, I get these search paths:

[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/Users/bruce/Library/Fonts/"
[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/Library/Fonts/"
[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/Network/Library/Fonts/"
[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/System/Cryptexes/App/System/Library/Fonts/"
[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/System/Cryptexes/OS/System/Library/Fonts/"
[fontique/src/backend/coretext.rs:52:22] p.to_string() + "/Fonts/" = "/System/Library/Fonts/"

If @madsmtm has any comments, that in particular would be great.

xorgy commented 1 month ago

I'm happy to approve this when mads' comments are addressed (either an answer or a code change).