fontWithFamily returns nil?

356 Views Asked by At

We're trying to create a font by doing something like the following:

NSFont * font;
font = [[NSFontManager sharedFontManager]
            fontWithFamily:@"Arial"
            traits:(NSUnboldFontMask | NSUnitalicFontMask)
            weight:5
            size:8.0];

But the font manager is returning "nil". I've verified that the "Arial" font is present on the customer's computer. Is there anything else that could be going on here?

The documentation doesn't talk about it at all, other than saying "it might return nil". Is there anything I can do other than "pick a font from the list of available fonts that the font manager reports exist"?

2

There are 2 best solutions below

1
On

I'm not sure why that's not working for you (it does here) but you might try using the simpler NSFont method:

NSFont* font = [NSFont fontWithName:@"Arial" size:8];
0
On

Go visit your Font Book app in OSX, and confirm that the font is not disabled. This is often the case when you migrate from another computer it seems.