Skip navigation.
 
mlRe: Installing a font programmatically?
FROM : John Stiles
DATE : Mon Nov 22 21:21:33 2004

You can load the font in code when you app starts up, without
installing it anywhere. Just keep it in your bundle.
Here's some code, copy-and-pasted from my app.

   ATSFontContainerRef container;
   OSStatus err = ATSFontActivateFromMemory(
                       data.Ptr<void>(),
                       data.Size(),
                       kATSFontContextLocal,
                       kATSFontFormatUnspecified,
                       NULL,
                       kATSOptionFlagsDefault,
                       &container );
   
   if( err != noErr )
       return NULL;
   
   ATSFontRef fontRefs[100];
   ItemCount  fontCount;
   err = ATSFontFindFromContainer(
                       container,
                       kATSOptionFlagsDefault,
                       arrsize(fontRefs),
                       fontRefs,
                       &fontCount );
   
   if( err != noErr || fontCount < 1 )
       return NULL;

   NSString *fontName;
   err = ATSFontGetPostScriptName(
                       fontRefs[0],
                       kATSOptionFlagsDefault,
                       reinterpret_cast<CFStringRef*>( &fontName ) );    
   // now you can use [NSFont fontWithName:fontName size:size];


On Nov 22, 2004, at 11:49 AM, Glen Simmons wrote:

> I need to install a font for one of the features of my app to work.
> I'd really like to avoid building an installer just to put this one
> file in the Fonts folder. Can this be done programmatically in a safe,
> clean way? I'm concerned about permissions, availability to apps,
> location (~/Fonts vs /Fonts), etc. Any insights would be most
> appreciated.
>
> Thanks,
> Glen Simmons
>
> Opportunity is missed by most because it is dressed in overalls and
> looks like work. -- Thomas Alva Edison
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlInstalling a font programmatically? Glen Simmons Nov 22, 20:49
mlRe: Installing a font programmatically? John Stiles Nov 22, 21:21
mlRe: Installing a font programmatically? Glen Simmons Nov 22, 21:39
mlRe: Installing a font programmatically? John C. Randolph Nov 22, 22:33
mlRe: Installing a font programmatically? John Stiles Nov 22, 23:07