Fix: [OSX] Fonts loaded directly from a file have to be registered with CoreText for proper text layout.

This commit is contained in:
Michael Lutz 2021-01-02 23:28:45 +01:00
parent 4bd3d18f34
commit 8c24b2b6ce
3 changed files with 21 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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)
{

View File

@ -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 */