Skip to content

Commit

Permalink
Stop using deprecated Cocoa APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
b4winckler committed Aug 12, 2008
1 parent ee84ad6 commit d58cb64
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
21 changes: 18 additions & 3 deletions src/MacVim/MMAtsuiTextView.m
Expand Up @@ -107,6 +107,19 @@ - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
@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
Expand Down Expand Up @@ -212,7 +225,9 @@ - (void)setFont:(NSFont *)newFont
[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];

Expand All @@ -221,7 +236,7 @@ - (void)setFont:(NSFont *)newFont
// 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];
}
Expand Down Expand Up @@ -251,7 +266,7 @@ - (void)setLinespace:(float)newLinespace
// 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);
}


Expand Down
24 changes: 17 additions & 7 deletions src/MacVim/MMTextStorage.m
Expand Up @@ -75,8 +75,8 @@ - (id)init
// 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;
Expand Down Expand Up @@ -219,6 +219,10 @@ - (float)linespace
- (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;

Expand All @@ -228,8 +232,7 @@ - (void)setLinespace:(float)newLinespace
// 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
Expand Down Expand Up @@ -653,7 +656,9 @@ - (void)setFont:(NSFont*)newFont
// 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];

Expand All @@ -674,8 +679,13 @@ - (void)setFont:(NSFont*)newFont
[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
Expand Down

0 comments on commit d58cb64

Please sign in to comment.