Changeset - r24554:c46033ff81ac
[Not reviewed]
master
0 3 0
Michael Lutz - 3 years ago 2021-01-02 22:28:45
michi@icosahedron.de
Fix: [OSX] Fonts loaded directly from a file have to be registered with CoreText for proper text layout.
3 files changed with 21 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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
 
		}
 
	}
 

	
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -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)
 
{
src/os/macosx/string_osx.h
Show inline comments
 
@@ -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 */
0 comments (0 inline, 0 general)