• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I embed a font in an app?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I embed a font in an app?


  • Subject: Re: How do I embed a font in an app?
  • From: Buddy Kurz <email@hidden>
  • Date: Fri, 4 Apr 2008 16:06:54 -0700

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 (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

_______________________________________________

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


  • Follow-Ups:
    • Re: How do I embed a font in an app?
      • From: Jens Alfke <email@hidden>
References: 
 >How do I embed a font in an app? (From: Jens Alfke <email@hidden>)

  • Prev by Date: How do I embed a font in an app?
  • Next by Date: Re: How do I embed a font in an app?
  • Previous by thread: How do I embed a font in an app?
  • Next by thread: Re: How do I embed a font in an app?
  • Index(es):
    • Date
    • Thread