mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-23 19:21:53 +03:00
Merge remote-tracking branch 'origin/pr/805' into 805
- Did not change AttributesRunDrawer since it breaks the vertical positioning with linespacing = 1.0. Conflicts: NvimView/Sources/NvimView/AttributesRunDrawer.swift NvimView/Sources/NvimView/FontUtils.swift
This commit is contained in:
commit
15ebbd4ee2
@ -21,7 +21,26 @@ private struct SizedFontTrait: Hashable {
|
||||
|
||||
extension FontTrait: Hashable {}
|
||||
|
||||
enum FontUtils {
|
||||
final class FontUtils {
|
||||
|
||||
static func cellHeight(of font: NSFont) -> CGFloat {
|
||||
let ascent = CTFontGetAscent(font)
|
||||
let descent = CTFontGetDescent(font)
|
||||
let leading = CTFontGetLeading(font)
|
||||
|
||||
return ceil(ascent + descent + leading)
|
||||
}
|
||||
|
||||
static func cellWidth(of font: NSFont) -> CGFloat {
|
||||
let capitalM = [UniChar(0x004D)]
|
||||
var glyph = [CGGlyph(0)]
|
||||
var advancement = CGSize.zero
|
||||
CTFontGetGlyphsForCharacters(font, capitalM, &glyph, 1)
|
||||
CTFontGetAdvancesForGlyphs(font, .horizontal, glyph, &advancement, 1)
|
||||
|
||||
return advancement.width
|
||||
}
|
||||
|
||||
static func cellSize(of font: NSFont, linespacing: CGFloat, characterspacing: CGFloat) -> CGSize {
|
||||
if let cached = cellSizeWithDefaultLinespacingCache.valueForKey(font) {
|
||||
return CGSize(
|
||||
@ -30,21 +49,11 @@ enum FontUtils {
|
||||
)
|
||||
}
|
||||
|
||||
let capitalM = [UniChar(0x004D)]
|
||||
var glyph = [CGGlyph(0)]
|
||||
var advancement = CGSize.zero
|
||||
CTFontGetGlyphsForCharacters(font, capitalM, &glyph, 1)
|
||||
CTFontGetAdvancesForGlyphs(font, .horizontal, glyph, &advancement, 1)
|
||||
|
||||
let ascent = CTFontGetAscent(font)
|
||||
let descent = CTFontGetDescent(font)
|
||||
let leading = CTFontGetLeading(font)
|
||||
|
||||
let cellSizeToCache = CGSize(width: advancement.width, height: ceil(ascent + descent + leading))
|
||||
let cellSizeToCache = CGSize(width: cellWidth(of: font), height: cellHeight(of: font))
|
||||
cellSizeWithDefaultLinespacingCache.set(cellSizeToCache, forKey: font)
|
||||
|
||||
let cellSize = CGSize(
|
||||
width: characterspacing * advancement.width,
|
||||
width: characterspacing * cellSizeToCache.width,
|
||||
height: ceil(linespacing * cellSizeToCache.height)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user