How can I get a list of the available NSFont families, preferably with the fontName: equivalents.
#import
@interface FontController : NSObject {
IBOutlet NSTextField *text;
}
- (IBAction)takeFontFamilyFrom: (id)sender;
- (IBAction)takeFontSizeFrom: (id)sender;
- (IBAction)takeFontAttributeFrom: (id)sender;
@end
#import "FontController.h"
NSFontManager *fm;
@implementation FontController
+ (void)initialize
{
fm = [NSFontManager sharedFontManager];
}
- (IBAction)takeFontFamilyFrom: (id)sender
{
NSFont *font = [text font];
font = [fm convertFont: font
toFamily: [sender stringValue]];
[text setFont: font];
}
- (IBAction)takeFontSizeFrom: (id)sender
{
NSFont *font = [text font];
font = [fm convertFont: font
toSize: [sender doubleValue]];
[text setFont: font];
}
- (IBAction)takeFontAttributeFrom: (id)sender
{
NSFont *font = [text font];
NSFontTraitMask attribute = [sender tag];
if (NSOnState == [sender state])
{
font = [fm convertFont: font toHaveTrait: attribute];
}
else
{
font = [fm convertFont: font toNotHaveTrait: attribute];
}
[sender setState: ([fm traitsOfFont: font] & attribute)];
[text setFont: font];
}
@end