OSDN Git Service

searching can be executed when typing a return key, and some names of variables or...
authormshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Wed, 23 Feb 2011 13:31:52 +0000 (13:31 +0000)
committermshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Wed, 23 Feb 2011 13:31:52 +0000 (13:31 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@23 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.h
chartool/objective-c/JavaScriptEngine.m

index 95deb6b..a88725d 100644 (file)
@@ -27,4 +27,6 @@
 - (IBAction) copyGlyphCharacter:(id)sender;
 - (IBAction) changeFont: (id)sender;
 
+- (BOOL) control: (NSControl *) control textView: (NSTextView *) textView doCommandBySelector: (SEL) command;
+
 @end
index 7f96e3c..9bb99ff 100644 (file)
 @implementation Controller
 
 - (id) init {
-       currentCharacter = nil;
        engine = [JavaScriptEngine instance];
        charUtil = [UnicharUtil instance];
        return [super init];
 }
 
 - (void) setupFontMenu {
-       NSArray* nm = [engine getFontsNameArray];
+       NSArray* nm = [engine fontNamesWithArray];
        NSMenuItem* menu = [glyphViewMenu itemAtIndex: 1];
        NSMenu* p = [[NSMenu alloc] init];
        
                        f, NSFontAttributeName, nil];
 }
 
-- (void) drawOnGlyphView: (NSString*) s {
+- (void) drawOnGlyphView: (NSString*) string {
        float dummy = 24.0;
        
-       NSSize vsz = [glyphView bounds].size;
-       NSImage *m = [[NSImage alloc] initWithSize: vsz];
-       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: currentFont size: fsize];
-       ssz = [s sizeWithAttributes: attr];
-       int margin = (vsz.width - ssz.width) / 2;
-       [m lockFocus];
-       [s drawAtPoint: NSMakePoint(margin, 0) withAttributes: attr];
-       [m unlockFocus];
-       [glyphView setImage: m];
+       NSSize viewSize = [glyphView bounds].size;
+       NSImage* image = [[NSImage alloc] initWithSize: viewSize];
+       NSSize stringSize = [string sizeWithAttributes: 
+                                                [self genFontAttrDict: currentFont size: dummy]];
+       float fontSize = dummy * 
+               (viewSize.width >= viewSize.height ? 1 / stringSize.height * viewSize.height :
+                1 / stringSize.width * viewSize.width);
+       NSDictionary *attr = [self genFontAttrDict: currentFont size: fontSize];
+       stringSize = [string sizeWithAttributes: attr];
+       int margin = (viewSize.width - stringSize.width) / 2;
+       [image lockFocus];
+       [string drawAtPoint: NSMakePoint(margin, 0) withAttributes: attr];
+       [image unlockFocus];
+       [glyphView setImage: image];
 }
 
-- (NSRange) getTargetRangeFrom: (NSString*) text withLocation: (int) loc {
-       unichar ch = [text characterAtIndex: loc];
+- (NSRange) getTargetRangeFrom: (NSString*) text withLocation: (int) location {
+       unichar ch = [text characterAtIndex: location];
        
        int rlen = 0, llen = 0;
        while (rlen <= 4 && [charUtil characterIsHexCharacter: ch]) {
                rlen++;
-               if (loc + rlen >= [text length]) break;
-               ch = [text characterAtIndex: loc + rlen];
+               if (location + rlen >= [text length]) break;
+               ch = [text characterAtIndex: location + rlen];
        }
        if (rlen >= 1 && rlen < 5) {
-               while (rlen + llen <= 4 && loc - llen > 0) {
-                       ch = [text characterAtIndex: loc - llen - 1];
+               while (rlen + llen <= 4 && location - llen > 0) {
+                       ch = [text characterAtIndex: location - llen - 1];
                        if (! [charUtil characterIsHexCharacter: ch]) break;
                        llen++;
                }
        }
 
-       return NSMakeRange(loc - llen, rlen + llen);
+       return NSMakeRange(location - llen, rlen + llen);
 }
 
-- (NSString*) getCharacterFrom: (NSString*) text withRange: (NSRange) range andLocation: (int) loc {
+- (NSString*) getCharacterFrom: (NSString*) text withRange: (NSRange) range andLocation: (int) location {
        if (range.length >= 4) {
                return [charUtil getUnicharFromCharCode: [text substringWithRange: range]];
        } else {
                unichar ch = [text characterAtIndex: range.location];
                BOOL high = [charUtil characterIsHighSurrogate: ch];
                BOOL low = [charUtil characterIsLowSurrogate: ch];
-               int p = loc - (low ? 1 : 0);
+               int p = location - (low ? 1 : 0);
                return [text substringWithRange: 
-                               NSMakeRange(p < 0 ? 0 : loc, high || low ? 2 : 1)];
+                               NSMakeRange(p < 0 ? 0 : location, high || low ? 2 : 1)];
        }
 }
 
+- (BOOL) control: (NSControl *) control textView: (NSTextView *) textView doCommandBySelector: (SEL) command {
+       if (command == @selector(insertNewline:)) {
+               [self search: control];
+               return YES;
+       }
+       return NO;
+}
+
 - (IBAction) search: (id) sender {
-       NSString *text = [searchField stringValue];
-       if ([text length] <=0) return;
+       NSStringtext = [searchField stringValue];
+       if ([text length] <= 0) return;
 
        NSText* editor = [searchField currentEditor];
-       NSRange r = [editor selectedRange];
-       int loc = r.location + r.length < [text length] ? r.location + r.length : 0;
+       NSRange range = [editor selectedRange];
+       int loc = range.location + range.length < [text length] ? range.location + range.length : 0;
        NSRange tr = [self getTargetRangeFrom: text withLocation: loc];
        NSString* ch = [self getCharacterFrom: text withRange: tr andLocation: loc];
-       
+
        currentCharacter = ch;
        [editor setSelectedRange: 
         tr.length < 4 ? NSMakeRange(loc, [ch length]) : NSMakeRange(tr.location, tr.length)];
index c66a71a..420b83e 100644 (file)
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
-                                               <string key="label">delegate</string>
-                                               <reference key="source" ref="37035572"/>
-                                               <reference key="destination" ref="507161502"/>
-                                       </object>
-                                       <int key="connectionID">506</int>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
                                                <string key="label">codeField</string>
                                                <reference key="source" ref="507161502"/>
                                                <reference key="destination" ref="719467350"/>
                                        </object>
                                        <int key="connectionID">523</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">delegate</string>
+                                               <reference key="source" ref="37035572"/>
+                                               <reference key="destination" ref="507161502"/>
+                                       </object>
+                                       <int key="connectionID">527</int>
+                               </object>
                        </object>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <object class="NSArray" key="orderedObjects">
                                </object>
                        </object>
                        <nil key="sourceID"/>
-                       <int key="maxID">523</int>
+                       <int key="maxID">528</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <object class="NSMutableArray" key="referencedPartialClassDescriptions">
index 2609f1c..94aaa8f 100644 (file)
@@ -15,7 +15,7 @@
 
 + (JavaScriptEngine *) instance;
 - (NSString *) evaluate: (NSString *) script;
-- (NSArray *) getFontsNameArray;
+- (NSArray *) fontNamesWithArray;
 - (void) executeScriptAtIndex: (int) index withProperty: (NSString*) property AndModifier: (int) modifier;
 
 @end
index f2a9192..cd2d85a 100644 (file)
@@ -149,7 +149,7 @@ static JSValueRef jsOpenFile(JSContextRef ctx,
        return [(NSString *) resultString autorelease];
 }
 
-- (NSArray *) getFontsNameArray {
+- (NSArray *) fontNamesWithArray {
        NSString* v = [self evaluate: @"font"];
        if (! [v isEqualToString: @"[Exception]"]) {
                NSArray* r = [v componentsSeparatedByString: @","];