summaryrefslogtreecommitdiff
path: root/src/os/macosx/string_osx.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-02-13 22:51:18 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-14 11:48:58 +0100
commit6755ff63e168dca62d16f3797a1a9dd5ceba307a (patch)
treef15f534ecfd25f83c8838ca349fc178f756f239b /src/os/macosx/string_osx.cpp
parent21a2cd7bc386207c68735edc05a21bb987dddd6b (diff)
downloadopenttd-6755ff63e168dca62d16f3797a1a9dd5ceba307a.tar.xz
Add: [OSX] Native font rendering without using FreeType.
Diffstat (limited to 'src/os/macosx/string_osx.cpp')
-rw-r--r--src/os/macosx/string_osx.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp
index 12440e1e1..5cd14e8e1 100644
--- a/src/os/macosx/string_osx.cpp
+++ b/src/os/macosx/string_osx.cpp
@@ -174,12 +174,16 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
for (const auto &i : fontMapping) {
if (i.first - last == 0) continue;
- if (!_font_cache[i.second->fc->GetSize()]) {
- /* Cache font information. */
- CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8));
- _font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr));
+ CTFontRef font = (CTFontRef)i.second->fc->GetOSHandle();
+ if (font == nullptr) {
+ if (!_font_cache[i.second->fc->GetSize()]) {
+ /* Cache font information. */
+ CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8));
+ _font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr));
+ }
+ font = _font_cache[i.second->fc->GetSize()].get();
}
- CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTFontAttributeName, _font_cache[i.second->fc->GetSize()].get());
+ CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTFontAttributeName, font);
CGColorRef color = CGColorCreateGenericGray((uint8)i.second->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTForegroundColorAttributeName, color);
@@ -300,7 +304,7 @@ void MacOSRegisterExternalFont(const char *file_path)
CTFontManagerRegisterFontsForURL(url.get(), kCTFontManagerScopeProcess, nullptr);
}
-/** Store current language locale as a CoreFounation locale. */
+/** Store current language locale as a CoreFoundation locale. */
void MacOSSetCurrentLocaleName(const char *iso_code)
{
if (!MacOSVersionIsAtLeast(10, 5, 0)) return;