]> granicus.if.org Git - libass/commitdiff
coretext: implement GetFallbackFunc
authorStefano Pigozzi <stefano.pigozzi@gmail.com>
Mon, 31 Aug 2015 22:18:03 +0000 (00:18 +0200)
committerwm4 <wm4@nowhere>
Tue, 1 Sep 2015 11:53:01 +0000 (13:53 +0200)
libass/ass_coretext.c

index bf8a20ae9f3a43c54310c2bec7c0dc564e1aff5c..35f10ffd5fe9145242f90d1d9795ca514525744c 100644 (file)
@@ -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 *