Deprecate wrapped line mark

This commit is contained in:
1024jp 2024-04-05 08:21:48 +09:00
parent 86c9b9b5f3
commit 8cce278a92
3 changed files with 10 additions and 24 deletions

View File

@ -6,6 +6,7 @@
### Improvements
- Change the filter field for the outline inspector to apply the selection of the filter history immediately.
- Remove wrapped line marks in the line number view.
### Fixes

View File

@ -34,7 +34,6 @@ final class LineNumberView: NSView {
let fontSize: CGFloat
let charWidth: CGFloat
let wrappedMarkGlyph: CGGlyph
let digitGlyphs: [CGGlyph]
let padding: CGFloat
let tickLength: CGFloat
@ -47,7 +46,6 @@ final class LineNumberView: NSView {
// prepare glyphs
let font = CTFontCreateWithGraphicsFont(LineNumberView.lineNumberFont, self.fontSize, nil, nil)
self.wrappedMarkGlyph = font.glyph(for: "-")
self.digitGlyphs = (0...9).map { font.glyph(for: Character(String($0))) }
// calculate character width by assuming the font is monospace
@ -310,9 +308,7 @@ final class LineNumberView: NSView {
}
case .wrapped:
// draw wrapped mark (-)
let position = CGPoint(x: -drawingInfo.padding - drawingInfo.charWidth, y: y - lineOffset)
context.showGlyphs([drawingInfo.wrappedMarkGlyph], at: [position])
break
}
}
}

View File

@ -225,29 +225,18 @@ final class PrintTextView: NSTextView, Themable {
NSGraphicsContext.current?.cgContext.rotate(by: -.pi / 2)
}
let options: NSTextView.LineEnumerationOptions = isVerticalText ? [.bySkippingWrappedLine] : []
let range = (self.layoutManager as? PrintLayoutManager)?.visibleRange
self.enumerateLineFragments(in: dirtyRect, for: range, options: options.union(.bySkippingExtraLine)) { (lineRect, line, lineNumber) in
let numberString: String = switch line {
case .new:
if isVerticalText, lineNumber != 1, !lineNumber.isMultiple(of: 5) {
"·" // draw number only every 5 times
} else {
String(lineNumber)
}
case .wrapped:
"-"
}
self.enumerateLineFragments(in: dirtyRect, for: range, options: [.bySkippingWrappedLine, .bySkippingExtraLine]) { (lineRect, _, lineNumber) in
// draw number only every 5 times
let numberString = (!isVerticalText || lineNumber == 1 || lineNumber.isMultiple(of: 5)) ? String(lineNumber) : "·"
// adjust position to draw
let width = CGFloat(numberString.count) * numberSize.width
let point: NSPoint = if isVerticalText {
NSPoint(x: -lineRect.midY - width / 2,
y: horizontalOrigin - numberSize.height)
} else {
NSPoint(x: horizontalOrigin - width, // - width to align to right
y: lineRect.minY + baselineOffset - numberAscender)
}
let point: NSPoint = isVerticalText
? NSPoint(x: -lineRect.midY - width / 2,
y: horizontalOrigin - numberSize.height)
: NSPoint(x: horizontalOrigin - width, // - width to align to right
y: lineRect.minY + baselineOffset - numberAscender)
// draw number
NSAttributedString(string: numberString, attributes: attrs).draw(at: point)