From 72f751e3a5693ed2b7e935cb6c31ce18eed8d7b0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 1 Sep 2015 00:18:03 +0200 Subject: coretext: implement GetFallbackFunc --- libass/ass_coretext.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libass/ass_coretext.c') diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index bf8a20a..35f10ff 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -262,6 +262,30 @@ static void match_fonts(ASS_Library *lib, ASS_FontProvider *provider, } #endif +static char *get_fallback(void *priv, ASS_FontProviderMetaData *meta, + uint32_t codepoint) +{ + char *failed = meta->families[0]; + CFStringRef name = CFStringCreateWithBytes( + 0, (UInt8 *)failed, sizeof(failed), kCFStringEncodingUTF8, false); + CTFontRef font = CTFontCreateWithName(name, 0, NULL); + uint32_t codepointle = OSSwapHostToLittleInt32(codepoint); + CFStringRef r = CFStringCreateWithBytes( + 0, (UInt8*)&codepointle, sizeof(codepointle), + kCFStringEncodingUTF32LE, false); + CTFontRef fb = CTFontCreateForString(font, r, CFRangeMake(0, 1)); + CFStringRef cffamily = CTFontCopyFamilyName(fb); + char *family = cfstr2buf(cffamily); + + CFRelease(name); + CFRelease(font); + CFRelease(r); + CFRelease(fb); + CFRelease(cffamily); + + return family; +} + static ASS_FontProviderFuncs coretext_callbacks = { NULL, check_glyph, @@ -273,7 +297,7 @@ static ASS_FontProviderFuncs coretext_callbacks = { match_fonts, #endif NULL, - NULL + get_fallback }; ASS_FontProvider * -- cgit v1.2.3