Loading Typeface from NSBundle
Loading Typeface from NSBundle
- Subject: Loading Typeface from NSBundle
- From: Pascal Harris <email@hidden>
- Date: Sat, 04 Feb 2012 00:13:37 +0000
I'm trying to load a custom typeface from my application bundle (a TrueType font of my own design). Hunting around on the web reveals only methods which are deprecated to the extent of not working under OS X Lion (FMActivateFonts):
#import <QD/Fonts.h>
-------------------
NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
if (fontsFolder) {
NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
if (fontsURL) {
FSRef fsRef;
FSSpec fsSpec;
(void)CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
OSStatus status = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL,
NULL, &fsSpec, NULL);
if (noErr == status) {
FMGeneration generationCount = FMGetGeneration();
status = FMActivateFonts(&fsSpec, NULL, NULL,
kFMLocalActivationContext);
generationCount = FMGetGeneration() - generationCount;
if (generationCount) {
NSLog(@"app - %@ added %u font file%s", name, generationCount,
(generationCount == 1 ? "" : "s"));
}
}
}
}
My question is (I hope) simple. How does one load fonts from the Application Bundle in Lion?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden