Skip to content

Commit ea36cb7

Browse files
authored
Merge pull request #19874 from MaddTheSane/registerFont
macOS/iOS: register font with CoreText
2 parents 008aaa8 + da3e300 commit ea36cb7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Common/Render/Text/draw_text_cocoa.mm

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
MAX_TEXT_HEIGHT = 512
3333
};
3434

35-
#define APPLE_FONT "Helvetica"
35+
#define APPLE_FONT "Roboto-Condensed"
36+
37+
// for future OpenEmu support
38+
#ifndef PPSSPP_FONT_BUNDLE
39+
#define PPSSPP_FONT_BUNDLE [NSBundle mainBundle]
40+
#endif
3641

3742
class TextDrawerFontContext {
3843
public:
@@ -41,24 +46,28 @@
4146
}
4247

4348
void Create() {
49+
// Register font with CoreText
50+
// We only need to do this once.
51+
static dispatch_once_t onceToken;
52+
dispatch_once(&onceToken, ^{
53+
NSURL *fontURL = [PPSSPP_FONT_BUNDLE URLForResource:@"Roboto-Condensed" withExtension:@"ttf" subdirectory:@"assets"];
54+
CTFontManagerRegisterFontsForURL((CFURLRef)fontURL, kCTFontManagerScopeProcess, NULL);
55+
});
4456
// Create an attributed string with string and font information
4557
CGFloat fontSize = ceilf((height / dpiScale) * 1.25f);
4658
INFO_LOG(Log::G3D, "Creating cocoa typeface '%s' size %d (effective size %0.1f)", APPLE_FONT, height, fontSize);
47-
// CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil);
48-
CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil);
59+
CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil);
60+
// CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil);
4961
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
5062
(__bridge id)font, kCTFontAttributeName,
5163
kCFBooleanTrue, kCTForegroundColorFromContextAttributeName, // Lets us specify the color later.
5264
nil];
5365
CFRelease(font);
5466
}
5567
void Destroy() {
56-
//CFRelease(font);
57-
font = {};
5868
}
5969

6070
NSDictionary* attributes = nil;
61-
CTFontRef font = nil;
6271
std::string fname;
6372
int height;
6473
int bold;

0 commit comments

Comments
 (0)