mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-23 19:21:53 +03:00
GH-405 Vertically center-align text when linespacing > 1
This commit is contained in:
parent
15ebbd4ee2
commit
f503b9e47e
@ -181,7 +181,9 @@ 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
|
||||
.baselineOffset = (self.cellSize.height + FontUtils.fontHeight(of: self.font)) / 2 -
|
||||
CTFontGetAscent(self.font)
|
||||
self.descent = CTFontGetDescent(self.font)
|
||||
self.underlinePosition = CTFontGetUnderlinePosition(self.font)
|
||||
self.underlineThickness = CTFontGetUnderlineThickness(self.font)
|
||||
|
@ -23,15 +23,19 @@ extension FontTrait: Hashable {}
|
||||
|
||||
final class FontUtils {
|
||||
|
||||
static func cellHeight(of font: NSFont) -> CGFloat {
|
||||
static func fontHeight(of font: NSFont) -> CGFloat {
|
||||
if let cached = fontHeightCache.valueForKey(font) { return cached }
|
||||
|
||||
let ascent = CTFontGetAscent(font)
|
||||
let descent = CTFontGetDescent(font)
|
||||
let leading = CTFontGetLeading(font)
|
||||
let height = ceil(ascent + descent + leading)
|
||||
|
||||
return ceil(ascent + descent + leading)
|
||||
fontHeightCache.set(height, forKey: font)
|
||||
return height
|
||||
}
|
||||
|
||||
static func cellWidth(of font: NSFont) -> CGFloat {
|
||||
static func fontWidth(of font: NSFont) -> CGFloat {
|
||||
let capitalM = [UniChar(0x004D)]
|
||||
var glyph = [CGGlyph(0)]
|
||||
var advancement = CGSize.zero
|
||||
@ -49,7 +53,7 @@ final class FontUtils {
|
||||
)
|
||||
}
|
||||
|
||||
let cellSizeToCache = CGSize(width: cellWidth(of: font), height: cellHeight(of: font))
|
||||
let cellSizeToCache = CGSize(width: fontWidth(of: font), height: fontHeight(of: font))
|
||||
cellSizeWithDefaultLinespacingCache.set(cellSizeToCache, forKey: font)
|
||||
|
||||
let cellSize = CGSize(
|
||||
@ -112,6 +116,7 @@ final class FontUtils {
|
||||
}
|
||||
|
||||
private let fontCache = FifoCache<SizedFontTrait, NSFont>(count: 100, queueQos: .userInteractive)
|
||||
private let fontHeightCache = FifoCache<NSFont, CGFloat>(count: 100, queueQos: .userInteractive)
|
||||
private let cellSizeWithDefaultLinespacingCache = FifoCache<NSFont, CGSize>(
|
||||
count: 100,
|
||||
queueQos: .userInteractive
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Next
|
||||
|
||||
* GH-874: Make Chinese input possible (and simplify input method handling in general), thank you very much, @SolarWing!
|
||||
* GH-805 (GH-415): Vertically center-align text. Thank you @apaleslimghost!
|
||||
* ...
|
||||
|
||||
## 0.35.0-20211105.213803
|
||||
|
Loading…
Reference in New Issue
Block a user