Skip navigation.
 
mlRe: Installing a font programmatically?
FROM : John Stiles
DATE : Mon Nov 22 23:07:49 2004

If you change that kATSFontContextLocal to a different constant, other 
apps will be able to see the font as long as you're running.
If they still need to see the font after you quit... well then you've 
got a valid issue :)


On Nov 22, 2004, at 12:39 PM, Glen Simmons wrote:

> Sorry, I didn't explain myself sufficiently. I need for other apps to 
> be able to access the font, so I do actually need to get the font into 
> the proper place. So, I'm still looking for insights on what happens 
> if my app copies the font into the Fonts folder. i.e. would a 
> logout/login be necessary? What about permissions? etc.
>
> Would this code allow my app to load and use the font without having 
> to relaunch or logout/login?
>
> Thanks,
> Glen
>
> On 22 Nov, 2004, at 2:21 PM, John Stiles wrote:
>

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