Skip to content

Instantly share code, notes, and snippets.

@jjgod
Created June 19, 2020 02:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjgod/700e4456e30dfeb29cc70d289bcd4e2a to your computer and use it in GitHub Desktop.
Save jjgod/700e4456e30dfeb29cc70d289bcd4e2a to your computer and use it in GitHub Desktop.
#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