Loading fonts with kATSFontContextGlobal
Loading fonts with kATSFontContextGlobal
- Subject: Loading fonts with kATSFontContextGlobal
- From: Thomas Deniau <email@hidden>
- Date: Sat, 15 May 2004 09:30:14 +0200
Hi !
I have to load some fonts from inside my application bundle.
Here is the code I use (path is the path (NSString*) to the font) :
NSFont *f=nil;
CFStringRef fontName=NULL;
ATSFontContainerRef container;
FSRef fsRef;
FSSpec fsSpec;
int osstatus = FSPathMakeRef((const UInt8*)[path UTF8String], &fsRef,
NULL);
osstatus =
FSGetCatalogInfo(&fsRef,kFSCatInfoNone,NULL,NULL,&fsSpec,NULL);
osstatus = ATSFontActivateFromFileSpecification ( &fsSpec,
kATSFontContextLocal, kATSFontFormatUnspecified,
NULL, kATSOptionFlagsDefault, &container);
if (osstatus != noErr) NSLog(@"Got error %d loading %@
!!!",osstatus,path);
else
{
ItemCount count;
osstatus = ATSFontFindFromContainer (container,
kATSOptionFlagsDefault, 0, NULL,&count);
ATSFontRef *ioArray=(ATSFontRef *)malloc(count * sizeof(ATSFontRef));
osstatus = ATSFontFindFromContainer (container,
kATSOptionFlagsDefault, count, ioArray,&count);
osstatus = ATSFontGetName (ioArray[0], kATSOptionFlagsDefault,
&fontName);
if (fontName) f = [NSFont fontWithName:(NSString*)fontName size:24];
}
This code works fine.
(I can check with the debugger that osstatus is always noErr, and f is
a valid NSFont*)
However I'd now like to make the font available to other applications
so that I can offer a Service.
BUT when I replace kATSFontContextLocal with kATSFontContextGlobal
(which according to the doc makes the font available to other
applications), suddenly this code fails and osstatus becomes -50 after
ATSFontActivateFromFileSpecification.
I haven't found this code in the ATS result codes and I have zero
experience with Carbon...
So ? Why does a global context make this code fail ?
Thank you in advance,
--
Thomas Deniau
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.