Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created January 28, 2012 22:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boredzo/1696100 to your computer and use it in GitHub Desktop.
Save boredzo/1696100 to your computer and use it in GitHub Desktop.
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];
CFRelease(coreTextFont);
}
CGFontRelease(graphicsFont);
CGDataProviderRelease(provider);
//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