diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index dc4010412d..4ddcba0e0f 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -107,6 +107,19 @@ enum { @end + + static float +defaultLineHeightForFont(NSFont *font) +{ + // HACK: -[NSFont defaultLineHeightForFont] is deprecated but since the + // ATSUI renderer does not use NSLayoutManager we create one temporarily. + NSLayoutManager *lm = [[NSLayoutManager alloc] init]; + float height = [lm defaultLineHeightForFont:font]; + [lm release]; + + return height; +} + @implementation MMAtsuiTextView - (id)initWithFrame:(NSRect)frame @@ -212,7 +225,9 @@ enum { [font release]; font = [newFont retain]; - float em = [newFont widthOfString:@"m"]; + float em = [@"m" sizeWithAttributes: + [NSDictionary dictionaryWithObject:newFont + forKey:NSFontAttributeName]].width; float cellWidthMultiplier = [[NSUserDefaults standardUserDefaults] floatForKey:MMCellWidthMultiplierKey]; @@ -221,7 +236,7 @@ enum { // an integer here, otherwise the window width and the actual text // width will not match. cellSize.width = ceilf(em * cellWidthMultiplier); - cellSize.height = linespace + [newFont defaultLineHeightForFont]; + cellSize.height = linespace + defaultLineHeightForFont(newFont); [self updateAtsuStyles]; } @@ -251,7 +266,7 @@ enum { // 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 + [font defaultLineHeightForFont]; + cellSize.height = linespace + defaultLineHeightForFont(font); } diff --git a/src/MacVim/MMTextStorage.m b/src/MacVim/MMTextStorage.m index 704620aaff..82ad1400e1 100644 --- a/src/MacVim/MMTextStorage.m +++ b/src/MacVim/MMTextStorage.m @@ -75,8 +75,8 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; // 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]; - cellSize.height = [font pointSize]; - cellSize.width = [font defaultLineHeightForFont]; + cellSize.height = 16.0; + cellSize.width = 6.0; } return self; @@ -219,6 +219,10 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; - (void)setLinespace:(float)newLinespace { NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0]; + if (!lm) { + NSLog(@"WARNING: No layout manager available in call to %s", _cmd); + return; + } linespace = newLinespace; @@ -228,8 +232,7 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; // 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]); + cellSize.height = linespace + [lm defaultLineHeightForFont:font]; } - (void)getMaxRows:(int*)rows columns:(int*)cols @@ -653,7 +656,9 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; // NOTE! When setting a new font we make sure that the advancement of // each glyph is fixed. - float em = [newFont widthOfString:@"m"]; + float em = [@"m" sizeWithAttributes: + [NSDictionary dictionaryWithObject:newFont + forKey:NSFontAttributeName]].width; float cellWidthMultiplier = [[NSUserDefaults standardUserDefaults] floatForKey:MMCellWidthMultiplierKey]; @@ -674,8 +679,13 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; [font retain]; NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0]; - cellSize.height = linespace + (lm ? [lm defaultLineHeightForFont:font] - : [font defaultLineHeightForFont]); + if (lm) { + cellSize.height = linespace + [lm defaultLineHeightForFont:font]; + } else { + // Should never happen, set some bogus value for cell height. + NSLog(@"WARNING: No layout manager available in call to %s", _cmd); + cellSize.height = linespace + 16.0; + } // NOTE: The font manager does not care about the 'font fixed advance' // attribute, so after converting the font we have to add this