Fix Mac version crashes on TextColor. Need at least v12.
This commit is contained in:
@@ -6,7 +6,7 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "SwiftMath",
|
name: "SwiftMath",
|
||||||
defaultLocalization: "en",
|
defaultLocalization: "en",
|
||||||
platforms: [.iOS(.v11), .macOS(.v11)],
|
platforms: [.iOS("11.0"), .macOS("12.0")],
|
||||||
products: [
|
products: [
|
||||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||||
.library(
|
.library(
|
||||||
|
|||||||
@@ -528,11 +528,6 @@ public class MTMathAtomFactory {
|
|||||||
case "\u{0410}"..."\u{044F}":
|
case "\u{0410}"..."\u{044F}":
|
||||||
return MTMathAtom(type: .ordinary, value: chStr)
|
return MTMathAtom(type: .ordinary, value: chStr)
|
||||||
case _ where ch.utf32Char < 0x0021 || ch.utf32Char > 0x007E:
|
case _ where ch.utf32Char < 0x0021 || ch.utf32Char > 0x007E:
|
||||||
// // allow Chinese characters for testing
|
|
||||||
// if ((ch.utf32Char >= 0x4E00) && (ch.utf32Char <= 0x9FFF)) {
|
|
||||||
// // CJK support. But xits-math-cn font only has Chinese characters support.
|
|
||||||
// return MTMathAtom(type:.ordinary, value:chStr)
|
|
||||||
// }
|
|
||||||
return nil
|
return nil
|
||||||
case "$", "%", "#", "&", "~", "\'", "^", "_", "{", "}", "\\":
|
case "$", "%", "#", "&", "~", "\'", "^", "_", "{", "}", "\\":
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -235,10 +235,10 @@ public class MTMathAtom: NSObject {
|
|||||||
return MTAccent(self as? MTAccent)
|
return MTAccent(self as? MTAccent)
|
||||||
case .space:
|
case .space:
|
||||||
return MTMathSpace(self as? MTMathSpace)
|
return MTMathSpace(self as? MTMathSpace)
|
||||||
case .color, .textcolor:
|
case .color:
|
||||||
return MTMathColor(self as? MTMathColor)
|
return MTMathColor(self as? MTMathColor)
|
||||||
// case .textcolor:
|
case .textcolor:
|
||||||
// return MTMathTextColor(self as? MTMathTextColor)
|
return MTMathTextColor(self as? MTMathTextColor)
|
||||||
case .colorBox:
|
case .colorBox:
|
||||||
return MTMathColorbox(self as? MTMathColorbox)
|
return MTMathColorbox(self as? MTMathColorbox)
|
||||||
case .table:
|
case .table:
|
||||||
@@ -684,33 +684,32 @@ public class MTMathColor: MTMathAtom {
|
|||||||
Note: None of the usual fields of the `MTMathAtom` apply even though this
|
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
|
class inherits from `MTMathAtom`. i.e. it is meaningless to have a value
|
||||||
in the nucleus, subscript or superscript fields. */
|
in the nucleus, subscript or superscript fields. */
|
||||||
// FIXME: Removed due to crash
|
public class MTMathTextColor: MTMathAtom {
|
||||||
//public class MTMathTextColor: MTMathAtom {
|
public var colorString:String=""
|
||||||
// public var colorString:String=""
|
public var innerList:MTMathList?
|
||||||
// public var innerList:MTMathList?
|
|
||||||
//
|
init(_ color: MTMathTextColor?) {
|
||||||
// init(_ color: MTMathTextColor?) {
|
super.init(color)
|
||||||
// super.init(color)
|
self.type = .textcolor
|
||||||
// self.type = .textcolor
|
self.colorString = color?.colorString ?? ""
|
||||||
// self.colorString = color?.colorString ?? ""
|
self.innerList = MTMathList(color?.innerList)
|
||||||
// self.innerList = MTMathList(color?.innerList)
|
}
|
||||||
// }
|
|
||||||
//
|
override init() {
|
||||||
// override init() {
|
super.init()
|
||||||
// super.init()
|
self.type = .textcolor
|
||||||
// self.type = .textcolor
|
}
|
||||||
// }
|
|
||||||
//
|
public override var string: String {
|
||||||
// public override var string: String {
|
"\\textcolor{\(self.colorString)}{\(self.innerList!.string)}"
|
||||||
// "\\textcolor{\(self.colorString)}{\(self.innerList!.string)}"
|
}
|
||||||
// }
|
|
||||||
//
|
override public var finalized: MTMathAtom {
|
||||||
// override public var finalized: MTMathAtom {
|
let newColor = super.finalized as! MTMathTextColor
|
||||||
// let newColor = super.finalized as! MTMathTextColor
|
newColor.innerList = newColor.innerList?.finalized
|
||||||
// newColor.innerList = newColor.innerList?.finalized
|
return newColor
|
||||||
// return newColor
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
// MARK: - MTMathColorbox
|
// MARK: - MTMathColorbox
|
||||||
/** An atom representing an colorbox element.
|
/** An atom representing an colorbox element.
|
||||||
|
|||||||
@@ -587,18 +587,18 @@ public struct MTMathListBuilder {
|
|||||||
}
|
}
|
||||||
let table = self.buildTable(env: env, firstList:nil, isRow:false)
|
let table = self.buildTable(env: env, firstList:nil, isRow:false)
|
||||||
return table
|
return table
|
||||||
} else if command == "color" || command == "textcolor" {
|
} else if command == "color" {
|
||||||
// A color command has 2 arguments
|
// A color command has 2 arguments
|
||||||
let mathColor = MTMathColor()
|
let mathColor = MTMathColor()
|
||||||
mathColor.colorString = self.readColor()!
|
mathColor.colorString = self.readColor()!
|
||||||
mathColor.innerList = self.buildInternal(true)
|
mathColor.innerList = self.buildInternal(true)
|
||||||
return mathColor
|
return mathColor
|
||||||
// } else if command == "textcolor" {
|
} else if command == "textcolor" {
|
||||||
// // A textcolor command has 2 arguments
|
// A textcolor command has 2 arguments
|
||||||
// let mathColor = MTMathTextColor()
|
let mathColor = MTMathTextColor()
|
||||||
// mathColor.colorString = self.readColor()!
|
mathColor.colorString = self.readColor()!
|
||||||
// mathColor.innerList = self.buildInternal(true)
|
mathColor.innerList = self.buildInternal(true)
|
||||||
// return mathColor
|
return mathColor
|
||||||
} else if command == "colorbox" {
|
} else if command == "colorbox" {
|
||||||
// A color command has 2 arguments
|
// A color command has 2 arguments
|
||||||
let mathColorbox = MTMathColorbox()
|
let mathColorbox = MTMathColorbox()
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ class MTTypesetter {
|
|||||||
// so we skip to the next node.
|
// so we skip to the next node.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
case .color, .textcolor:
|
case .color:
|
||||||
// stash the existing layout
|
// stash the existing layout
|
||||||
if currentLine.length > 0 {
|
if currentLine.length > 0 {
|
||||||
self.addDisplayLine()
|
self.addDisplayLine()
|
||||||
@@ -512,35 +512,35 @@ class MTTypesetter {
|
|||||||
currentPosition.x += display!.width
|
currentPosition.x += display!.width
|
||||||
displayAtoms.append(display!)
|
displayAtoms.append(display!)
|
||||||
|
|
||||||
// case .textcolor:
|
case .textcolor:
|
||||||
// // stash the existing layout
|
// stash the existing layout
|
||||||
// if currentLine.length > 0 {
|
if currentLine.length > 0 {
|
||||||
// self.addDisplayLine()
|
self.addDisplayLine()
|
||||||
// }
|
}
|
||||||
// let colorAtom = atom as! MTMathTextColor
|
let colorAtom = atom as! MTMathTextColor
|
||||||
// let display = MTTypesetter.createLineForMathList(colorAtom.innerList, font: font, style: style)
|
let display = MTTypesetter.createLineForMathList(colorAtom.innerList, font: font, style: style)
|
||||||
// display!.localTextColor = MTColor(fromHexString: colorAtom.colorString)
|
display!.localTextColor = MTColor(fromHexString: colorAtom.colorString)
|
||||||
//
|
|
||||||
// if prevNode != nil {
|
if prevNode != nil {
|
||||||
// let subDisplay: MTDisplay = display!.subDisplays[0]
|
let subDisplay: MTDisplay = display!.subDisplays[0]
|
||||||
// let subDisplayAtom = (subDisplay as? MTCTLineDisplay)!.atoms[0]
|
let subDisplayAtom = (subDisplay as? MTCTLineDisplay)!.atoms[0]
|
||||||
// let interElementSpace = self.getInterElementSpace(prevNode!.type, right:subDisplayAtom.type)
|
let interElementSpace = self.getInterElementSpace(prevNode!.type, right:subDisplayAtom.type)
|
||||||
// if currentLine.length > 0 {
|
if currentLine.length > 0 {
|
||||||
// if interElementSpace > 0 {
|
if interElementSpace > 0 {
|
||||||
// // add a kerning of that space to the previous character
|
// add a kerning of that space to the previous character
|
||||||
// currentLine.addAttribute(kCTKernAttributeName as NSAttributedString.Key,
|
currentLine.addAttribute(kCTKernAttributeName as NSAttributedString.Key,
|
||||||
// value:NSNumber(floatLiteral: interElementSpace),
|
value:NSNumber(floatLiteral: interElementSpace),
|
||||||
// range:currentLine.mutableString.rangeOfComposedCharacterSequence(at: currentLine.length-1))
|
range:currentLine.mutableString.rangeOfComposedCharacterSequence(at: currentLine.length-1))
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// // increase the space
|
// increase the space
|
||||||
// currentPosition.x += interElementSpace
|
currentPosition.x += interElementSpace
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// display!.position = currentPosition
|
display!.position = currentPosition
|
||||||
// currentPosition.x += display!.width
|
currentPosition.x += display!.width
|
||||||
// displayAtoms.append(display!)
|
displayAtoms.append(display!)
|
||||||
|
|
||||||
case .colorBox:
|
case .colorBox:
|
||||||
// stash the existing layout
|
// stash the existing layout
|
||||||
|
|||||||
Reference in New Issue
Block a user