From 5db52978b5fc67ade9a6f918463d216cf7ef4d6c Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Fri, 31 Aug 2007 17:15:15 +0000 Subject: [PATCH] 'linespace' now supported git-svn-id: http://macvim.googlecode.com/svn/trunk@224 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMBackend.h | 1 + MMBackend.m | 7 +++++++ MMTextStorage.h | 3 +++ MMTextStorage.m | 28 ++++++++++++++++++++++++++-- MMTypesetter.m | 4 +++- MMVimController.m | 5 +++++ MMWindowController.h | 1 + MMWindowController.m | 10 ++++++++-- MacVim.h | 1 + MacVim.m | 1 + gui_macvim.m | 3 ++- 11 files changed, 58 insertions(+), 6 deletions(-) diff --git a/MMBackend.h b/MMBackend.h index 75630e0a32..68cbb6f521 100644 --- a/MMBackend.h +++ b/MMBackend.h @@ -102,6 +102,7 @@ - (void)setBlinkWait:(int)wait on:(int)on off:(int)off; - (void)startBlink; - (void)stopBlink; +- (void)adjustLinespace:(int)linespace; - (int)lookupColorWithKey:(NSString *)key; - (BOOL)hasSpecialKeyWithValue:(NSString *)value; diff --git a/MMBackend.m b/MMBackend.m index d2fe34de58..08f7285181 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -836,6 +836,13 @@ enum { blinkState = MMBlinkStateNone; } +- (void)adjustLinespace:(int)linespace +{ + NSMutableData *data = [NSMutableData data]; + [data appendBytes:&linespace length:sizeof(int)]; + [self queueMessage:AdjustLinespaceMsgID data:data]; +} + - (int)lookupColorWithKey:(NSString *)key { if (!(key && [key length] > 0)) diff --git a/MMTextStorage.h b/MMTextStorage.h index b2b619fd5b..0f0fbdffd1 100644 --- a/MMTextStorage.h +++ b/MMTextStorage.h @@ -25,6 +25,7 @@ NSColor *defaultBackgroundColor; NSColor *defaultForegroundColor; NSSize cellSize; + float linespace; } - (NSString *)string; @@ -38,6 +39,8 @@ - (int)maxColumns; - (int)actualRows; - (int)actualColumns; +- (float)linespace; +- (void)setLinespace:(float)newLinespace; - (void)getMaxRows:(int*)rows columns:(int*)cols; - (void)setMaxRows:(int)rows columns:(int)cols; - (void)replaceString:(NSString *)string atRow:(int)row column:(int)col diff --git a/MMTextStorage.m b/MMTextStorage.m index ede428935a..89de6b8f0f 100644 --- a/MMTextStorage.m +++ b/MMTextStorage.m @@ -39,6 +39,9 @@ // NOTE! It does not matter which font is set here, Vim will set its // own font on startup anyway. Just set some bogus values. font = [[NSFont userFixedPitchFontOfSize:0] retain]; + boldFont = [font retain]; + italicFont = [font retain]; + boldItalicFont = [font retain]; cellSize.height = [font pointSize]; cellSize.width = [font defaultLineHeightForFont]; } @@ -153,6 +156,27 @@ return actualColumns; } +- (float)linespace +{ + return linespace; +} + +- (void)setLinespace:(float)newLinespace +{ + NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0]; + + linespace = newLinespace; + + // NOTE: The linespace is added to the cell height in order for a multiline + // selection not to have white (background color) gaps between lines. Also + // this simplifies the code a lot because there is no need to check the + // linespace when calculating the size of the text view etc. When the + // linespace is non-zero the baseline will be adjusted as well; check + // MMTypesetter. + cellSize.height = linespace + (lm ? [lm defaultLineHeightForFont:font] + : [font defaultLineHeightForFont]); +} + - (void)getMaxRows:(int*)rows columns:(int*)cols { if (rows) *rows = maxRows; @@ -417,8 +441,8 @@ [font retain]; NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0]; - cellSize.height = lm ? [lm defaultLineHeightForFont:font] - : [font defaultLineHeightForFont]; + cellSize.height = linespace + (lm ? [lm defaultLineHeightForFont:font] + : [font defaultLineHeightForFont]); // NOTE: The font manager does not care about the 'font fixed advance' // attribute, so after converting the font we have to add this diff --git a/MMTypesetter.m b/MMTypesetter.m index d551f447c9..90a620df49 100644 --- a/MMTypesetter.m +++ b/MMTypesetter.m @@ -52,7 +52,9 @@ NSString *text = [ts string]; unsigned textLen = [text length]; NSSize cellSize = [ts cellSize]; - float baseline = [font descender]; + // NOTE: With non-zero linespace the baseline is adjusted so that the text + // is centered within a line. + float baseline = [font descender] - floor(.5*[ts linespace]); if (!(ts && tv && tc && font && text && textLen)) return; diff --git a/MMVimController.m b/MMVimController.m index 0de871d11e..febdce2a42 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -744,6 +744,11 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) int shape = *((int*)bytes); bytes += sizeof(int); [windowController setMouseShape:shape]; + } else if (AdjustLinespaceMsgID == msgid) { + const void *bytes = [data bytes]; + int linespace = *((int*)bytes); bytes += sizeof(int); + + [windowController adjustLinespace:linespace]; } else { NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid); } diff --git a/MMWindowController.h b/MMWindowController.h index 7ec973be9d..84a46b407d 100644 --- a/MMWindowController.h +++ b/MMWindowController.h @@ -57,6 +57,7 @@ - (void)showTabBar:(BOOL)on; - (void)showToolbar:(BOOL)on size:(int)size mode:(int)mode; - (void)setMouseShape:(int)shape; +- (void)adjustLinespace:(int)linespace; - (IBAction)addNewTab:(id)sender; - (IBAction)toggleToolbar:(id)sender; diff --git a/MMWindowController.m b/MMWindowController.m index 67c2d98846..3f5d923748 100644 --- a/MMWindowController.m +++ b/MMWindowController.m @@ -280,8 +280,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) [self addNewTabViewItem]; - //[[self window] setAcceptsMouseMovedEvents:YES]; - setupDone = YES; [self updateResizeIncrements]; @@ -543,6 +541,14 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) [NSCursor setHiddenUntilMouseMoves:YES]; } +- (void)adjustLinespace:(int)linespace +{ + if (textStorage) { + [textStorage setLinespace:(float)linespace]; + shouldUpdateWindowSize = YES; + } +} + - (IBAction)addNewTab:(id)sender { // NOTE! This can get called a lot if the user holds down the key diff --git a/MacVim.h b/MacVim.h index 4bead2863a..74d24d079e 100644 --- a/MacVim.h +++ b/MacVim.h @@ -118,6 +118,7 @@ enum { LostFocusMsgID, MouseMovedMsgID, SetMouseShapeMsgID, + AdjustLinespaceMsgID, }; diff --git a/MacVim.m b/MacVim.m index ed967924d1..f8772c3f65 100644 --- a/MacVim.m +++ b/MacVim.m @@ -56,6 +56,7 @@ char *MessageStrings[] = "LostFocusMsgID", "MouseMovedMsgID", "SetMouseShapeMsgID", + "AdjustLinespaceMsgID", }; diff --git a/gui_macvim.m b/gui_macvim.m index 39e8499e45..66365f487f 100644 --- a/gui_macvim.m +++ b/gui_macvim.m @@ -1073,7 +1073,8 @@ ex_action(eap) int gui_mch_adjust_charheight(void) { - return 0; + [[MMBackend sharedInstance] adjustLinespace:p_linespace]; + return OK; }