A quick test (in Swift no less) suggests to me that this function just doesn’t 
work (TM). 

I get non-zero results for these 13 flag combinations (count of fonts + mask) 
and zero results for every other one of the 4096 combinations. 

141     NSItalicFontMask
259     NSBoldFontMask
61      NSItalicFontMask + NSBoldFontMask
6       NSExpandedFontMask
3       NSExpandedFontMask + NSBoldFontMask
43      NSCondensedFontMask 
12      NSCondensedFontMask + NSItalicFontMask
22      NSCondensedFontMask + NSBoldFontMask
6       NSCondensedFontMask + NSItalicFontMask + NSBoldFontMask
30      NSFixedPitchFontMask 
11      NSFixedPitchFontMask + NSItalicFontMask
11      NSFixedPitchFontMask + NSBoldFontMask
5       NSFixedPitchFontMask + NSItalicFontMask + NSBoldFontMask

I think you’re probably better off calling availableFontFamilies then iterating 
those with availableMembersOfFontFamily: and picking out the ones you want from 
there. That’s probably better anyway as it will give you all the font families 
which have both a plain and a bold option which sounds like what you might 
want. I’d try it out but I’ve exhausted my Swift-fu for the day. 


> On 31 May 2015, at 10:42, Graham Cox <graham....@bigpond.com> wrote:
> 
> I’m using -[NSFontManager availableFontNamesWithTraits:] and I want to get 
> the names of all of the fonts that have both a regular (plain) and bold 
> option.
> 
> I’ve tried various things, but this seems like it should work:
> 
>       NSArray* fonts = [[NSFontManager sharedFontManager] 
> availableFontNamesWithTraits:NSBoldFontMask | NSUnboldFontMask];
> 
> Except it returns no results. According to the docs if I pass 0 for traits, 
> it should return all the plain fonts, and it’s equivalent to NSUnboldFontMask 
> | NSUnitalicFontMask. That returns no results.
> 
> If I set it to a single value, such as NSBoldFontMask, I get all the bold 
> fonts, but no plain ones. I also tried NSBoldFontMask | NSUnboldFontMask | 
> NSUnitalicFontMask, but that returns no results.
> 
> What’s the magic traits mask I need? Seems like it should be a simple thing 
> to get plain + bold, except that a bit mask doesn’t really work to express 
> this, because there’s no value for “plain” - plain is the absence of any 
> other trait. So how do I ask for it?
> 
> —Graham
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to r...@rols.org

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to