summaryrefslogtreecommitdiff
path: root/src/os/macosx
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-02 23:28:45 +0100
committerMichael Lutz <michi@icosahedron.de>2021-01-03 01:00:28 +0100
commit8c24b2b6ce7a2049d13132b2657ac3fce6145076 (patch)
tree81e7bd1a3c3a70d0910c8f3ea3096ccd3c7ace7a /src/os/macosx
parent4bd3d18f34962436d8fea6843690cc142e5dd8c6 (diff)
downloadopenttd-8c24b2b6ce7a2049d13132b2657ac3fce6145076.tar.xz
Fix: [OSX] Fonts loaded directly from a file have to be registered with CoreText for proper text layout.
Diffstat (limited to 'src/os/macosx')
-rw-r--r--src/os/macosx/string_osx.cpp11
-rw-r--r--src/os/macosx/string_osx.h2
2 files changed, 13 insertions, 0 deletions
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 */