Re: How to get bold and plain fonts?
Re: How to get bold and plain fonts?
- Subject: Re: How to get bold and plain fonts?
- From: Graham Cox <email@hidden>
- Date: Sun, 31 May 2015 15:47:11 +1000
> On 31 May 2015, at 1:44 pm, Kyle Sluder <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden