|
@@ -32,12 +32,33 @@ public typealias TTImage = CGImage
|
|
extension TerminalView {
|
|
extension TerminalView {
|
|
typealias CellDimension = CGSize
|
|
typealias CellDimension = CGSize
|
|
|
|
|
|
- func setupOptions(width: CGFloat, height: CGFloat)
|
|
|
|
|
|
+ func resetCaches ()
|
|
{
|
|
{
|
|
self.attributes = [:]
|
|
self.attributes = [:]
|
|
self.urlAttributes = [:]
|
|
self.urlAttributes = [:]
|
|
self.colors = Array(repeating: nil, count: 256)
|
|
self.colors = Array(repeating: nil, count: 256)
|
|
self.trueColors = [:]
|
|
self.trueColors = [:]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // This is invoked when the font changes to recompute state
|
|
|
|
+ func resetFont()
|
|
|
|
+ {
|
|
|
|
+ resetCaches()
|
|
|
|
+ self.cellDimension = computeFontDimensions ()
|
|
|
|
+ let newCols = Int(frame.width / cellDimension.width)
|
|
|
|
+ let newRows = Int(frame.height / cellDimension.height)
|
|
|
|
+ resize(cols: newCols, rows: newRows)
|
|
|
|
+ updateCaretView()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func updateCaretView ()
|
|
|
|
+ {
|
|
|
|
+ caretView.frame.size = CGSize(width: cellDimension.width, height: cellDimension.height)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func setupOptions(width: CGFloat, height: CGFloat)
|
|
|
|
+ {
|
|
|
|
+ resetCaches ()
|
|
// Calculation assume that all glyphs in the font have the same advancement.
|
|
// Calculation assume that all glyphs in the font have the same advancement.
|
|
// Get the ascent + descent + leading from the font, already scaled for the font's size
|
|
// Get the ascent + descent + leading from the font, already scaled for the font's size
|
|
self.cellDimension = computeFontDimensions ()
|
|
self.cellDimension = computeFontDimensions ()
|
|
@@ -64,7 +85,7 @@ extension TerminalView {
|
|
caretView = CaretView(frame: CGRect(origin: .zero, size: CGSize(width: cellDimension.width, height: cellDimension.height)))
|
|
caretView = CaretView(frame: CGRect(origin: .zero, size: CGSize(width: cellDimension.width, height: cellDimension.height)))
|
|
addSubview(caretView)
|
|
addSubview(caretView)
|
|
} else {
|
|
} else {
|
|
- caretView.frame.size = CGSize(width: cellDimension.width, height: cellDimension.height)
|
|
|
|
|
|
+ updateCaretView ()
|
|
}
|
|
}
|
|
|
|
|
|
search = SearchService (terminal: terminal)
|
|
search = SearchService (terminal: terminal)
|
|
@@ -142,14 +163,14 @@ extension TerminalView {
|
|
// Computes the font dimensions once font.normal has been set
|
|
// Computes the font dimensions once font.normal has been set
|
|
func computeFontDimensions () -> CellDimension
|
|
func computeFontDimensions () -> CellDimension
|
|
{
|
|
{
|
|
- let lineAscent = CTFontGetAscent (font.normal)
|
|
|
|
- let lineDescent = CTFontGetDescent (font.normal)
|
|
|
|
- let lineLeading = CTFontGetLeading (font.normal)
|
|
|
|
|
|
+ let lineAscent = CTFontGetAscent (fontSet.normal)
|
|
|
|
+ let lineDescent = CTFontGetDescent (fontSet.normal)
|
|
|
|
+ let lineLeading = CTFontGetLeading (fontSet.normal)
|
|
let cellHeight = ceil(lineAscent + lineDescent + lineLeading)
|
|
let cellHeight = ceil(lineAscent + lineDescent + lineLeading)
|
|
#if os(macOS)
|
|
#if os(macOS)
|
|
- let cellWidth = font.normal.maximumAdvancement.width
|
|
|
|
|
|
+ let cellWidth = fontSet.normal.maximumAdvancement.width
|
|
#else
|
|
#else
|
|
- let fontAttributes = [NSAttributedString.Key.font: font.normal]
|
|
|
|
|
|
+ let fontAttributes = [NSAttributedString.Key.font: fontSet.normal]
|
|
let cellWidth = "W".size(withAttributes: fontAttributes).width
|
|
let cellWidth = "W".size(withAttributes: fontAttributes).width
|
|
#endif
|
|
#endif
|
|
return CellDimension(width: cellWidth, height: cellHeight)
|
|
return CellDimension(width: cellWidth, height: cellHeight)
|
|
@@ -263,14 +284,14 @@ extension TerminalView {
|
|
let isBold = flags.contains(.bold)
|
|
let isBold = flags.contains(.bold)
|
|
if isBold {
|
|
if isBold {
|
|
if flags.contains (.italic) {
|
|
if flags.contains (.italic) {
|
|
- tf = font.boldItalic
|
|
|
|
|
|
+ tf = fontSet.boldItalic
|
|
} else {
|
|
} else {
|
|
- tf = font.bold
|
|
|
|
|
|
+ tf = fontSet.bold
|
|
}
|
|
}
|
|
} else if flags.contains (.italic) {
|
|
} else if flags.contains (.italic) {
|
|
- tf = font.italic
|
|
|
|
|
|
+ tf = fontSet.italic
|
|
} else {
|
|
} else {
|
|
- tf = font.normal
|
|
|
|
|
|
+ tf = fontSet.normal
|
|
}
|
|
}
|
|
|
|
|
|
let fgColor = mapColor (color: fg, isFg: true, isBold: isBold)
|
|
let fgColor = mapColor (color: fg, isFg: true, isBold: isBold)
|
|
@@ -404,13 +425,13 @@ extension TerminalView {
|
|
// draw underline at font.normal.underlinePosition baseline
|
|
// draw underline at font.normal.underlinePosition baseline
|
|
let underlineStyle = NSUnderlineStyle(rawValue: attributes[.underlineStyle] as? NSUnderlineStyle.RawValue ?? 0)
|
|
let underlineStyle = NSUnderlineStyle(rawValue: attributes[.underlineStyle] as? NSUnderlineStyle.RawValue ?? 0)
|
|
let underlineColor = attributes[.underlineColor] as? TTColor ?? nativeForegroundColor
|
|
let underlineColor = attributes[.underlineColor] as? TTColor ?? nativeForegroundColor
|
|
- let underlinePosition = font.underlinePosition ()
|
|
|
|
|
|
+ let underlinePosition = fontSet.underlinePosition ()
|
|
|
|
|
|
// draw line at the baseline
|
|
// draw line at the baseline
|
|
currentContext.setShouldAntialias(false)
|
|
currentContext.setShouldAntialias(false)
|
|
currentContext.setStrokeColor(underlineColor.cgColor)
|
|
currentContext.setStrokeColor(underlineColor.cgColor)
|
|
|
|
|
|
- let underlineThickness = max(round(scale * font.underlineThickness ()) / scale, 0.5)
|
|
|
|
|
|
+ let underlineThickness = max(round(scale * fontSet.underlineThickness ()) / scale, 0.5)
|
|
for p in positions {
|
|
for p in positions {
|
|
switch underlineStyle {
|
|
switch underlineStyle {
|
|
case let style where style.contains(.single):
|
|
case let style where style.contains(.single):
|
|
@@ -459,8 +480,8 @@ extension TerminalView {
|
|
// TODO: this should not render any lines outside the dirtyRect
|
|
// TODO: this should not render any lines outside the dirtyRect
|
|
func drawTerminalContents (dirtyRect: TTRect, context: CGContext)
|
|
func drawTerminalContents (dirtyRect: TTRect, context: CGContext)
|
|
{
|
|
{
|
|
- let lineDescent = CTFontGetDescent(font.normal)
|
|
|
|
- let lineLeading = CTFontGetLeading(font.normal)
|
|
|
|
|
|
+ let lineDescent = CTFontGetDescent(fontSet.normal)
|
|
|
|
+ let lineLeading = CTFontGetLeading(fontSet.normal)
|
|
|
|
|
|
// draw lines
|
|
// draw lines
|
|
for row in terminal.buffer.yDisp..<terminal.rows + terminal.buffer.yDisp {
|
|
for row in terminal.buffer.yDisp..<terminal.rows + terminal.buffer.yDisp {
|