• 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: 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

  • Follow-Ups:
    • Re: How do I embed a font in an app?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Problems with Split Views?
  • Next by Date: Re: Apparent bug with button hotkeys that use shift
  • Previous by thread: Re: 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