-
-
Save mrdekk/2c05dd1eddafbc48918615c2840d8dcf to your computer and use it in GitHub Desktop.
Creating font(s) from a URL
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
//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