OSDN Git Service

implement a function to change font on the glyph view, and add the HOME variable...
authormshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Sat, 19 Feb 2011 10:01:35 +0000 (10:01 +0000)
committermshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Sat, 19 Feb 2011 10:01:35 +0000 (10:01 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@19 54a90f34-5e62-402c-8eae-46c47f0b2e07

chartool/objective-c/Controller.h
chartool/objective-c/Controller.m
chartool/objective-c/English.lproj/MainMenu.xib
chartool/objective-c/JavaScriptEngine.m

index 9422ec2..95deb6b 100644 (file)
        IBOutlet NSMenu* glyphViewMenu;
 
        NSString* currentCharacter;
        IBOutlet NSMenu* glyphViewMenu;
 
        NSString* currentCharacter;
+       NSString* currentFont;
        JavaScriptEngine* engine;
        UnicharUtil* charUtil;
 }
 - (IBAction) search:(id)sender;
 - (IBAction) clickScriptButton: (id)sender;
 - (IBAction) copyGlyphCharacter:(id)sender;
        JavaScriptEngine* engine;
        UnicharUtil* charUtil;
 }
 - (IBAction) search:(id)sender;
 - (IBAction) clickScriptButton: (id)sender;
 - (IBAction) copyGlyphCharacter:(id)sender;
+- (IBAction) changeFont: (id)sender;
 
 @end
 
 @end
index 7bc2b29..0620bcc 100644 (file)
        NSMenuItem* menu = [glyphViewMenu itemAtIndex: 1];
        NSMenu* p = [[NSMenu alloc] init];
        
        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];
                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];
                [p addItem: m];
-       }
+       } while (nm != NULL && ++i <= [nm count]);
        [menu setSubmenu: p];
 }
 
        [menu setSubmenu: p];
 }
 
        
        NSSize vsz = [glyphView bounds].size;
        NSImage *m = [[NSImage alloc] initWithSize: vsz];
        
        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);
        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];
        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
 @end
index da02e28..c66a71a 100644 (file)
@@ -12,9 +12,9 @@
                </object>
                <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
                        <bool key="EncodedWithXMLCoder">YES</bool>
                </object>
                <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
                        <bool key="EncodedWithXMLCoder">YES</bool>
-                       <integer value="510"/>
-                       <integer value="57"/>
                        <integer value="471"/>
                        <integer value="471"/>
+                       <integer value="518"/>
+                       <integer value="57"/>
                </object>
                <object class="NSArray" key="IBDocument.PluginDependencies">
                        <bool key="EncodedWithXMLCoder">YES</bool>
                </object>
                <object class="NSArray" key="IBDocument.PluginDependencies">
                        <bool key="EncodedWithXMLCoder">YES</bool>
                        <object class="NSWindowTemplate" id="376871716">
                                <int key="NSWindowStyleMask">15</int>
                                <int key="NSWindowBacking">2</int>
                        <object class="NSWindowTemplate" id="376871716">
                                <int key="NSWindowStyleMask">15</int>
                                <int key="NSWindowBacking">2</int>
-                               <string key="NSWindowRect">{{10, 800}, {341, 122}}</string>
+                               <string key="NSWindowRect">{{3, 855}, {341, 122}}</string>
                                <int key="NSWTFlags">603980800</int>
                                <string key="NSWindowTitle">chartool</string>
                                <string key="NSWindowClass">NSPanel</string>
                                <int key="NSWTFlags">603980800</int>
                                <string key="NSWindowTitle">chartool</string>
                                <string key="NSWindowClass">NSPanel</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       <string>{{18, 855}, {341, 122}}</string>
+                                       <string>{{3, 855}, {341, 122}}</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       <string>{{18, 855}, {341, 122}}</string>
+                                       <string>{{3, 855}, {341, 122}}</string>
                                        <boolean value="YES"/>
                                        <boolean value="YES"/>
                                        <string>{341, 122}</string>
                                        <boolean value="YES"/>
                                        <boolean value="YES"/>
                                        <string>{341, 122}</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       <string>{{93, 926}, {86, 23}}</string>
+                                       <string>{{90, 926}, {83, 23}}</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                                <bool key="EncodedWithXMLCoder">YES</bool>
                                                <object class="NSArray" key="dict.sortedKeys">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                <bool key="EncodedWithXMLCoder">YES</bool>
                                                <object class="NSArray" key="dict.sortedKeys">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <string>changeFont:</string>
                                                        <string>clickScriptButton:</string>
                                                        <string>copyGlyphCharacter:</string>
                                                        <string>search:</string>
                                                        <string>clickScriptButton:</string>
                                                        <string>copyGlyphCharacter:</string>
                                                        <string>search:</string>
                                                        <string>id</string>
                                                        <string>id</string>
                                                        <string>id</string>
                                                        <string>id</string>
                                                        <string>id</string>
                                                        <string>id</string>
+                                                       <string>id</string>
                                                </object>
                                        </object>
                                        <object class="NSMutableDictionary" key="actionInfosByName">
                                                <bool key="EncodedWithXMLCoder">YES</bool>
                                                <object class="NSArray" key="dict.sortedKeys">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                </object>
                                        </object>
                                        <object class="NSMutableDictionary" key="actionInfosByName">
                                                <bool key="EncodedWithXMLCoder">YES</bool>
                                                <object class="NSArray" key="dict.sortedKeys">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <string>changeFont:</string>
                                                        <string>clickScriptButton:</string>
                                                        <string>copyGlyphCharacter:</string>
                                                        <string>search:</string>
                                                        <string>clickScriptButton:</string>
                                                        <string>copyGlyphCharacter:</string>
                                                        <string>search:</string>
                                                <object class="NSMutableArray" key="dict.values">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                        <object class="IBActionInfo">
                                                <object class="NSMutableArray" key="dict.values">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                        <object class="IBActionInfo">
+                                                               <string key="name">changeFont:</string>
+                                                               <string key="candidateClassName">id</string>
+                                                       </object>
+                                                       <object class="IBActionInfo">
                                                                <string key="name">clickScriptButton:</string>
                                                                <string key="candidateClassName">id</string>
                                                        </object>
                                                                <string key="name">clickScriptButton:</string>
                                                                <string key="candidateClassName">id</string>
                                                        </object>
index fc2e24e..f0a5878 100644 (file)
@@ -75,6 +75,14 @@ static JSValueRef jsOpenFile(JSContextRef ctx,
        JSStringRelease(nm);
 }
 
        JSStringRelease(nm);
 }
 
+- (void) setValue: (const char*) value ToVariable: (const char*) name {
+       JSObjectRef object = JSContextGetGlobalObject(context);
+       JSStringRef nm = JSStringCreateWithUTF8CString(name);
+       JSValueRef var = JSValueMakeString(context, JSStringCreateWithUTF8CString(value));
+       JSObjectSetProperty(context, object, nm, var, kJSPropertyAttributeNone, NULL);
+       JSStringRelease(nm);
+}
+
 - (void) setFunctions {
        [self setFunction:(JSObjectCallAsFunctionCallback) jsAlert withName: "alert"];
        [self setFunction:(JSObjectCallAsFunctionCallback) jsOpenFile withName: "openFile"];
 - (void) setFunctions {
        [self setFunction:(JSObjectCallAsFunctionCallback) jsAlert withName: "alert"];
        [self setFunction:(JSObjectCallAsFunctionCallback) jsOpenFile withName: "openFile"];
@@ -82,13 +90,14 @@ static JSValueRef jsOpenFile(JSContextRef ctx,
 
 - (void) loadScript {
        NSString* script;
 
 - (void) loadScript {
        NSString* script;
-       NSString* path = @"./js/charpalette.js";
+       NSString* path = [[NSString alloc] initWithFormat: @"%@/.charpalette.js", NSHomeDirectory()];
        NSError* error;
        
        script = [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: &error];
        if (script) {
                [self evaluateScript: script];
                [self setFunctions];
        NSError* error;
        
        script = [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: &error];
        if (script) {
                [self evaluateScript: script];
                [self setFunctions];
+               [self setValue: [NSHomeDirectory() UTF8String] ToVariable: "HOME"];
        } else {
                NSLog(@"the js file is not found");
        }
        } else {
                NSLog(@"the js file is not found");
        }
@@ -122,9 +131,13 @@ static JSValueRef jsOpenFile(JSContextRef ctx,
 
 - (NSArray *) getFontsNameArray {
        NSString* v = [self evaluate: @"font"];
 
 - (NSArray *) getFontsNameArray {
        NSString* v = [self evaluate: @"font"];
-       NSArray* r = [v componentsSeparatedByString: @","];
+       if (! [v isEqualToString: @"[Exception]"]) {
+               NSArray* r = [v componentsSeparatedByString: @","];
 
 
-       return r;
+               return r;
+       } else {
+               return NULL;
+       }
 }
 
 - (void) release {
 }
 
 - (void) release {