Skip to content

Instantly share code, notes, and snippets.

@MaximKeegan
Created February 7, 2013 08:53
Show Gist options
  • Save MaximKeegan/4729659 to your computer and use it in GitHub Desktop.
Save MaximKeegan/4729659 to your computer and use it in GitHub Desktop.
BOOL GSFontAddFromFile(const char * path);
NSUInteger newFontCount = 0;
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
if (frameworkPath) {
void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
if (graphicsServices) {
BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
if (GSFontAddFromFile) {
for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"otf" inDirectory:nil])
newFontCount += GSFontAddFromFile([fontFile UTF8String]);
for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
newFontCount += GSFontAddFromFile([fontFile UTF8String]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment