OSDN Git Service

implement a function to change font on the glyph view, and add the HOME variable...
[sawarabi-fonts/sawarabi-fonts.git] / chartool / objective-c / Controller.m
index 7bc2b29..0620bcc 100644 (file)
        NSMenuItem* menu = [glyphViewMenu itemAtIndex: 1];
        NSMenu* p = [[NSMenu alloc] init];
        
-       for (int i = 0; i <= [nm count]; i++) {
+       [p setAutoenablesItems: NO];
+       int i = 0;
+       do {
                NSString* t = i == 0 ? @"default" : [nm objectAtIndex: i - 1];
                NSMenuItem* m = [[NSMenuItem alloc] init];
                [m setTitle: t];
+               [m setAction: @selector(changeFont:)];
+               [m setTarget: self];
+               [m setEnabled: YES];
                [p addItem: m];
-       }
+       } while (nm != NULL && ++i <= [nm count]);
        [menu setSubmenu: p];
 }
 
        
        NSSize vsz = [glyphView bounds].size;
        NSImage *m = [[NSImage alloc] initWithSize: vsz];
-       NSSize ssz = [s sizeWithAttributes: [self genFontAttrDict: nil size: dummy]];
+       NSSize ssz = [s sizeWithAttributes: [self genFontAttrDict: currentFont size: dummy]];
        float fsize = dummy * 
                (vsz.width >= vsz.height ? 1 / ssz.height * vsz.height :
                 1 / ssz.width * vsz.width);
-       NSDictionary *attr = [self genFontAttrDict: nil size: fsize];
+       NSDictionary *attr = [self genFontAttrDict: currentFont size: fsize];
        ssz = [s sizeWithAttributes: attr];
        int margin = (vsz.width - ssz.width) / 2;
        [m lockFocus];
        }
 }
 
+- (IBAction) changeFont: (id) sender {
+       currentFont = [sender title];
+       if (currentCharacter != nil) {
+               [self drawOnGlyphView: currentCharacter];
+       }
+}
+
 @end