Re: How to get bold and plain fonts?

2015-05-31 Thread Graham Cox

 On 31 May 2015, at 4:43 pm, Roland King r...@rols.org wrote:
 
 
 So, TL;DR: how do I find the Font Family name(s) corresponding to an 
 arbitrary list of NSFontDescriptors from a font collection?
 
 —Graham
 
 
 
 just looking at the docs for NSFontDescriptor I would guess
 
   [ fontDescriptor objectForKey:NSFontFamilyAttribute ]


D’oh!!! As simple as that.

Thanks…

—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/archive%40mail-archive.com

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

Re: How to get bold and plain fonts?

2015-05-31 Thread Roland King
 
 So, TL;DR: how do I find the Font Family name(s) corresponding to an 
 arbitrary list of NSFontDescriptors from a font collection?
 
 —Graham
 
 

just looking at the docs for NSFontDescriptor I would guess

[ fontDescriptor objectForKey:NSFontFamilyAttribute ]
___

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

Re: How to get bold and plain fonts?

2015-05-30 Thread Roland King
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

Re: How to get bold and plain fonts?

2015-05-30 Thread Graham Cox

 On 31 May 2015, at 1:44 pm, Kyle Sluder k...@ksluder.com wrote:
 
 Here, you're asking for all fonts that consider themselves to be both
 bold and unbold. This set is going to be empty (unless you have a
 particularly broken font installed).


Yeah, I just realised that though of course you’re adding trait masks together 
with OR, the value is interpreted as AND, so A ~A = 0. Seems as if there’s no 
way to express what I want with this. It’s a terrible API anyway.

 If you want to query for fonts with certain traits, you're much better
 off using NSFontDescriptor.

I’ll look at that as a better alternative.

 On 31 May 2015, at 1:27 pm, Roland King r...@rols.org wrote:
 
 A quick test (in Swift no less) suggests to me that this function just 
 doesn’t work (TM). 


Looks that way :(

Thanks both.

—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/archive%40mail-archive.com

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

Re: How to get bold and plain fonts?

2015-05-30 Thread Kyle Sluder
On Sat, May 30, 2015, at 09:42 PM, Graham Cox 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];

Here, you're asking for all fonts that consider themselves to be both
bold and unbold. This set is going to be empty (unless you have a
particularly broken font installed).

 
 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.
 

This is a known bug.

If you want to query for fonts with certain traits, you're much better
off using NSFontDescriptor.

--Kyle Sluder

___

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

Re: How to get bold and plain fonts?

2015-05-30 Thread Graham Cox

 On 31 May 2015, at 1:44 pm, Kyle Sluder k...@ksluder.com wrote:
 
 you're much better
 off using NSFontDescriptor.



So here’s what I’m trying to do. I have a “simple” UI that, among many other 
things, allows the user to choose a font for various things in a display. I 
want to keep the set of choosable fonts down to something ”reasonable” rather 
than stacking it with every possible font. I’m using a pop-up button to present 
the fonts, so I want to avoid hierarchical menus which don’t really work very 
well in a pop-up button.

Looking at what NSFontManager provides, I can read in entire font collections 
that match what the user has set up in the Fonts panel, and that gave me the 
idea to actually look for a custom collection that has a particular name - I 
can document that creating a collection with such-and-such a name and 
populating it will show only those fonts the user added to the custom 
collection. That’s a nice way to limit the choice, because the user can set it 
up themselves how they want.

But I also need a fallback for when this hasn’t been done, so I thought I’d use 
the “User” collection and the Favourites” collection (the “User” collection’s 
name is localized I guess - in mine it’s “English”, but the actual collection 
name is “com.apple.UserFonts”).

When I ask NSFontManager for the descriptors in a collection, I get a very 
large number, one for each variant of a given font. I’d like to be able to 
collapse this down to match what the Font Panel displays - it only displays a 
single entry for each font family, then breaks that down using separate 
columns. I’d like my menu to match the first column, showing only the family 
names. Then I might offer only the plain and bold variants within that family. 
What I’m not clear about is how to go from a list of NSFontDescriptors to a 
common family that groups those descriptors. There seem to be many methods that 
expand a descriptor or family, but none that collapse a set of descriptors to a 
family. I’m happy to perform this collapsing myself, I’m just not sure how I 
should do it. A NSFontDescriptor doesn’t have a ‘family’ property, and the 
postscript name property is the full description of course. I could attempt to 
parse that to find the common root but I’m not sure if that’s reliable. It 
seems as if it could be, based on the fonts I have installed, but that doesn’t 
mean it is.

So, TL;DR: how do I find the Font Family name(s) corresponding to an arbitrary 
list of NSFontDescriptors from a font collection?

—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/archive%40mail-archive.com

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