Created
June 19, 2020 02:44
-
-
Save jjgod/700e4456e30dfeb29cc70d289bcd4e2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <CoreText/CoreText.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12, NULL); | |
{ | |
CTFontRef fallback = CTFontCreateForStringWithLanguage(font, CFSTR("\u4E2D"), CFRangeMake(0, 1), CFSTR("zh-Hans")); | |
CFCharacterSetRef covered = CTFontCopyCharacterSet(fallback); | |
bool isMember = CFCharacterSetIsCharacterMember(covered, 0x61); | |
NSLog(@"%d", isMember); | |
} | |
{ | |
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"\u4E2D" attributes:@{ (id)kCTFontAttributeName: CFBridgingRelease(font) }]; | |
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); | |
CFArrayRef runs = CTLineGetGlyphRuns(line); | |
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, 0); | |
CFDictionaryRef attributes = CTRunGetAttributes(run); | |
CTFontRef fallback = CFDictionaryGetValue(attributes, kCTFontAttributeName); | |
CFCharacterSetRef covered = CTFontCopyCharacterSet(fallback); | |
bool isMember = CFCharacterSetIsCharacterMember(covered, 0x61); | |
NSLog(@"%d", isMember); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment