diff options
-rw-r--r-- | src/fontcache.cpp | 8 | ||||
-rw-r--r-- | src/os/macosx/string_osx.cpp | 11 | ||||
-rw-r--r-- | src/os/macosx/string_osx.h | 2 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index c523cade7..4a34a48d4 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -565,11 +565,19 @@ static void LoadFreeTypeFont(FontSize fs) /* If font is an absolute path to a ttf, try loading that first. */ FT_Error error = FT_New_Face(_library, settings->font, 0, &face); +#if defined(WITH_COCOA) + extern void MacOSRegisterExternalFont(const char *file_path); + if (error == FT_Err_Ok) MacOSRegisterExternalFont(settings->font); +#endif + if (error != FT_Err_Ok) { /* Check if font is a relative filename in one of our search-paths. */ std::string full_font = FioFindFullPath(BASE_DIR, settings->font); if (!full_font.empty()) { error = FT_New_Face(_library, full_font.c_str(), 0, &face); +#if defined(WITH_COCOA) + if (error == FT_Err_Ok) MacOSRegisterExternalFont(full_font.c_str()); +#endif } } diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 47c7f0a46..a36bed6be 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -289,6 +289,17 @@ void MacOSResetScriptCache(FontSize size) _font_cache[size].reset(); } +/** Register an external font file with the CoreText system. */ +void MacOSRegisterExternalFont(const char *file_path) +{ + if (!MacOSVersionIsAtLeast(10, 6, 0)) return; + + CFAutoRelease<CFStringRef> path(CFStringCreateWithCString(kCFAllocatorDefault, file_path, kCFStringEncodingUTF8)); + CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false)); + + CTFontManagerRegisterFontsForURL(url.get(), kCTFontManagerScopeProcess, nullptr); +} + /** Store current language locale as a CoreFounation locale. */ void MacOSSetCurrentLocaleName(const char *iso_code) { diff --git a/src/os/macosx/string_osx.h b/src/os/macosx/string_osx.h index 39f255b16..88e5924e8 100644 --- a/src/os/macosx/string_osx.h +++ b/src/os/macosx/string_osx.h @@ -85,4 +85,6 @@ void MacOSResetScriptCache(FontSize size); void MacOSSetCurrentLocaleName(const char *iso_code); int MacOSStringCompare(const char *s1, const char *s2); +void MacOSRegisterExternalFont(const char *file_path); + #endif /* STRING_OSX_H */ |