I had some success with this -

-(void) loadFonts {
        // Get the main bundle object
        NSBundle * appBundle = [NSBundle mainBundle];
NSString *fontsPath = [[appBundle resourcePath] stringByAppendingPathComponent:@"Fonts"];
        if (fontsPath) {
                NSURL *fontsURL = [NSURL fileURLWithPath:fontsPath];
                if (fontsURL) {
                        // Using the Carbon APIs:  get a file reference and 
spec for the path
                        
                        FSRef fsRef;
                        FSSpec fsSpec;
                        (void)CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
OSStatus status = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL);
                        if (status==noErr) {
                                //activate the font file using the file spec
                                status = ATSFontActivateFromFileSpecification (  
&fsSpec,
                                                                 
kATSFontContextLocal,
                                                                
kATSFontFormatUnspecified,
                                                                NULL,
                                                                
kATSOptionFlagsDefault,
                                                                 NULL
                                                                );
                                if (status != noErr) {
                                        NSLog(@"Error %d loading fonts from 
%@",status,fontsURL);
                                }
                        } else {
                                NSLog(@"Error loading catalog info");
                        }
                } else {
                        NSLog(@"Error creating fonts URL");
                }
        } else {
                NSLog(@"Error creating fonts path");
        }
}

On Apr 4, 2008, at 3:37 PM, Jens Alfke wrote:
In my application's user interface I want to use some TrueType fonts which are not built into the OS. (Yes, they're free and their licenses allow this sort of use.) I thought I remembered a way to embed fonts in an application bundle, or to programmatically load a font from a file; but I'm drawing a blank now when I try to look it up.

Surely I don't have to copy the fonts into the system (~/Library/ Fonts) like in the bad old days? :-P

—Jens_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/buddykurz%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to