Fix text run display node
This commit is contained in:
@@ -49,18 +49,10 @@ extension CGContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func draw(_ textRun: Math.DisplayTextRun, foregroundColor: CGColor) {
|
private func draw(_ textRun: Math.DisplayTextRun, foregroundColor: CGColor) {
|
||||||
guard let platformFont = Math.PlatformFont(font: textRun.font) else {
|
let line = CTLineCreateWithAttributedString(textRun.attributedString)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let attributes: [NSAttributedString.Key: Any] = [
|
|
||||||
NSAttributedString.Key(kCTFontAttributeName as String): platformFont.ctFont,
|
|
||||||
NSAttributedString.Key(kCTForegroundColorAttributeName as String): foregroundColor,
|
|
||||||
]
|
|
||||||
let attributedString = NSAttributedString(string: textRun.text, attributes: attributes)
|
|
||||||
let line = CTLineCreateWithAttributedString(attributedString)
|
|
||||||
|
|
||||||
saveGState()
|
saveGState()
|
||||||
|
setFillColor(foregroundColor)
|
||||||
textPosition = textRun.position
|
textPosition = textRun.position
|
||||||
CTLineDraw(line, self)
|
CTLineDraw(line, self)
|
||||||
restoreGState()
|
restoreGState()
|
||||||
|
|||||||
@@ -3,14 +3,19 @@ import Foundation
|
|||||||
|
|
||||||
extension Math {
|
extension Math {
|
||||||
final class DisplayTextRun: DisplayNode {
|
final class DisplayTextRun: DisplayNode {
|
||||||
var text: String
|
var attributedString: NSAttributedString
|
||||||
var font: Math.Font
|
var font: Math.Font
|
||||||
var atoms: [Math.Atom]
|
var atoms: [Math.Atom]
|
||||||
|
var text: String { attributedString.string }
|
||||||
|
|
||||||
init(
|
init(
|
||||||
text: String, font: Math.Font, position: CGPoint = .zero, range: NSRange, atoms: [Math.Atom]
|
attributedString: NSAttributedString,
|
||||||
|
font: Math.Font,
|
||||||
|
position: CGPoint = .zero,
|
||||||
|
range: NSRange,
|
||||||
|
atoms: [Math.Atom]
|
||||||
) {
|
) {
|
||||||
self.text = text
|
self.attributedString = attributedString
|
||||||
self.font = font
|
self.font = font
|
||||||
self.atoms = atoms
|
self.atoms = atoms
|
||||||
super.init()
|
super.init()
|
||||||
|
|||||||
@@ -1794,9 +1794,10 @@ extension Math {
|
|||||||
"The length of the current line: %@ does not match the length of the range (%d, %d)",
|
"The length of the current line: %@ does not match the length of the range (%d, %d)",
|
||||||
currentLine, currentLineIndexRange.location, currentLineIndexRange.length);*/
|
currentLine, currentLineIndexRange.location, currentLineIndexRange.length);*/
|
||||||
|
|
||||||
let line = CTLineCreateWithAttributedString(currentLine)
|
let attributedString = currentLine.copy() as! NSAttributedString
|
||||||
|
let line = CTLineCreateWithAttributedString(attributedString)
|
||||||
let displayAtom = DisplayTextRun(
|
let displayAtom = DisplayTextRun(
|
||||||
text: currentLine.string,
|
attributedString: attributedString,
|
||||||
font: styleFont.font,
|
font: styleFont.font,
|
||||||
position: currentPosition,
|
position: currentPosition,
|
||||||
range: currentLineIndexRange,
|
range: currentLineIndexRange,
|
||||||
@@ -2406,9 +2407,10 @@ extension Math {
|
|||||||
line.addAttribute(
|
line.addAttribute(
|
||||||
kCTFontAttributeName as NSAttributedString.Key, value: styleFont.ctFont,
|
kCTFontAttributeName as NSAttributedString.Key, value: styleFont.ctFont,
|
||||||
range: NSMakeRange(0, line.length))
|
range: NSMakeRange(0, line.length))
|
||||||
let ctLine = CTLineCreateWithAttributedString(line)
|
let attributedString = line.copy() as! NSAttributedString
|
||||||
|
let ctLine = CTLineCreateWithAttributedString(attributedString)
|
||||||
let displayAtom = DisplayTextRun(
|
let displayAtom = DisplayTextRun(
|
||||||
text: line.string,
|
attributedString: attributedString,
|
||||||
font: styleFont.font,
|
font: styleFont.font,
|
||||||
position: currentPosition,
|
position: currentPosition,
|
||||||
range: op.indexRange,
|
range: op.indexRange,
|
||||||
|
|||||||
Reference in New Issue
Block a user