From 92dd6bacc77cdbff5789260e6e4bcbda0de36021 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Sun, 28 Jul 2019 10:11:13 -0700 Subject: [PATCH 1/2] -[MMCoreTextView initWithFrame:] doesn't initialize fontDescent Fixes #883. --- src/MacVim/MMCoreTextView.m | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 03924d29ee..94295a3b87 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -150,6 +150,7 @@ - (id)initWithFrame:(NSRect)frame // 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]; + fontDescent = ceil(CTFontGetDescent((CTFontRef)font)); cellSize.width = cellSize.height = 1; // NOTE: If the default changes to 'NO' then the intialization of @@ -301,18 +302,13 @@ - (NSRect)rectForColumnsInRange:(NSRange)range - (void)setFont:(NSFont *)newFont { - if (!(newFont && font != newFont)) + if (!newFont || [font isEqual:newFont]) return; double em = round(defaultAdvanceForFont(newFont)); - double pt = round([newFont pointSize]); - - CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize((CFStringRef)[newFont fontName], pt); - CTFontRef fontRef = CTFontCreateWithFontDescriptor(desc, pt, NULL); - CFRelease(desc); [font release]; - font = (NSFont*)fontRef; + font = [newFont retain]; float cellWidthMultiplier = [[NSUserDefaults standardUserDefaults] floatForKey:MMCellWidthMultiplierKey]; @@ -324,7 +320,7 @@ - (void)setFont:(NSFont *)newFont cellSize.width = columnspace + ceil(em * cellWidthMultiplier); cellSize.height = linespace + defaultLineHeightForFont(font); - fontDescent = ceil(CTFontGetDescent(fontRef)); + fontDescent = ceil(CTFontGetDescent((CTFontRef)newFont)); [fontCache removeAllObjects]; } From 545bd216a186dac277e35e0230115f1e4fdc60ba Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Mon, 29 Jul 2019 07:40:42 -0700 Subject: [PATCH 2/2] Use setFont: directly --- src/MacVim/MMCoreTextView.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 94295a3b87..1449fe7e2c 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -147,18 +147,13 @@ - (id)initWithFrame:(NSRect)frame } cgLayerLock = [NSLock new]; - // 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]; - fontDescent = ceil(CTFontGetDescent((CTFontRef)font)); - cellSize.width = cellSize.height = 1; - // NOTE: If the default changes to 'NO' then the intialization of // p_antialias in option.c must change as well. antialias = YES; drawData = [[NSMutableArray alloc] init]; fontCache = [[NSMutableArray alloc] init]; + [self setFont:[NSFont userFixedPitchFontOfSize:0]]; helper = [[MMTextViewHelper alloc] init]; [helper setTextView:self];