From ba058d45a9f00141efea7c8b3cbf5ba7cc889f54 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 9 Aug 2007 10:22:52 +0000 Subject: [PATCH] - All user default key variables end with 'key' - Added user default keys: typesetter, cellwidthmultiplier, baselineoffset - Cell width calculations based on widht of 'm' (so that 'cellwidthmultiplier' is the width of a cell in em-units) git-svn-id: http://macvim.googlecode.com/svn/trunk@108 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMAppController.h | 13 ++++++++----- MMAppController.m | 29 ++++++++++++++++++----------- MMTextStorage.m | 7 ++++++- MMTypesetter.m | 6 ++++++ MMWindowController.m | 37 +++++++++++++++++++------------------ 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/MMAppController.h b/MMAppController.h index 086749e347..abf9a69bf0 100644 --- a/MMAppController.h +++ b/MMAppController.h @@ -18,11 +18,14 @@ extern NSString *MMTabMinWidthKey; extern NSString *MMTabMaxWidthKey; extern NSString *MMTabOptimumWidthKey; extern NSString *MMStatuslineOffKey; -extern NSString *MMTextInsetLeft; -extern NSString *MMTextInsetRight; -extern NSString *MMTextInsetTop; -extern NSString *MMTextInsetBottom; -extern NSString *MMTerminateAfterLastWindowClosed; +extern NSString *MMTextInsetLeftKey; +extern NSString *MMTextInsetRightKey; +extern NSString *MMTextInsetTopKey; +extern NSString *MMTextInsetBottomKey; +extern NSString *MMTerminateAfterLastWindowClosedKey; +extern NSString *MMTypesetterKey; +extern NSString *MMCellWidthMultiplierKey; +extern NSString *MMBaselineOffsetKey; diff --git a/MMAppController.m b/MMAppController.m index cfd4b1726d..220cec88db 100644 --- a/MMAppController.m +++ b/MMAppController.m @@ -19,11 +19,15 @@ NSString *MMTabMinWidthKey = @"tabminwidth"; NSString *MMTabMaxWidthKey = @"tabmaxwidth"; NSString *MMTabOptimumWidthKey = @"taboptimumwidth"; NSString *MMStatuslineOffKey = @"statuslineoff"; -NSString *MMTextInsetLeft = @"insetleft"; -NSString *MMTextInsetRight = @"insetright"; -NSString *MMTextInsetTop = @"insettop"; -NSString *MMTextInsetBottom = @"insetbottom"; -NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed"; +NSString *MMTextInsetLeftKey = @"insetleft"; +NSString *MMTextInsetRightKey = @"insetright"; +NSString *MMTextInsetTopKey = @"insettop"; +NSString *MMTextInsetBottomKey = @"insetbottom"; +NSString *MMTerminateAfterLastWindowClosedKey + = @"terminateafterlastwindowclosed"; +NSString *MMTypesetterKey = @"typesetter"; +NSString *MMCellWidthMultiplierKey = @"cellwidthmultiplier"; +NSString *MMBaselineOffsetKey = @"baselineoffset"; @@ -56,11 +60,14 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed"; [NSNumber numberWithInt:6*64], MMTabMaxWidthKey, [NSNumber numberWithInt:132], MMTabOptimumWidthKey, [NSNumber numberWithBool:NO], MMStatuslineOffKey, - [NSNumber numberWithInt:2], MMTextInsetLeft, - [NSNumber numberWithInt:1], MMTextInsetRight, - [NSNumber numberWithInt:1], MMTextInsetTop, - [NSNumber numberWithInt:1], MMTextInsetBottom, - [NSNumber numberWithBool:NO], MMTerminateAfterLastWindowClosed, + [NSNumber numberWithInt:2], MMTextInsetLeftKey, + [NSNumber numberWithInt:1], MMTextInsetRightKey, + [NSNumber numberWithInt:1], MMTextInsetTopKey, + [NSNumber numberWithInt:1], MMTextInsetBottomKey, + [NSNumber numberWithBool:NO], MMTerminateAfterLastWindowClosedKey, + @"MMTypesetter", MMTypesetterKey, + [NSNumber numberWithFloat:1.0], MMCellWidthMultiplierKey, + [NSNumber numberWithFloat:0.0], MMBaselineOffsetKey, nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; @@ -181,7 +188,7 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed"; - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return [[NSUserDefaults standardUserDefaults] - boolForKey:MMTerminateAfterLastWindowClosed]; + boolForKey:MMTerminateAfterLastWindowClosedKey]; } - (NSApplicationTerminateReply)applicationShouldTerminate: diff --git a/MMTextStorage.m b/MMTextStorage.m index c69dff86ff..08610b137f 100644 --- a/MMTextStorage.m +++ b/MMTextStorage.m @@ -9,6 +9,7 @@ */ #import "MMTextStorage.h" +#import "MMAppController.h" // If 0 DRAW_TRANSP flag will be ignored. Setting it to 1 causes the cursor // background to be drawn in white. @@ -510,7 +511,11 @@ - (float)cellWidth { - return [font widthOfString:@"W"]; + float em = [font widthOfString:@"m"]; + float cellWidthMultiplier = [[NSUserDefaults standardUserDefaults] + floatForKey:MMCellWidthMultiplierKey]; + + return em * cellWidthMultiplier; } @end // MMTextStorage diff --git a/MMTypesetter.m b/MMTypesetter.m index aa65b2d109..2ab3af4bbf 100644 --- a/MMTypesetter.m +++ b/MMTypesetter.m @@ -10,6 +10,7 @@ #import "MMTypesetter.h" #import "MMTextStorage.h" +#import "MMAppController.h" @@ -55,6 +56,11 @@ if (!(ts && tv && tc && font && text && textLen)) return; + float baselineOffset = [[NSUserDefaults standardUserDefaults] + floatForKey:MMBaselineOffsetKey]; + + baseline += baselineOffset; + unsigned startCharIdx = [lm characterIndexForGlyphAtIndex:startGlyphIdx]; unsigned i, numberOfLines = 0, firstLine = 0; NSRange firstLineRange = { 0, 0 }; diff --git a/MMWindowController.m b/MMWindowController.m index 2f3c863e12..6660df839b 100644 --- a/MMWindowController.m +++ b/MMWindowController.m @@ -8,8 +8,6 @@ * See README.txt for an overview of the Vim source code. */ -#define MM_USE_CUSTOM_TYPESETTER 1 - #import "MMWindowController.h" #import #import "MMTextView.h" @@ -17,10 +15,7 @@ #import "MMVimController.h" #import "MacVim.h" #import "MMAppController.h" - -#if MM_USE_CUSTOM_TYPESETTER -# import "MMTypesetter.h" -#endif +#import "MMTypesetter.h" // Scroller type; these must match SBAR_* in gui.h @@ -113,11 +108,17 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) NSTextContainer *tc = [[NSTextContainer alloc] initWithContainerSize: NSMakeSize(1.0e7,1.0e7)]; -#if MM_USE_CUSTOM_TYPESETTER - MMTypesetter *typesetter = [[MMTypesetter alloc] init]; - [lm setTypesetter:typesetter]; - [typesetter release]; -#endif + NSString *typesetterString = [[NSUserDefaults standardUserDefaults] + stringForKey:MMTypesetterKey]; + if (![typesetterString isEqual:@"NSTypesetter"]) { + MMTypesetter *typesetter = [[MMTypesetter alloc] init]; + [lm setTypesetter:typesetter]; + [typesetter release]; + } else { + // Only MMTypesetter supports different cell width multipliers. + [[NSUserDefaults standardUserDefaults] + setFloat:1.0 forKey:MMCellWidthMultiplierKey]; + } [tc setWidthTracksTextView:NO]; [tc setHeightTracksTextView:NO]; @@ -130,8 +131,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) textContainer:tc]; NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - int left = [ud integerForKey:MMTextInsetLeft]; - int top = [ud integerForKey:MMTextInsetTop]; + int left = [ud integerForKey:MMTextInsetLeftKey]; + int top = [ud integerForKey:MMTextInsetTopKey]; [textView setTextContainerInset:NSMakeSize(left, top)]; // The text storage retains the layout manager which in turn retains @@ -628,8 +629,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) NSSize size = textViewSize; NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - int right = [ud integerForKey:MMTextInsetRight]; - int bot = [ud integerForKey:MMTextInsetBottom]; + int right = [ud integerForKey:MMTextInsetRightKey]; + int bot = [ud integerForKey:MMTextInsetBottomKey]; size.width += [textView textContainerOrigin].x + right; size.height += [textView textContainerOrigin].y + bot; @@ -638,7 +639,7 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) if ([tabBarControl isHidden]) ++size.height; else size.height += [tabBarControl frame].size.height; - if (![[NSUserDefaults standardUserDefaults] boolForKey:MMStatuslineOffKey]) + if (![ud boolForKey:MMStatuslineOffKey]) size.height += StatusLineHeight; if ([self bottomScrollbarVisible]) @@ -684,8 +685,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) NSSize size = textViewSize; NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - int right = [ud integerForKey:MMTextInsetRight]; - int bot = [ud integerForKey:MMTextInsetBottom]; + int right = [ud integerForKey:MMTextInsetRightKey]; + int bot = [ud integerForKey:MMTextInsetBottomKey]; size.width -= [textView textContainerOrigin].x + right; size.height -= [textView textContainerOrigin].y + bot;