From b3877b0e92aff354dcd77815721d6ee3a1634d39 Mon Sep 17 00:00:00 2001 From: bren Date: Mon, 20 Apr 2020 19:03:47 +0100 Subject: [PATCH] vertically center-align text in linespacing, fixes #415 --- NvimView/NvimView/AttributesRunDrawer.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NvimView/NvimView/AttributesRunDrawer.swift b/NvimView/NvimView/AttributesRunDrawer.swift index e4f68551..d0e5f135 100644 --- a/NvimView/NvimView/AttributesRunDrawer.swift +++ b/NvimView/NvimView/AttributesRunDrawer.swift @@ -24,6 +24,7 @@ final class AttributesRunDrawer { private(set) var cellSize: CGSize = .zero private(set) var baselineOffset: CGFloat = 0 + private(set) var ascent: CGFloat = 0 private(set) var descent: CGFloat = 0 private(set) var underlinePosition: CGFloat = 0 private(set) var underlineThickness: CGFloat = 0 @@ -181,8 +182,10 @@ final class AttributesRunDrawer { self.cellSize = FontUtils.cellSize( of: self.font, linespacing: self.linespacing, characterspacing: self.characterspacing ) - self.baselineOffset = self.cellSize.height - CTFontGetAscent(self.font) + + self.ascent = CTFontGetAscent(font) self.descent = CTFontGetDescent(font) + self.baselineOffset = (self.cellSize.height - ascent + descent) / 2 self.underlinePosition = CTFontGetUnderlinePosition(font) self.underlineThickness = CTFontGetUnderlineThickness(font) }