Put back Color code in place of txetcolor due to crashes.

This commit is contained in:
Michael Griebling
2024-10-05 11:29:31 -04:00
parent a87d4b5a3c
commit 428537b8d9
5 changed files with 69 additions and 68 deletions

View File

@@ -235,10 +235,10 @@ public class MTMathAtom: NSObject {
return MTAccent(self as? MTAccent)
case .space:
return MTMathSpace(self as? MTMathSpace)
case .color:
case .color, .textcolor:
return MTMathColor(self as? MTMathColor)
case .textcolor:
return MTMathTextColor(self as? MTMathTextColor)
// case .textcolor:
// return MTMathTextColor(self as? MTMathTextColor)
case .colorBox:
return MTMathColorbox(self as? MTMathColorbox)
case .table:
@@ -684,32 +684,33 @@ public class MTMathColor: MTMathAtom {
Note: None of the usual fields of the `MTMathAtom` apply even though this
class inherits from `MTMathAtom`. i.e. it is meaningless to have a value
in the nucleus, subscript or superscript fields. */
public class MTMathTextColor: MTMathAtom {
public var colorString:String=""
public var innerList:MTMathList?
init(_ color: MTMathTextColor?) {
super.init(color)
self.type = .textcolor
self.colorString = color?.colorString ?? ""
self.innerList = MTMathList(color?.innerList)
}
override init() {
super.init()
self.type = .textcolor
}
public override var string: String {
"\\textcolor{\(self.colorString)}{\(self.innerList!.string)}"
}
override public var finalized: MTMathAtom {
let newColor = super.finalized as! MTMathTextColor
newColor.innerList = newColor.innerList?.finalized
return newColor
}
}
// FIXME: Removed due to crash
//public class MTMathTextColor: MTMathAtom {
// public var colorString:String=""
// public var innerList:MTMathList?
//
// init(_ color: MTMathTextColor?) {
// super.init(color)
// self.type = .textcolor
// self.colorString = color?.colorString ?? ""
// self.innerList = MTMathList(color?.innerList)
// }
//
// override init() {
// super.init()
// self.type = .textcolor
// }
//
// public override var string: String {
// "\\textcolor{\(self.colorString)}{\(self.innerList!.string)}"
// }
//
// override public var finalized: MTMathAtom {
// let newColor = super.finalized as! MTMathTextColor
// newColor.innerList = newColor.innerList?.finalized
// return newColor
// }
//}
// MARK: - MTMathColorbox
/** An atom representing an colorbox element.

View File

@@ -587,18 +587,18 @@ public struct MTMathListBuilder {
}
let table = self.buildTable(env: env, firstList:nil, isRow:false)
return table
} else if command == "color" {
} else if command == "color" || command == "textcolor" {
// A color command has 2 arguments
let mathColor = MTMathColor()
mathColor.colorString = self.readColor()!
mathColor.innerList = self.buildInternal(true)
return mathColor
} else if command == "textcolor" {
// A textcolor command has 2 arguments
let mathColor = MTMathTextColor()
mathColor.colorString = self.readColor()!
mathColor.innerList = self.buildInternal(true)
return mathColor
// } else if command == "textcolor" {
// // A textcolor command has 2 arguments
// let mathColor = MTMathTextColor()
// mathColor.colorString = self.readColor()!
// mathColor.innerList = self.buildInternal(true)
// return mathColor
} else if command == "colorbox" {
// A color command has 2 arguments
let mathColorbox = MTMathColorbox()

View File

@@ -500,7 +500,7 @@ class MTTypesetter {
// so we skip to the next node.
continue
case .color:
case .color, .textcolor:
// stash the existing layout
if currentLine.length > 0 {
self.addDisplayLine()
@@ -512,35 +512,35 @@ class MTTypesetter {
currentPosition.x += display!.width
displayAtoms.append(display!)
case .textcolor:
// stash the existing layout
if currentLine.length > 0 {
self.addDisplayLine()
}
let colorAtom = atom as! MTMathTextColor
let display = MTTypesetter.createLineForMathList(colorAtom.innerList, font: font, style: style)
display!.localTextColor = MTColor(fromHexString: colorAtom.colorString)
if prevNode != nil {
let subDisplay: MTDisplay = display!.subDisplays[0]
let subDisplayAtom = (subDisplay as? MTCTLineDisplay)!.atoms[0]
let interElementSpace = self.getInterElementSpace(prevNode!.type, right:subDisplayAtom.type)
if currentLine.length > 0 {
if interElementSpace > 0 {
// add a kerning of that space to the previous character
currentLine.addAttribute(kCTKernAttributeName as NSAttributedString.Key,
value:NSNumber(floatLiteral: interElementSpace),
range:currentLine.mutableString.rangeOfComposedCharacterSequence(at: currentLine.length-1))
}
} else {
// increase the space
currentPosition.x += interElementSpace
}
}
display!.position = currentPosition
currentPosition.x += display!.width
displayAtoms.append(display!)
// case .textcolor:
// // stash the existing layout
// if currentLine.length > 0 {
// self.addDisplayLine()
// }
// let colorAtom = atom as! MTMathTextColor
// let display = MTTypesetter.createLineForMathList(colorAtom.innerList, font: font, style: style)
// display!.localTextColor = MTColor(fromHexString: colorAtom.colorString)
//
// if prevNode != nil {
// let subDisplay: MTDisplay = display!.subDisplays[0]
// let subDisplayAtom = (subDisplay as? MTCTLineDisplay)!.atoms[0]
// let interElementSpace = self.getInterElementSpace(prevNode!.type, right:subDisplayAtom.type)
// if currentLine.length > 0 {
// if interElementSpace > 0 {
// // add a kerning of that space to the previous character
// currentLine.addAttribute(kCTKernAttributeName as NSAttributedString.Key,
// value:NSNumber(floatLiteral: interElementSpace),
// range:currentLine.mutableString.rangeOfComposedCharacterSequence(at: currentLine.length-1))
// }
// } else {
// // increase the space
// currentPosition.x += interElementSpace
// }
// }
//
// display!.position = currentPosition
// currentPosition.x += display!.width
// displayAtoms.append(display!)
case .colorBox:
// stash the existing layout

View File

@@ -13,7 +13,7 @@ final class ConcurrencyThreadsafeTests: XCTestCase {
private let executionQueue = DispatchQueue(label: "com.swiftmath.concurrencytests", attributes: .concurrent)
private let executionGroup = DispatchGroup()
let totalCases = 20
let totalCases = 20
var testCount = 0
func testSwiftMathConcurrentScript() throws {

View File

@@ -62,7 +62,7 @@ final class MTFontMathTableV2Tests: XCTestCase {
}
workitem.notify(queue: .main) { [weak self] in
// print("\(Thread.isMainThread ? "main" : "global") completed .....")
let mTable = mtfont.mathTable
// let mTable = mtfont.mathTable
if count % 70 == 0 {
// let values = [
// mTable?.fractionNumeratorDisplayStyleShiftUp,