mirror of
https://github.com/qvacua/vimr.git
synced 2024-08-16 20:20:28 +03:00
Do not include font check for CTRuns when typesetting.
We have to clear the cache when changing the font (and other parameters which may affect the typesetting).
This commit is contained in:
parent
4c3d968a0c
commit
35527bc52e
@ -23,6 +23,11 @@ public final class FifoCache<Key: Hashable, Value> {
|
||||
}
|
||||
|
||||
public func valueForKey(_ key: Key) -> Value? { self.storage[key] }
|
||||
|
||||
public func clear() {
|
||||
self.keys = Array(repeating: nil, count: count)
|
||||
self.storage.removeAll(keepingCapacity: true)
|
||||
}
|
||||
|
||||
private let count: Int
|
||||
private var keys: [Key?]
|
||||
|
@ -18,7 +18,9 @@ final class AttributesRunDrawer {
|
||||
didSet { self.updateFontMetrics() }
|
||||
}
|
||||
|
||||
var usesLigatures: Bool
|
||||
var usesLigatures: Bool {
|
||||
didSet { self.typesetter.clearCache() }
|
||||
}
|
||||
|
||||
private(set) var cellSize: CGSize = .zero
|
||||
private(set) var baselineOffset: CGFloat = 0
|
||||
@ -187,5 +189,7 @@ final class AttributesRunDrawer {
|
||||
self.descent = CTFontGetDescent(self.font)
|
||||
self.underlinePosition = CTFontGetUnderlinePosition(self.font)
|
||||
self.underlineThickness = CTFontGetUnderlineThickness(self.font)
|
||||
|
||||
self.typesetter.clearCache()
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,10 @@ import Commons
|
||||
import os
|
||||
|
||||
final class Typesetter {
|
||||
func clearCache() {
|
||||
self.ctRunsCache.clear()
|
||||
}
|
||||
|
||||
func fontGlyphRunsWithLigatures(
|
||||
nvimUtf16Cells: [[Unicode.UTF16.CodeUnit]],
|
||||
startColumn: Int,
|
||||
@ -141,8 +145,7 @@ final class Typesetter {
|
||||
}
|
||||
|
||||
private func ctRuns(from utf16Chars: [Unicode.UTF16.CodeUnit], font: NSFont) -> [CTRun] {
|
||||
if let ctRunsAndFont = self.ctRunsCache.valueForKey(utf16Chars),
|
||||
font == ctRunsAndFont.font { return ctRunsAndFont.ctRuns }
|
||||
if let ctRunsAndFont = self.ctRunsCache.valueForKey(utf16Chars) { return ctRunsAndFont }
|
||||
|
||||
let attrStr = NSAttributedString(
|
||||
string: String(utf16CodeUnits: utf16Chars, count: utf16Chars.count),
|
||||
@ -152,7 +155,7 @@ final class Typesetter {
|
||||
let ctLine = CTLineCreateWithAttributedString(attrStr)
|
||||
guard let ctRuns = CTLineGetGlyphRuns(ctLine) as? [CTRun] else { return [] }
|
||||
|
||||
self.ctRunsCache.set(CtRunsAndFont(ctRuns: ctRuns, font: font), forKey: utf16Chars)
|
||||
self.ctRunsCache.set(ctRuns, forKey: utf16Chars)
|
||||
|
||||
return ctRuns
|
||||
}
|
||||
@ -270,15 +273,10 @@ final class Typesetter {
|
||||
}
|
||||
}
|
||||
|
||||
private let ctRunsCache = FifoCache<[Unicode.UTF16.CodeUnit], CtRunsAndFont>(count: 5000)
|
||||
private let ctRunsCache = FifoCache<[Unicode.UTF16.CodeUnit], [CTRun]>(count: 5000)
|
||||
|
||||
private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.view)
|
||||
|
||||
private struct CtRunsAndFont {
|
||||
var ctRuns: [CTRun]
|
||||
var font: NSFont
|
||||
}
|
||||
|
||||
private struct NvimUtf16CellsRun {
|
||||
var startColumn: Int
|
||||
var nvimUtf16Cells: [[Unicode.UTF16.CodeUnit]]
|
||||
|
@ -16,7 +16,7 @@ class Document: NSDocument, NSWindowDelegate {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
self.nvimView.font = NSFont(name: "Fira Code", size: 13)
|
||||
self.nvimView.font = NSFont(name: "Iosevka", size: 13)
|
||||
?? NSFont.userFixedPitchFont(ofSize: 13)!
|
||||
self.nvimView.usesLigatures = true
|
||||
self.nvimView.usesLiveResize = true
|
||||
|
Loading…
Reference in New Issue
Block a user