From 7fb3e24bb9ca6698bf4d371e786b44922075e92a Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Wed, 16 Oct 2019 08:25:08 -0700 Subject: [PATCH] Fix font initialization pulling in extra metadata Recent fix to font initialization (#927) seems to have caused issues with other fonts. Keep the fix but revert to the old way of font initialization by manually creating a new one with point size to not use the other aspects of the font to keep the behavior consistent with previous behavior Fix #928 --- src/MacVim/MMCoreTextView.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 1449fe7e2c..7ce71a4bb6 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -301,9 +301,14 @@ - (void)setFont:(NSFont *)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 = [newFont retain]; + font = (NSFont*)fontRef; float cellWidthMultiplier = [[NSUserDefaults standardUserDefaults] floatForKey:MMCellWidthMultiplierKey]; @@ -315,7 +320,7 @@ - (void)setFont:(NSFont *)newFont cellSize.width = columnspace + ceil(em * cellWidthMultiplier); cellSize.height = linespace + defaultLineHeightForFont(font); - fontDescent = ceil(CTFontGetDescent((CTFontRef)newFont)); + fontDescent = ceil(CTFontGetDescent(fontRef)); [fontCache removeAllObjects]; }