Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search correct paths for fonts on Apple platforms. #71

Merged

Conversation

waywardmonkeys
Copy link
Contributor

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
Copy link
Contributor Author

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.

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 linebender#50.
Copy link

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory safety looks fine, and I think using NSSearchPathForDirectoriesInDomains and appending "Fonts" is the correct approach. An alternative, as the docs say, would've been -[NSFileManager URLsForDirectory:inDomains:].

fontique/src/backend/coretext.rs Show resolved Hide resolved
fontique/src/backend/coretext.rs Show resolved Hide resolved
@waywardmonkeys waywardmonkeys requested a review from dfrg June 3, 2024 17:58
@xorgy
Copy link
Member

xorgy commented Jun 6, 2024

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

@xorgy xorgy self-requested a review June 6, 2024 15:53
@waywardmonkeys waywardmonkeys added this pull request to the merge queue Jun 7, 2024
Merged via the queue into linebender:main with commit 14f7116 Jun 7, 2024
19 checks passed
@waywardmonkeys waywardmonkeys deleted the apple-font-search-path branch June 7, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search paths for fonts on Apple platforms
4 participants