native table border rendering
This commit is contained in:
parent
d1efbed9a8
commit
39feb208ab
|
|
@ -118,22 +118,34 @@ class MarkdownLayoutManager: NSLayoutManager {
|
||||||
charOffset += lineLen + 1
|
charOffset += lineLen + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw vertical column separators from first line pipe positions
|
// Draw vertical column separators using pipe character glyph positions
|
||||||
if let firstLine = lines.first {
|
if let firstLine = lines.first {
|
||||||
let colWidth = rect.size.width / CGFloat(max(columns, 1))
|
let nsFirstLine = firstLine as NSString
|
||||||
for col in 1..<columns {
|
var pipeOffsets: [Int] = []
|
||||||
let x = rect.origin.x + colWidth * CGFloat(col)
|
for i in 0..<nsFirstLine.length {
|
||||||
let colLine = NSBezierPath()
|
if nsFirstLine.character(at: i) == UInt16(UnicodeScalar("|").value) {
|
||||||
colLine.move(to: NSPoint(x: x, y: rect.origin.y))
|
pipeOffsets.append(i)
|
||||||
colLine.line(to: NSPoint(x: x, y: rect.origin.y + rect.size.height))
|
}
|
||||||
colLine.lineWidth = 0.5
|
}
|
||||||
Theme.current.surface2.setStroke()
|
// Skip first and last pipe (outer borders), draw inner separators
|
||||||
colLine.stroke()
|
if pipeOffsets.count > 2 {
|
||||||
|
for pi in 1..<(pipeOffsets.count - 1) {
|
||||||
|
let charPos = charRange.location + pipeOffsets[pi]
|
||||||
|
let pipeGlyph = self.glyphRange(forCharacterRange: NSRange(location: charPos, length: 1), actualCharacterRange: nil)
|
||||||
|
let pipeRect = boundingRect(forGlyphRange: pipeGlyph, in: container)
|
||||||
|
let x = pipeRect.origin.x + origin.x + pipeRect.size.width / 2
|
||||||
|
let colLine = NSBezierPath()
|
||||||
|
colLine.move(to: NSPoint(x: x, y: rect.origin.y))
|
||||||
|
colLine.line(to: NSPoint(x: x, y: rect.origin.y + rect.size.height))
|
||||||
|
colLine.lineWidth = 0.5
|
||||||
|
Theme.current.surface2.setStroke()
|
||||||
|
colLine.stroke()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header background
|
// Header background
|
||||||
if lines.count > 1 {
|
if lines.count > 1 {
|
||||||
let firstLineRange = NSRange(location: charRange.location, length: (firstLine as NSString).length)
|
let firstLineRange = NSRange(location: charRange.location, length: nsFirstLine.length)
|
||||||
let headerGlyphRange = self.glyphRange(forCharacterRange: firstLineRange, actualCharacterRange: nil)
|
let headerGlyphRange = self.glyphRange(forCharacterRange: firstLineRange, actualCharacterRange: nil)
|
||||||
var headerRect = boundingRect(forGlyphRange: headerGlyphRange, in: container)
|
var headerRect = boundingRect(forGlyphRange: headerGlyphRange, in: container)
|
||||||
headerRect.origin.x = rect.origin.x
|
headerRect.origin.x = rect.origin.x
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue