Not able to load a custom font into an OSX project but... am into an iOS project?

161 views Asked by At

I am able to load a custom font in an iOS project and see it on the available fonts using:

NSArray *fontFamilies = [UIFont familyNames];

for (int i=0; i<[fontFamilies count]; i++)
{
    NSLog(@"Font: %@ ...", [fontFamilies objectAtIndex:i]);
}

But when I try and load the font into the OSX project, I am not able to see it in the list when I display the fonts:

NSLog(@"%@",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);

I used: Unable to set custom font for the UILabel in XCode to install the font for iOS project and assumed it should be the same approach for the OSX project.

The link to the font file is in the bundle resources, Info.plist file(add: Fonts provided by application), and the file is in the Supporting files.

Am I missing something? thx

1

There are 1 answers

0
jdl On

I solved it programmatically(but would prefer the approach like iOS approach in the link above):

NSString* path = [[NSBundle mainBundle] pathForResource:@"Symbola" ofType:@"ttf"];
NSURL* fontsURL = [NSURL fileURLWithPath:path];

FSRef fsRef;
CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, kATSFontFormatUnspecified,
                                              NULL, kATSOptionFlagsDefault, NULL);