• 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:Loading Fonts from the App Bundle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:Loading Fonts from the App Bundle


  • Subject: Re:Loading Fonts from the App Bundle
  • From: Bela Bernat Hackman <email@hidden>
  • Date: Sat, 7 Dec 2002 11:27:46 -0600

Try this (minus error checking of course):

// Get the main bundle object
NSBundle * appBundle = [NSBundle mainBundle];

// Ask for the path to the resources
NSString * fontsPath = [appBundle resourcePath];

// Using the Carbon APIs: get a file reference and spec for the path
FSRef fsRef;
FSSpec fsSpec;
int osstatus = FSPathMakeRef( [fontsPath UTF8String], &fsRef, NULL);
if ( osstatus == noErr)
{
osstatus = FSGetCatalogInfo( &fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL);
}
//activate the font file using the file spec
osstatus = FMActivateFonts( &fsSpec, NULL, NULL, kFMGlobalActivationContext);

Comments:
1) Make sure the font files are actually copied to the Resource directory of the bundle not just referenced. Copying the font files to the bundle in the Finder will do this. Project Builder appears to place file references in the bundle which aren't recognised as font files by the Carbon Font Manager and hence activation doesn't occur. I haven't figured out how to change this behaviour of PB yet.
2) The Carbon Font Manager activates all fonts in a container (ie font file) as a group. There is no way to activate a single font within a font file (eg activating only Cochin-Bold from the Cochin file also containing Cochin-Roman and Cochin-Italic).
3) The code above activates all the font containers in the bundle. To activate individual containers use [appBundle pathForResource:@"FontFileName" ofType:/*@"otf" or @"ttf" or @"suit" etc*/]. You may pass ofType:nil may be used if the font file name is unique  ie you aren't including different formats with the same name.
4) Local activation is accomplished by passing kFMLocalActivationContext to FMActivateFonts.
5) To my knowlege there is no way to activate fonts directly with the Cocoa API.
6) A method using the Core Foundation API is outlined in "Managing Fonts With the Font Manager" available as html and pdf at: http://developer.apple.com/techpubs/macosx/Carbon/text/FontManager/ fontmanager.html. This works just as well but is not as Cocoa-ish.

Regards,

Bela
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Passing ids to Distributed Objects
  • Next by Date: Drag and Drop a File... help!!
  • Previous by thread: Re: Override NSDocumentController?
  • Next by thread: Drag and Drop a File... help!!
  • Index(es):
    • Date
    • Thread