Skip to content

Commit

Permalink
Search correct paths for fonts on Apple platforms.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
waywardmonkeys committed Jun 2, 2024
1 parent 8e10403 commit 98a491f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
57 changes: 54 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fontique/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ wio = "0.2.2"
[target.'cfg(target_vendor="apple")'.dependencies]
core-text = "20.1.0"
core-foundation = "0.9.4"
objc2 = { version = "0.5.2" }
objc2-foundation = { version = "0.2.2", features = ["NSArray", "NSEnumerator", "NSPathUtilities", "NSString"] }

[target.'cfg(not(any(target_vendor="apple", target_family="windows")))'.dependencies]
fontconfig-cache-parser = "0.2.0"
Expand Down
16 changes: 15 additions & 1 deletion fontique/src/backend/coretext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use super::{
};
use alloc::sync::Arc;
use hashbrown::HashMap;
use objc2::runtime::Bool;
use objc2_foundation::{
NSSearchPathDirectory, NSSearchPathDomainMask, NSSearchPathForDirectoriesInDomains,
};
use {
core_foundation::{
base::{CFRange, TCFType},
Expand Down Expand Up @@ -37,7 +41,17 @@ pub struct SystemFonts {

impl SystemFonts {
pub fn new() -> Self {
let scanned = scan::ScannedCollection::from_paths(Some("/System/Library/Fonts"), 8);
let paths = unsafe {
NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory::NSLibraryDirectory,
NSSearchPathDomainMask::NSAllDomainsMask,
Bool::YES,
)
.as_ref()
.iter()
.map(|p| format!("{p}/Fonts/"))
};
let scanned = scan::ScannedCollection::from_paths(paths, 8);
let name_map = scanned.family_names;
let mut generic_families = GenericFamilyMap::default();
for (family, names) in DEFAULT_GENERIC_FAMILIES {
Expand Down

0 comments on commit 98a491f

Please sign in to comment.