Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS/iOS: register font with CoreText #19874

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Common/Render/Text/draw_text_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
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:
Expand All @@ -41,24 +46,28 @@
}

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);
// CTFontRef font = CTFontCreateWithName(CFSTR(APPLE_FONT), fontSize, nil);
CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, fontSize, nil);
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.
nil];
CFRelease(font);
}
void Destroy() {
//CFRelease(font);
font = {};
}

NSDictionary* attributes = nil;
CTFontRef font = nil;
std::string fname;
int height;
int bold;
Expand Down
Loading