Last active
May 17, 2016 09:05
-
-
Save evadne/5519337 to your computer and use it in GitHub Desktop.
Loading Custom Fonts with CTFontManager
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
CTFontManagerRegisterFontsForURLs((__bridge CFArrayRef)((^{ | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL]; | |
NSArray *resourceURLs = [fileManager contentsOfDirectoryAtURL:resourceURL includingPropertiesForKeys:nil options:0 error:nil]; | |
return [resourceURLs filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSURL *url, NSDictionary *bindings) { | |
CFStringRef pathExtension = (__bridge CFStringRef)[url pathExtension]; | |
NSArray *allIdentifiers = (__bridge_transfer NSArray *)UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, pathExtension, CFSTR("public.font")); | |
if (![allIdentifiers count]) { | |
return NO; | |
} | |
CFStringRef utType = (__bridge CFStringRef)[allIdentifiers lastObject]; | |
return (!CFStringHasPrefix(utType, CFSTR("dyn.")) && UTTypeConformsTo(utType, CFSTR("public.font"))); | |
}]]; | |
})()), kCTFontManagerScopeProcess, nil); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow this is useful. Nice work! Could be more readable though :)