Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Creating font(s) from a URL
//Core Graphics method
CGDataProviderRef provider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontURL);
CGFontRef graphicsFont = CGFontCreateWithDataProvider(provider);
CTFontRef coreTextFont = CTFontCreateWithGraphicsFont(graphicsFont, fontSize, /*matrix*/ NULL, /*attributes*/ NULL);
if (coreTextFont) {
NSFont *font = (__bridge NSFont *)coreTextFont;
[fonts addObject:font];
//Pure Core Text method
NSArray *descriptors = (__bridge_transfer NSArray *)CTFontManagerCreateFontDescriptorsFromURL((__bridge CFURLRef)fontURL);
for (NSFontDescriptor *desc in descriptors) {
NSFont *font = [NSFont fontWithDescriptor:desc size:fontSize];
[fonts addObject:font];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment