From a04c2d1a6a3bf3fc4b5eabca46accbc56ccf7d61 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Tue, 14 Jan 2025 15:10:18 -0700 Subject: [PATCH 1/3] Initial attempt at loading Roboto into CoreText --- Common/Render/Text/draw_text_cocoa.mm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Common/Render/Text/draw_text_cocoa.mm b/Common/Render/Text/draw_text_cocoa.mm index 4776e03f87..386e18fa6e 100644 --- a/Common/Render/Text/draw_text_cocoa.mm +++ b/Common/Render/Text/draw_text_cocoa.mm @@ -32,7 +32,12 @@ enum { MAX_TEXT_HEIGHT = 512 }; -#define APPLE_FONT "Helvetica" +#define APPLE_FONT "Roboto-Condensed" + +// for future OpenEmu support +#ifndef PPSSPP_FONT_BUNDLE +#define PPSSPP_FONT_BUNDLE [NSBundle mainBundle] +#endif class TextDrawerFontContext { public: @@ -44,8 +49,10 @@ public: // Create an attributed string with string and font information CGFloat fontSize = ceilf((height / dpiScale) * 1.25f); INFO_LOG(Log::G3D, "Creating cocoa typeface '%s' size %d (effective size %0.1f)", APPLE_FONT, height, fontSize); - // CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil); - CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil); + NSURL *fontURL = [PPSSPP_FONT_BUNDLE URLForResource:@"Roboto-Condensed" withExtension:@"ttf" subdirectory:@"assets"]; + CTFontManagerRegisterFontsForURL((CFURLRef)fontURL, kCTFontManagerScopeProcess, NULL); + CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil); + // CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil); attributes = [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)font, kCTFontAttributeName, kCFBooleanTrue, kCTForegroundColorFromContextAttributeName, // Lets us specify the color later. From a8486e833f61f674d083a8587cbdd2594260e70c Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Tue, 14 Jan 2025 15:41:19 -0700 Subject: [PATCH 2/3] We only need to register the font once. --- Common/Render/Text/draw_text_cocoa.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Common/Render/Text/draw_text_cocoa.mm b/Common/Render/Text/draw_text_cocoa.mm index 386e18fa6e..206665cbe3 100644 --- a/Common/Render/Text/draw_text_cocoa.mm +++ b/Common/Render/Text/draw_text_cocoa.mm @@ -46,11 +46,16 @@ public: } void Create() { + // Register font with CoreText + // We only need to do this once. + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSURL *fontURL = [PPSSPP_FONT_BUNDLE URLForResource:@"Roboto-Condensed" withExtension:@"ttf" subdirectory:@"assets"]; + CTFontManagerRegisterFontsForURL((CFURLRef)fontURL, kCTFontManagerScopeProcess, NULL); + }); // Create an attributed string with string and font information CGFloat fontSize = ceilf((height / dpiScale) * 1.25f); INFO_LOG(Log::G3D, "Creating cocoa typeface '%s' size %d (effective size %0.1f)", APPLE_FONT, height, fontSize); - NSURL *fontURL = [PPSSPP_FONT_BUNDLE URLForResource:@"Roboto-Condensed" withExtension:@"ttf" subdirectory:@"assets"]; - CTFontManagerRegisterFontsForURL((CFURLRef)fontURL, kCTFontManagerScopeProcess, NULL); CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil); // CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil); attributes = [NSDictionary dictionaryWithObjectsAndKeys: From da3e300b58f9447c59b3de64ad0e4a8429bd3210 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Tue, 14 Jan 2025 16:31:03 -0700 Subject: [PATCH 3/3] Remove unused font variable. --- Common/Render/Text/draw_text_cocoa.mm | 3 --- 1 file changed, 3 deletions(-) diff --git a/Common/Render/Text/draw_text_cocoa.mm b/Common/Render/Text/draw_text_cocoa.mm index 206665cbe3..5c4db43976 100644 --- a/Common/Render/Text/draw_text_cocoa.mm +++ b/Common/Render/Text/draw_text_cocoa.mm @@ -65,12 +65,9 @@ public: CFRelease(font); } void Destroy() { - //CFRelease(font); - font = {}; } NSDictionary* attributes = nil; - CTFontRef font = nil; std::string fname; int height; int bold;