Hi everybody
I want to have a list of all my working fonts in a popup button.
I am using Suitcase to manage my font, if it helps…
thank you all
Hi everybody
I want to have a list of all my working fonts in a popup button.
I am using Suitcase to manage my font, if it helps…
thank you all
Here’s a method that uses the cocoa font manager to get a list of all the current fonts.
I’ve set it up in a window ‘will open’ handler so the menu updates whenever it’s window opens. I also added a few frills like a title menu item and a call method to add a separator item. Figured you might want them, but if not just delete them. I placed the menu-building code in a subroutine so you could also call it in other ways.
Applescript…
on will open theObject
if name of theObject is "fontWindow" then
updateFontMenu()
end if
end will open
to updateFontMenu()
set fontArray to call method "getFontArray" of class "JBFontController"
tell menu of popup button "fontMenu" of window "fontWindow"
(* Delete all existing menu items *)
delete every menu item
(* Create the first menu item... the menu's "Title" *)
make new menu item at end of menu items with properties {name:"Default", title:"Fonts:", enabled:true}
(* Create a separator Item *)
set theMenu to it
call method "addMenuSeparator:" of class "JBFontController" with parameters {theMenu}
(* Create a menu item for every font in the array *)
repeat with tmpFont in fontArray
make new menu item at end of menu items with properties {name:tmpFont, title:tmpFont, enabled:true}
end repeat
end tell
end updateFontMenu
Obj-c cocoa file named “JBFontController.m” (no .h file necessary)…
#import <Cocoa/Cocoa.h>
#import <AppKit/AppKit.h>
@interface JBFontController : NSObject
+(NSArray *)getFontArray;
+(void)addMenuSeparator:(NSMenu *)theMenu;
@end
@implementation JBFontController
+(NSArray *)getFontArray {
NSArray *fontArray;
fontArray = [[[NSFontManager sharedFontManager] availableFontFamilies] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
return fontArray;
}
+(void)addMenuSeparator:(NSMenu *)theMenu {
[theMenu addItem: [NSMenuItem separatorItem]];
}
@end
Let me know if any of this doesn’t make sense.
j
Hi J
I think I need your help with this.
after I added a new file and paste the coca code it will run and quit with some errors
the code looks like this:
//
// JBFontControlle.m
// eee
//
// Created by Yarnin on 11/10/04.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <AppKit/AppKit.h>
@interface JBFontController : NSObject
+(NSArray *)getFontArray;
+(void)addMenuSeparator:(NSMenu *)theMenu;
@end
@implementation JBFontController
+(NSArray *)getFontArray {
NSArray *fontArray;
fontArray = [[[NSFontManager sharedFontManager] availableFontFamilies] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
return fontArray;
}
+(void)addMenuSeparator:(NSMenu *)theMenu {
[theMenu addItem: [NSMenuItem separatorItem]];
}
@end