nil NSFont from fonts popup
nil NSFont from fonts popup
- Subject: nil NSFont from fonts popup
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 31 Jul 2002 19:13:14 +0100
I'm having trouble with my own-rolled font menu (in a popup button).
Selection of certain fonts from the menu (usually but _not always_
graphic fonts like Symbol or Animals) raises a "nil NSFont given" error.
This is how the menu is implemented:
- (void)awakeFromNib
{
int fontsCount;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSArray *fontsArray = [[NSArray alloc] initWithArray:[fontManager
availableFontFamilies]];
NSArray *sortedFontsArray = [fontsArray
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (fontsCount = 0; fontsCount < [sortedFontsArray count];
fontsCount++) {
if (![[[sortedFontsArray objectAtIndex:fontsCount]
substringToIndex:1] isEqualToString:@"#"]) {
[fontMenuPopUp addItemWithTitle:[sortedFontsArray
objectAtIndex:fontsCount]];
}
}
[fontsArray release];
}
- (IBAction)fontChoiceAction:(id)sender
{
NSFont *chosenFont;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
chosenFont = [fontManager convertFont:[[notepad textView] font]
toFamily:[sender titleOfSelectedItem]];
[[notepad textView] setFont:chosenFont];
[prefs setObject:[sender titleOfSelectedItem] forKey:@"Font Pref"];
}
I've tried to filter out invalid fonts by using -availableFontFamilies
rather than -availableFonts, and adding the -if statement to get rid of
families starting with "#", but family names which should return valid
fonts are returning nil. What am I doing wrong?
-Jeremy
=======================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.