I have a NSFont
whose size, family, traits I would like to modify.
I found that I can use NSFontManager
to do so (using e.g. convertFont:toFamily
or convertFont:toSize
), but I suspected that there would be some possibility to alter all at once (I imagined something like convertFont:toFamily:toSize:toHaveTrait
). However, I have not found any such thing, which is why I am currently doing a stepwise transformation.
Another thing I have considered is using a NSFontDescriptor
. However, using this seems a bit cumbersome if I already start with an NSFont (NSFont -> NSFontDescriptor -> modified NSFontDescriptor -> modified NSFont
looks more verbose to me than NSFont -> converted NSFont
).
So, is there an ideomatic way of converting NSFont
s? And if so, what is it?
Font descriptors are the usual way to approach this. See Using Fonts with Text Kit from WWDC 2013 starting around 26:00 (this talk is focused on UIKit, but many of the principles apply to AppKit as well). NSFontManager
is designed to work with an interactive font-picker UI (particularly the Font Panel). If you're interacting with the user-selected font (in a UI-kind of way), you should definitely use NSFontManager
, but in most cases then you're modifying things piecemeal as the user selects and deselects various options. If you're manipulating fonts independently of the user, you probably want to use font descriptors, particularly so you don't unintentionally modify the font panel.