Re: How do I embed a font in an app?
Re: How do I embed a font in an app?
- Subject: Re: How do I embed a font in an app?
- From: Brad Peterson <email@hidden>
- Date: Mon, 7 Apr 2008 17:52:19 -0700 (PDT)
Hi,
Just embed it as a resource, and then use the code
below to load it for use. You can just reference it by
name from then on (well, as long as your app is
running) as you would any other font. (Where
"kDefaultFontFile" is the name of your TTF file. Ex:
@"MyFont.TTF")
HTH!
B
NSString *fontPath = [[[[NSBundle mainBundle]
resourcePath] stringByAppendingPathComponent:@"Fonts"]
stringByAppendingPathComponent: kDefaultFontFile];
NSData *fontData = [NSData dataWithContentsOfFile:
fontPath];
ATSFontContainerRef container;
OSStatus err = ATSFontActivateFromMemory([fontData
bytes], [fontData length],
kATSFontContextLocal,
kATSFontFormatUnspecified,
NULL,
kATSOptionFlagsDefault,
&container );
if( err != noErr )
NSLog(@"failed to load font into memory");
ATSFontRef fontRefs[100];
ItemCount fontCount;
err = ATSFontFindFromContainer(
container,
kATSOptionFlagsDefault,
100,
fontRefs,
&fontCount );
if( err != noErr || fontCount < 1 ){
NSLog(@"font could not be loaded.");
}
else{
NSString *fontName;
err = ATSFontGetPostScriptName(
fontRefs[0],
kATSOptionFlagsDefault,
(CFStringRef*)( &fontName ) );
NSLog(@"font %@ loaded", fontName);
}
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
_______________________________________________
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