views:

274

answers:

2

Prior to OSX 10.6, ATSFontActivateFromFileSpecification/ATSFontActivateFromFileReference were available and could be used to load a font from a file. I can't find anything similar in Core Text.

+1  A: 

It looks like CTFontManagerCreateFontDescriptorsFromURL is the Core Text replacement.

minus1
+3  A: 

You can get a CTFontRef from a file by going via a CGFontRef:

CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/font"), kCFURLPOSIXPathStyle, false);
CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url);
CGFontRef theCGFont = CGFontCreateWithDataProvider(dataProvider);
CTFontRef theCTFont = CTFontCreateWithGraphicsFont(theCGFont);
CFRelease(theFont);
CFRelease(dataProvider);
CFRelease(url);

//do something with the CTFontRef here

CFRelease(theCTFont);
Rob Keniger