Working on typesetting test failures.

This commit is contained in:
Michael Griebling
2023-01-14 15:30:44 -05:00
parent 2ee1cc0b19
commit fad14cfa3b
6 changed files with 187 additions and 223 deletions

View File

@@ -64,12 +64,12 @@ public class MTFont {
} }
func get(nameForGlyph glyph:CGGlyph) -> String { func get(nameForGlyph glyph:CGGlyph) -> String {
let name = self.defaultCGFont.name(for: glyph) let name = defaultCGFont.name(for: glyph) as? String
return name! as String return name!
} }
func get(glyphWithName name:String) -> CGGlyph { func get(glyphWithName name:String) -> CGGlyph {
return self.defaultCGFont.getGlyphWithGlyphName(name: name as CFString) return defaultCGFont.getGlyphWithGlyphName(name: name as CFString)
} }
var fontSize:CGFloat { var fontSize:CGFloat {

View File

@@ -44,7 +44,7 @@ class GlyphPart {
class MTFontMathTable { class MTFontMathTable {
// The font for this math table. // The font for this math table.
weak var font:MTFont? // @property (nonatomic, readonly, weak) MTFont* font; var font:MTFont? // @property (nonatomic, readonly, weak) MTFont* font;
var _unitsPerEm: UInt var _unitsPerEm: UInt
var _fontSize: CGFloat var _fontSize: CGFloat
@@ -62,7 +62,7 @@ class MTFontMathTable {
init(withFont font: MTFont?, mathTable:NSDictionary) { init(withFont font: MTFont?, mathTable:NSDictionary) {
assert(font != nil, "font has nil value") assert(font != nil, "font has nil value")
assert(font!.ctFont != nil, "font.ctFont has nil value") assert(font!.ctFont != nil, "font.ctFont has nil value")
self.font = font; self.font = font
// do domething with font // do domething with font
_unitsPerEm = UInt(CTFontGetUnitsPerEm(font!.ctFont)) _unitsPerEm = UInt(CTFontGetUnitsPerEm(font!.ctFont))
_fontSize = font!.fontSize; _fontSize = font!.fontSize;
@@ -202,12 +202,12 @@ class MTFontMathTable {
} }
func getVariantsForGlyph(_ glyph: CGGlyph, inDictionary variants:NSDictionary?) -> [NSNumber?] { func getVariantsForGlyph(_ glyph: CGGlyph, inDictionary variants:NSDictionary?) -> [NSNumber?] {
let glyphName = self.font?.get(nameForGlyph: glyph) let glyphName = self.font!.get(nameForGlyph: glyph)
let variantGlyphs = variants![glyphName!] as! NSArray? let variantGlyphs = variants![glyphName] as! NSArray?
let glyphArray = NSMutableArray(capacity: variantGlyphs!.count) let glyphArray = NSMutableArray(capacity: variantGlyphs!.count)
if variantGlyphs == nil { if variantGlyphs == nil {
// There are no extra variants, so just add the current glyph to it. // There are no extra variants, so just add the current glyph to it.
let glyph = self.font?.get(glyphWithName: glyphName!) let glyph = self.font!.get(glyphWithName: glyphName)
glyphArray.add(glyph as Any) glyphArray.add(glyph as Any)
return glyphArray as! [NSNumber?] return glyphArray as! [NSNumber?]
} }

View File

@@ -129,11 +129,11 @@ public class MTMathAtom: NSObject {
} }
} }
public var nucleus: String = "" public var nucleus: String = ""
public var childAtoms = [MTMathAtom]() // atoms that fused to create this one // public var childAtoms = [MTMathAtom]() // atoms that fused to create this one
public var indexRange = NSRange(location: 0, length: 0) // indexRange in list that this atom tracks: public var indexRange = NSRange(location: 0, length: 0) // indexRange in list that this atom tracks:
var fontStyle: MTFontStyle = .defaultStyle var fontStyle: MTFontStyle = .defaultStyle
var fusedAtoms: MTMathList? var fusedAtoms = [MTMathAtom]() // atoms that fused to create this one
init(_ atom:MTMathAtom?) { init(_ atom:MTMathAtom?) {
guard let atom = atom else { return } guard let atom = atom else { return }
@@ -143,8 +143,8 @@ public class MTMathAtom: NSObject {
self.superScript = MTMathList(atom.superScript) self.superScript = MTMathList(atom.superScript)
self.indexRange = atom.indexRange self.indexRange = atom.indexRange
self.fontStyle = atom.fontStyle self.fontStyle = atom.fontStyle
self.childAtoms = [MTMathAtom](atom.childAtoms) // self.childAtoms = [MTMathAtom](atom.childAtoms)
self.fusedAtoms = MTMathList(atom.fusedAtoms) self.fusedAtoms = atom.fusedAtoms
} }
override init() { } override init() { }
@@ -239,19 +239,17 @@ public class MTMathAtom: NSObject {
assert(self.subScript == nil, "Cannot fuse into an atom which has a subscript: \(self)"); assert(self.subScript == nil, "Cannot fuse into an atom which has a subscript: \(self)");
assert(self.superScript == nil, "Cannot fuse into an atom which has a superscript: \(self)"); assert(self.superScript == nil, "Cannot fuse into an atom which has a superscript: \(self)");
assert(atom.type == self.type, "Only atoms of the same type can be fused. \(self), \(atom)"); assert(atom.type == self.type, "Only atoms of the same type can be fused. \(self), \(atom)");
guard self.subScript == nil, guard self.subScript == nil, self.superScript == nil, self.type == atom.type
self.superScript == nil, else { print("Can't fuse these 2 atoms"); return }
self.type == atom.type
else {
print("Can't fuse these 2 atoms")
return
}
self.childAtoms.append(self) // Update the fused atoms list
if atom.childAtoms.count > 0 { if self.fusedAtoms.isEmpty {
self.childAtoms += atom.childAtoms self.fusedAtoms.append(MTMathAtom(self))
}
if atom.fusedAtoms.count > 0 {
self.fusedAtoms.append(contentsOf: atom.fusedAtoms)
} else { } else {
self.childAtoms.append(atom) self.fusedAtoms.append(atom)
} }
// Update nucleus: // Update nucleus:

View File

@@ -33,7 +33,7 @@ protocol DownShift {
// MARK: - MTDisplay // MARK: - MTDisplay
/// The base class for rendering a math equation. /// The base class for rendering a math equation.
class MTDisplay { class MTDisplay:NSObject {
// needed for isIos6Supported() func above // needed for isIos6Supported() func above
static var initialized = false static var initialized = false
@@ -50,7 +50,6 @@ class MTDisplay {
} }
} }
/// Gets the bounding rectangle for the MTDisplay /// Gets the bounding rectangle for the MTDisplay
func displayBounds() -> CGRect { func displayBounds() -> CGRect {
return CGRectMake(self.position.x, self.position.y - self.descent, self.width, self.ascent + self.descent) return CGRectMake(self.position.x, self.position.y - self.descent, self.width, self.ascent + self.descent)
@@ -117,7 +116,11 @@ class MTCTLineDisplay : MTDisplay {
var line:CTLine! var line:CTLine!
/// The attributed string used to generate the CTLineRef. Note setting this does not reset the dimensions of /// The attributed string used to generate the CTLineRef. Note setting this does not reset the dimensions of
/// the display. So set only when /// the display. So set only when
var attributedString:NSAttributedString? var attributedString:NSAttributedString? {
didSet {
line = CTLineCreateWithAttributedString(attributedString!)
}
}
/// An array of MTMathAtoms that this CTLine displays. Used for indexing back into the MTMathList /// An array of MTMathAtoms that this CTLine displays. Used for indexing back into the MTMathList
var atoms = [MTMathAtom]() var atoms = [MTMathAtom]()
@@ -126,6 +129,7 @@ class MTCTLineDisplay : MTDisplay {
super.init() super.init()
self.position = position self.position = position
self.attributedString = attrString self.attributedString = attrString
self.line = CTLineCreateWithAttributedString(attrString!)
self.range = range self.range = range
self.atoms = atoms self.atoms = atoms
// We can't use typographic bounds here as the ascent and descent returned are for the font and not for the line. // We can't use typographic bounds here as the ascent and descent returned are for the font and not for the line.
@@ -142,10 +146,10 @@ class MTCTLineDisplay : MTDisplay {
} }
} }
func set(attrString: NSAttributedString?) { // func set(attrString: NSAttributedString?) {
attributedString = attrString // attributedString = attrString
line = CTLineCreateWithAttributedString(attributedString!) // line = CTLineCreateWithAttributedString(attributedString!)
} // }
func set(textColor:MTColor) { func set(textColor:MTColor) {
self.textColor = textColor self.textColor = textColor
@@ -219,7 +223,7 @@ class MTMathListDisplay : MTDisplay {
super.init() super.init()
self.subDisplays = displays self.subDisplays = displays
self.position = CGPoint.zero self.position = CGPoint.zero
self.type = .regular //kMTLinePositionRegular; self.type = .regular
self.index = NSNotFound self.index = NSNotFound
self.range = range self.range = range
self.recomputeDimensions() self.recomputeDimensions()
@@ -623,8 +627,8 @@ class MTLargeOpLimitsDisplay : MTDisplay {
self.lowerLimit = lowerLimit; self.lowerLimit = lowerLimit;
self.nucleus = nucleus; self.nucleus = nucleus;
var maxWidth = max(nucleus!.width, upperLimit!.width); var maxWidth = max(nucleus!.width, upperLimit?.width ?? 0)
maxWidth = max(maxWidth, lowerLimit!.width); maxWidth = max(maxWidth, lowerLimit?.width ?? 0)
self.limitShift = limitShift; self.limitShift = limitShift;
self.upperLimitGap = 0; self.upperLimitGap = 0;

View File

@@ -9,7 +9,7 @@ import Foundation
import CoreGraphics import CoreGraphics
import CoreText import CoreText
// Mark: - Inter Element Spacing // MARK: - - Inter Element Spacing
enum InterElementSpaceType : Int { enum InterElementSpaceType : Int {
case invalid = -1 case invalid = -1
@@ -20,10 +20,10 @@ enum InterElementSpaceType : Int {
case nsThick case nsThick
} }
var interElementSpaceArray:[[InterElementSpaceType]]? = nil var interElementSpaceArray = [[InterElementSpaceType]]()
func getInterElementSpaces() -> [[InterElementSpaceType]] { func getInterElementSpaces() -> [[InterElementSpaceType]] {
if interElementSpaceArray == nil { if interElementSpaceArray.isEmpty {
interElementSpaceArray = interElementSpaceArray =
// ordinary operator binary relation open close punct fraction // ordinary operator binary relation open close punct fraction
[ [.none, .thin, .nsMedium, .nsThick, .none, .none, .none, .nsThin], // ordinary [ [.none, .thin, .nsMedium, .nsThick, .none, .none, .none, .nsThin], // ordinary
@@ -34,14 +34,14 @@ func getInterElementSpaces() -> [[InterElementSpaceType]] {
[.none, .thin, .nsMedium, .nsThick, .none, .none, .none, .nsThin], // close [.none, .thin, .nsMedium, .nsThick, .none, .none, .none, .nsThin], // close
[.nsThin, .nsThin, .invalid, .nsThin, .nsThin, .nsThin, .nsThin, .nsThin], // punct [.nsThin, .nsThin, .invalid, .nsThin, .nsThin, .nsThin, .nsThin, .nsThin], // punct
[.nsThin, .thin, .nsMedium, .nsThick, .nsThin, .none, .nsThin, .nsThin], // fraction [.nsThin, .thin, .nsMedium, .nsThick, .nsThin, .none, .nsThin, .nsThin], // fraction
[.nsMedium, .nsThin, .nsMedium, .nsThick, .none, .none, .none, .nsThin]] // radical [.nsMedium, .nsThin, .nsMedium, .nsThick, .none, .none, .none, .nsThin]] // radical
} }
return interElementSpaceArray! return interElementSpaceArray
} }
// Get's the index for the given type. If row is true, the index is for the row (i.e. left element) otherwise it is for the column (right element) // Get's the index for the given type. If row is true, the index is for the row (i.e. left element) otherwise it is for the column (right element)
func getInterElementSpaceArrayIndexForType(_ type:MTMathAtomType, row:Bool) -> UInt { func getInterElementSpaceArrayIndexForType(_ type:MTMathAtomType, row:Bool) -> Int {
switch type { switch type {
case .ordinary, .placeholder: // A placeholder is treated as ordinary case .ordinary, .placeholder: // A placeholder is treated as ordinary
return 0 return 0
@@ -61,22 +61,22 @@ func getInterElementSpaceArrayIndexForType(_ type:MTMathAtomType, row:Bool) -> U
.inner: .inner:
return 7; return 7;
case .radical: case .radical:
if (row) { if row {
// Radicals have inter element spaces only when on the left side. // Radicals have inter element spaces only when on the left side.
// Note: This is a departure from latex but we don't want \sqrt{4}4 to look weird so we put a space in between. // Note: This is a departure from latex but we don't want \sqrt{4}4 to look weird so we put a space in between.
// They have the same spacing as ordinary except with ordinary. // They have the same spacing as ordinary except with ordinary.
return 8; return 8;
} else { } else {
assert(false, "Interelement space undefined for radical on the right. Treat radical as ordinary.") assert(false, "Interelement space undefined for radical on the right. Treat radical as ordinary.")
return UInt.max return Int.max
} }
default: default:
assert(false, "Interelement space undefined for type \(type)") assert(false, "Interelement space undefined for type \(type)")
return UInt.max return Int.max
} }
} }
// Mark: - Italics // MARK: - - Italics
// mathit // mathit
func getItalicized(_ ch:Character) -> UTF32Char { func getItalicized(_ ch:Character) -> UTF32Char {
var unicode = ch.utf32Char var unicode = ch.utf32Char
@@ -296,38 +296,25 @@ func styleCharacter(_ ch:Character, fontStyle:MTFontStyle) -> UTF32Char {
switch fontStyle { switch fontStyle {
case .defaultStyle: case .defaultStyle:
return getDefaultStyle(ch); return getDefaultStyle(ch);
case .roman: case .roman:
return ch.utf32Char return ch.utf32Char
case .bold: case .bold:
return getBold(ch); return getBold(ch);
case .italic: case .italic:
return getItalicized(ch); return getItalicized(ch);
case .boldItalic: case .boldItalic:
return getBoldItalic(ch); return getBoldItalic(ch);
case .caligraphic: case .caligraphic:
return getCaligraphic(ch); return getCaligraphic(ch);
case .typewriter: case .typewriter:
return getTypewriter(ch); return getTypewriter(ch);
case .sansSerif: case .sansSerif:
return getSansSerif(ch); return getSansSerif(ch);
case .fraktur: case .fraktur:
return getFraktur(ch); return getFraktur(ch);
case .blackboard: case .blackboard:
return getBlackboard(ch); return getBlackboard(ch);
// default:
// NSException(name: NSExceptionName("Invalid style"), reason: "Unknown style \(fontStyle) for font.").raise()
} }
// return ch.utf32Char
} }
func changeFont(_ str:String, fontStyle:MTFontStyle) -> String { func changeFont(_ str:String, fontStyle:MTFontStyle) -> String {
@@ -337,39 +324,20 @@ func changeFont(_ str:String, fontStyle:MTFontStyle) -> String {
let ch = codes[i] let ch = codes[i]
var unicode = styleCharacter(ch, fontStyle: fontStyle); var unicode = styleCharacter(ch, fontStyle: fontStyle);
unicode = NSSwapHostIntToLittle(unicode) unicode = NSSwapHostIntToLittle(unicode)
let charStr = String(unicode) let charStr = String(UnicodeScalar(unicode)!)
retval.append(charStr) retval.append(charStr)
} }
return retval return retval
} }
//func mathItalicize(_ str:String) -> String {
// let retval = NSMutableString(capacity: str.count)
// var charBuffer = [unichar]()
// charBuffer.reserveCapacity(str.count)
// (str as NSString).getCharacters(&charBuffer, range: NSMakeRange(0, str.count))
// for i in 0 ..< str.count {
// let ch = charBuffer[i]
// var unicode = getItalicized(ch)
// unicode = NSSwapHostIntToLittle(unicode)
// let charStr = NSString(bytes: &unicode, length: MemoryLayout.size(ofValue: unicode), encoding: NSUTF32LittleEndianStringEncoding)
// retval.append(charStr! as String)
// }
// return retval as String
//}
func getBboxDetails(_ bbox:CGRect, ascent:inout CGFloat, descent:inout CGFloat) { func getBboxDetails(_ bbox:CGRect, ascent:inout CGFloat, descent:inout CGFloat) {
if ascent != 0 { ascent = max(0, CGRectGetMaxY(bbox) - 0)
ascent = max(0, CGRectGetMaxY(bbox) - 0)
}
if descent != 0 { // Descent is how much the line goes below the origin. However if the line is all above the origin, then descent can't be negative.
// Descent is how much the line goes below the origin. However if the line is all above the origin, then descent can't be negative. descent = max(0, 0 - CGRectGetMinY(bbox))
descent = max(0, 0 - CGRectGetMinY(bbox))
}
} }
// Mark: - MTTypesetter // MARK: - - MTTypesetter
class MTTypesetter { class MTTypesetter {
var font:MTFont! var font:MTFont!
@@ -378,12 +346,10 @@ class MTTypesetter {
var currentLine:NSMutableAttributedString! var currentLine:NSMutableAttributedString!
var currentAtoms = [MTMathAtom]() // List of atoms that make the line var currentAtoms = [MTMathAtom]() // List of atoms that make the line
var currentLineIndexRange = NSMakeRange(0, 0) var currentLineIndexRange = NSMakeRange(0, 0)
var style:MTLineStyle { var style:MTLineStyle
didSet { var styleFont:MTFont {
self.styleFont = self.font.copy(withSize: Self.getStyleSize(self.style, font: self.font)) self.font.copy(withSize: Self.getStyleSize(self.style, font: self.font))
}
} }
var styleFont:MTFont!
var cramped = false var cramped = false
var spaced = false var spaced = false
@@ -405,7 +371,8 @@ class MTTypesetter {
let typesetter = MTTypesetter(withFont:font, style:style, cramped:cramped, spaced:spaced) let typesetter = MTTypesetter(withFont:font, style:style, cramped:cramped, spaced:spaced)
typesetter.createDisplayAtoms(preprocessedAtoms) typesetter.createDisplayAtoms(preprocessedAtoms)
let lastAtom = mathList!.atoms.last let lastAtom = mathList!.atoms.last
let line = MTMathListDisplay(withDisplays: typesetter.displayAtoms, range: NSMakeRange(0, NSMaxRange(lastAtom!.indexRange))) let last = lastAtom?.indexRange ?? NSMakeRange(0, 0)
let line = MTMathListDisplay(withDisplays: typesetter.displayAtoms, range: NSMakeRange(0, NSMaxRange(last)))
return line return line
} }
@@ -466,13 +433,11 @@ class MTTypesetter {
let original = font!.fontSize let original = font!.fontSize
switch style { switch style {
case .display, .text: case .display, .text:
return original; return original
case .script: case .script:
return original * font!.mathTable!.scriptScaleDown; return original * font!.mathTable!.scriptScaleDown
case .scriptOfScript: case .scriptOfScript:
return original * font!.mathTable!.scriptScriptScaleDown; return original * font!.mathTable!.scriptScriptScaleDown
} }
} }
@@ -490,8 +455,8 @@ class MTTypesetter {
func createDisplayAtoms(_ preprocessed:[MTMathAtom]) { func createDisplayAtoms(_ preprocessed:[MTMathAtom]) {
// items should contain all the nodes that need to be layed out. // items should contain all the nodes that need to be layed out.
// convert to a list of DisplayAtoms // convert to a list of DisplayAtoms
var prevNode:MTMathAtom? = nil; var prevNode:MTMathAtom? = nil
var lastType:MTMathAtomType = .style var lastType:MTMathAtomType!
for atom in preprocessed { for atom in preprocessed {
switch atom.type { switch atom.type {
case .number, .variable,. unaryOperator: case .number, .variable,. unaryOperator:
@@ -520,7 +485,7 @@ class MTTypesetter {
self.addDisplayLine() self.addDisplayLine()
} }
let style = atom as! MTMathStyle let style = atom as! MTMathStyle
self.style = style.style; self.style = style.style
// We need to preserve the prevNode for any interelement space changes. // We need to preserve the prevNode for any interelement space changes.
// so we skip to the next node. // so we skip to the next node.
continue continue
@@ -695,8 +660,8 @@ class MTTypesetter {
// All we need is render the character and set the interelement space. // All we need is render the character and set the interelement space.
if prevNode != nil { if prevNode != nil {
let interElementSpace = self.getInterElementSpace(prevNode!.type, right:atom.type) let interElementSpace = self.getInterElementSpace(prevNode!.type, right:atom.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),
@@ -704,26 +669,27 @@ class MTTypesetter {
} }
} else { } else {
// increase the space // increase the space
currentPosition.x += interElementSpace; currentPosition.x += interElementSpace
} }
} }
var current:NSAttributedString? = nil var current:NSAttributedString? = nil
if (atom.type == .placeholder) { if atom.type == .placeholder {
let color = MTTypesetter.placeholderColor let color = MTTypesetter.placeholderColor
current = NSAttributedString(string: atom.nucleus, attributes:[kCTForegroundColorAttributeName as NSAttributedString.Key : color.cgColor]) current = NSAttributedString(string:atom.nucleus,
attributes:[kCTForegroundColorAttributeName as NSAttributedString.Key : color.cgColor])
} else { } else {
current = NSAttributedString(string:atom.nucleus) current = NSAttributedString(string:atom.nucleus)
} }
currentLine.append(current!) currentLine.append(current!)
// add the atom to the current range // add the atom to the current range
if (currentLineIndexRange.location == NSNotFound) { if currentLineIndexRange.location == NSNotFound {
currentLineIndexRange = atom.indexRange; currentLineIndexRange = atom.indexRange
} else { } else {
currentLineIndexRange.length += atom.indexRange.length currentLineIndexRange.length += atom.indexRange.length
} }
// add the fused atoms // add the fused atoms
if !atom.childAtoms.isEmpty { if !atom.fusedAtoms.isEmpty {
currentAtoms.append(contentsOf: atom.childAtoms) //.addObjectsFromArray:atom.fusedAtoms) currentAtoms.append(contentsOf: atom.fusedAtoms) //.addObjectsFromArray:atom.fusedAtoms)
} else { } else {
currentAtoms.append(atom) currentAtoms.append(atom)
} }
@@ -746,14 +712,14 @@ class MTTypesetter {
} }
self.makeScripts(atom, display:line, index:UInt(NSMaxRange(atom.indexRange) - 1), delta:delta) self.makeScripts(atom, display:line, index:UInt(NSMaxRange(atom.indexRange) - 1), delta:delta)
} }
} } // switch
lastType = atom.type; lastType = atom.type
prevNode = atom; prevNode = atom
} } // node loop
if (currentLine.length > 0) { if currentLine.length > 0 {
self.addDisplayLine() self.addDisplayLine()
} }
if spaced { if spaced && lastType != nil {
// If spaced then add an interelement space between the last type and close // If spaced then add an interelement space between the last type and close
let display = displayAtoms.last let display = displayAtoms.last
let interElementSpace = self.getInterElementSpace(lastType, right:.close) let interElementSpace = self.getInterElementSpace(lastType, right:.close)
@@ -764,7 +730,7 @@ class MTTypesetter {
@discardableResult @discardableResult
func addDisplayLine() -> MTCTLineDisplay? { func addDisplayLine() -> MTCTLineDisplay? {
// add the font // add the font
currentLine.addAttribute(kCTFontAttributeName as NSAttributedString.Key, value:styleFont.ctFont!, range:NSMakeRange(0, currentLine.length)) currentLine.addAttribute(kCTFontAttributeName as NSAttributedString.Key, value:styleFont.ctFont as Any, range:NSMakeRange(0, currentLine.length))
/*assert(currentLineIndexRange.length == numCodePoints(currentLine.string), /*assert(currentLineIndexRange.length == numCodePoints(currentLine.string),
"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);*/
@@ -780,7 +746,7 @@ class MTTypesetter {
return displayAtom return displayAtom
} }
// Mark: Spacing // MARK: - Spacing
// Returned in units of mu = 1/18 em. // Returned in units of mu = 1/18 em.
func getSpacingInMu(_ type: InterElementSpaceType) -> Int { func getSpacingInMu(_ type: InterElementSpaceType) -> Int {
@@ -802,8 +768,8 @@ class MTTypesetter {
} }
func getInterElementSpace(_ left: MTMathAtomType, right:MTMathAtomType) -> CGFloat { func getInterElementSpace(_ left: MTMathAtomType, right:MTMathAtomType) -> CGFloat {
let leftIndex = getInterElementSpaceArrayIndexForType(left, row: true); let leftIndex = getInterElementSpaceArrayIndexForType(left, row: true)
let rightIndex = getInterElementSpaceArrayIndexForType(right, row: false); let rightIndex = getInterElementSpaceArrayIndexForType(right, row: false)
let spaceArray = getInterElementSpaces()[Int(leftIndex)] let spaceArray = getInterElementSpaces()[Int(leftIndex)]
let spaceTypeObj = spaceArray[Int(rightIndex)] let spaceTypeObj = spaceArray[Int(rightIndex)]
let spaceType = spaceTypeObj let spaceType = spaceTypeObj
@@ -818,7 +784,7 @@ class MTTypesetter {
} }
// Mark: Subscript/Superscript // MARK: - Subscript/Superscript
func scriptStyle() -> MTLineStyle { func scriptStyle() -> MTLineStyle {
switch style { switch style {
@@ -922,7 +888,7 @@ class MTTypesetter {
currentPosition.x += max(superScript!.width + delta, ssubscript!.width) + styleFont.mathTable!.spaceAfterScript; currentPosition.x += max(superScript!.width + delta, ssubscript!.width) + styleFont.mathTable!.spaceAfterScript;
} }
// Mark: - Fractions // MARK: - - Fractions
func numeratorShiftUp(_ hasRule:Bool) -> CGFloat { func numeratorShiftUp(_ hasRule:Bool) -> CGFloat {
if hasRule { if hasRule {
@@ -1080,7 +1046,7 @@ class MTTypesetter {
return innerDisplay return innerDisplay
} }
// Mark: Radicals // MARK: - Radicals
func radicalVerticalGap() -> CGFloat { func radicalVerticalGap() -> CGFloat {
if style == .display { if style == .display {
@@ -1102,7 +1068,7 @@ class MTTypesetter {
glyphDisplay = self.constructGlyph(radicalGlyph, withHeight:radicalHeight) glyphDisplay = self.constructGlyph(radicalGlyph, withHeight:radicalHeight)
} }
if glyphDisplay != nil { if glyphDisplay == nil {
// No constructed display so use the glyph we got. // No constructed display so use the glyph we got.
glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: NSMakeRange(NSNotFound, 0), font:styleFont) glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: NSMakeRange(NSNotFound, 0), font:styleFont)
glyphDisplay!.ascent = glyphAscent; glyphDisplay!.ascent = glyphAscent;
@@ -1149,7 +1115,7 @@ class MTTypesetter {
return radical; return radical;
} }
// Mark: Glyphs // MARK: - Glyphs
func findGlyph(_ glyph:CGGlyph, withHeight height:CGFloat, glyphAscent:inout CGFloat, glyphDescent:inout CGFloat, glyphWidth:inout CGFloat) -> CGGlyph { func findGlyph(_ glyph:CGGlyph, withHeight height:CGFloat, glyphAscent:inout CGFloat, glyphDescent:inout CGFloat, glyphWidth:inout CGFloat) -> CGGlyph {
let variants = styleFont.mathTable!.getVerticalVariantsForGlyph(glyph) let variants = styleFont.mathTable!.getVerticalVariantsForGlyph(glyph)
@@ -1158,13 +1124,11 @@ class MTTypesetter {
glyphs.reserveCapacity(numVariants) glyphs.reserveCapacity(numVariants)
for i in 0 ..< numVariants { for i in 0 ..< numVariants {
let glyph = variants[i]!.uint16Value let glyph = variants[i]!.uint16Value
glyphs[i] = glyph glyphs.append(glyph)
} }
var bboxes = [CGRect]() // = [numVariants) var bboxes = [CGRect](repeating: CGRect.zero, count: numVariants)
var advances = [CGSize]() // [numVariants) var advances = [CGSize](repeating: CGSize.zero, count: numVariants)
bboxes.reserveCapacity(numVariants)
advances.reserveCapacity(numVariants)
// Get the bounds for these glyphs // Get the bounds for these glyphs
CTFontGetBoundingRectsForGlyphs(styleFont.ctFont, .horizontal, glyphs, &bboxes, numVariants) CTFontGetBoundingRectsForGlyphs(styleFont.ctFont, .horizontal, glyphs, &bboxes, numVariants)
@@ -1206,10 +1170,10 @@ class MTTypesetter {
} }
func constructGlyphWithParts(_ parts:[GlyphPart], glyphHeight:CGFloat, glyphs:inout [NSNumber], offsets:inout [NSNumber], height:inout CGFloat) { func constructGlyphWithParts(_ parts:[GlyphPart], glyphHeight:CGFloat, glyphs:inout [NSNumber], offsets:inout [NSNumber], height:inout CGFloat) {
assert(!glyphs.isEmpty) // assert(!glyphs.isEmpty)
assert(!offsets.isEmpty) // assert(!offsets.isEmpty)
for numExtenders in 0...1 { for numExtenders in 0..<Int.max {
var glyphsRv = [NSNumber]() var glyphsRv = [NSNumber]()
var offsetsRv = [NSNumber]() var offsetsRv = [NSNumber]()
@@ -1274,11 +1238,10 @@ class MTTypesetter {
func findGlyphForCharacterAtIndex(_ index:String.Index, inString str:String) -> CGGlyph { func findGlyphForCharacterAtIndex(_ index:String.Index, inString str:String) -> CGGlyph {
// Get the character at index taking into account UTF-32 characters // Get the character at index taking into account UTF-32 characters
let range = str.rangeOfComposedCharacterSequence(at: index) //.rangeOfComposedCharacterSequenceAtIndex(index) var chars = Array(str[index].utf16)
var chars = str[range].unicodeScalars.map { UInt16($0.value) }
// Get the glyph from the font // Get the glyph from the font
var glyph = [CGGlyph](repeating: CGGlyph.zero, count: chars.count) // [range.length) var glyph = [CGGlyph](repeating: CGGlyph.zero, count: chars.count)
let found = CTFontGetGlyphsForCharacters(styleFont.ctFont, &chars, &glyph, chars.count) let found = CTFontGetGlyphsForCharacters(styleFont.ctFont, &chars, &glyph, chars.count)
if !found { if !found {
// the font did not contain a glyph for our character, so we just return 0 (notdef) // the font did not contain a glyph for our character, so we just return 0 (notdef)
@@ -1287,7 +1250,7 @@ class MTTypesetter {
return glyph[0] return glyph[0]
} }
// Mark: Large Operators // MARK: - Large Operators
func makeLargeOp(_ op:MTLargeOperator!) -> MTDisplay? { func makeLargeOp(_ op:MTLargeOperator!) -> MTDisplay? {
let limits = op.limits && style == .display let limits = op.limits && style == .display
@@ -1307,7 +1270,7 @@ class MTTypesetter {
var ascent=CGFloat(0), descent=CGFloat(0) var ascent=CGFloat(0), descent=CGFloat(0)
getBboxDetails(bbox, ascent: &ascent, descent: &descent) getBboxDetails(bbox, ascent: &ascent, descent: &descent)
let shiftDown = 0.5*(ascent - descent) - styleFont.mathTable!.axisHeight; let shiftDown = 0.5*(ascent - descent) - styleFont.mathTable!.axisHeight;
let glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: op.indexRange, font: styleFont) //initWithGlpyh:glyph range:op.indexRange font:styleFont) let glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: op.indexRange, font: styleFont)
glyphDisplay.ascent = ascent; glyphDisplay.ascent = ascent;
glyphDisplay.descent = descent; glyphDisplay.descent = descent;
glyphDisplay.width = width; glyphDisplay.width = width;
@@ -1365,7 +1328,7 @@ class MTTypesetter {
} }
} }
// Mark: Large delimiters // MARK: - Large delimiters
// Delimiter shortfall from plain.tex // Delimiter shortfall from plain.tex
static let kDelimiterFactor = CGFloat(901) static let kDelimiterFactor = CGFloat(901)
@@ -1384,7 +1347,7 @@ class MTTypesetter {
// be at most 5pt short. // be at most 5pt short.
let glyphHeight = max(d1, d2); let glyphHeight = max(d1, d2);
var innerElements = [MTDisplay]() // NSMutableArray() var innerElements = [MTDisplay]()
var position = CGPoint.zero var position = CGPoint.zero
if inner!.leftBoundary != nil && !inner!.leftBoundary!.nucleus.isEmpty { if inner!.leftBoundary != nil && !inner!.leftBoundary!.nucleus.isEmpty {
let leftGlyph = self.findGlyphForBoundary(inner!.leftBoundary!.nucleus, withHeight:glyphHeight) let leftGlyph = self.findGlyphForBoundary(inner!.leftBoundary!.nucleus, withHeight:glyphHeight)
@@ -1418,7 +1381,7 @@ class MTTypesetter {
glyphDisplay = self.constructGlyph(leftGlyph, withHeight:glyphHeight) glyphDisplay = self.constructGlyph(leftGlyph, withHeight:glyphHeight)
} }
if glyphDisplay != nil { if glyphDisplay == nil {
// Create a glyph display // Create a glyph display
glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: NSMakeRange(NSNotFound, 0), font:styleFont) glyphDisplay = MTGlyphDisplay(withGlpyh: glyph, range: NSMakeRange(NSNotFound, 0), font:styleFont)
glyphDisplay!.ascent = glyphAscent; glyphDisplay!.ascent = glyphAscent;
@@ -1431,7 +1394,7 @@ class MTTypesetter {
return glyphDisplay; return glyphDisplay;
} }
// Mark: Underline/Overline // MARK: - Underline/Overline
func makeUnderline(_ under:MTUnderLine?) -> MTDisplay? { func makeUnderline(_ under:MTUnderLine?) -> MTDisplay? {
let innerListDisplay = MTTypesetter.createLineForMathList(under!.innerList, font:font, style:style, cramped:cramped) let innerListDisplay = MTTypesetter.createLineForMathList(under!.innerList, font:font, style:style, cramped:cramped)
@@ -1456,19 +1419,20 @@ class MTTypesetter {
return overDisplay; return overDisplay;
} }
// Mark: Accents // MARK: - Accents
func isSingleCharAccentee(_ accent:MTAccent?) -> Bool { func isSingleCharAccentee(_ accent:MTAccent?) -> Bool {
if (accent!.innerList!.atoms.count != 1) { guard let accent = accent else { return false }
if accent.innerList!.atoms.count != 1 {
// Not a single char list. // Not a single char list.
return false return false
} }
let innerAtom = accent!.innerList!.atoms[0] let innerAtom = accent.innerList!.atoms[0]
if innerAtom.nucleus.count != 1 { if innerAtom.nucleus.count != 1 {
// A complex atom, not a simple char. // A complex atom, not a simple char.
return false return false
} }
if (innerAtom.subScript != nil || innerAtom.superScript != nil) { if innerAtom.subScript != nil || innerAtom.superScript != nil {
return false return false
} }
return true return true
@@ -1476,22 +1440,23 @@ class MTTypesetter {
// The distance the accent must be moved from the beginning. // The distance the accent must be moved from the beginning.
func getSkew(_ accent: MTAccent?, accenteeWidth width:CGFloat, accentGlyph:CGGlyph) -> CGFloat { func getSkew(_ accent: MTAccent?, accenteeWidth width:CGFloat, accentGlyph:CGGlyph) -> CGFloat {
if accent!.nucleus.isEmpty { guard let accent = accent else { return 0 }
if accent.nucleus.isEmpty {
// No accent // No accent
return 0; return 0
} }
let accentAdjustment = styleFont.mathTable!.getTopAccentAdjustment(accentGlyph) let accentAdjustment = styleFont.mathTable!.getTopAccentAdjustment(accentGlyph)
var accenteeAdjustment = CGFloat(0) var accenteeAdjustment = CGFloat(0)
if !self.isSingleCharAccentee(accent) { if !self.isSingleCharAccentee(accent) {
// use the center of the accentee // use the center of the accentee
accenteeAdjustment = width/2; accenteeAdjustment = width/2
} else { } else {
let innerAtom = accent!.innerList!.atoms[0] let innerAtom = accent.innerList!.atoms[0]
let accenteeGlyph = self.findGlyphForCharacterAtIndex(innerAtom.nucleus.index(innerAtom.nucleus.endIndex, offsetBy:-1), inString:innerAtom.nucleus) let accenteeGlyph = self.findGlyphForCharacterAtIndex(innerAtom.nucleus.index(innerAtom.nucleus.endIndex, offsetBy:-1), inString:innerAtom.nucleus)
accenteeAdjustment = styleFont.mathTable!.getTopAccentAdjustment(accenteeGlyph) accenteeAdjustment = styleFont.mathTable!.getTopAccentAdjustment(accenteeGlyph)
} }
// The adjustments need to aligned, so skew is just the difference. // The adjustments need to aligned, so skew is just the difference.
return (accenteeAdjustment - accentAdjustment); return (accenteeAdjustment - accentAdjustment)
} }
// Find the largest horizontal variant if exists, with width less than max width. // Find the largest horizontal variant if exists, with width less than max width.
@@ -1581,7 +1546,7 @@ class MTTypesetter {
return display; return display;
} }
// Mark: - Table // MARK: - Table
let kBaseLineSkipMultiplier = CGFloat(1.2) // default base line stretch is 12 pt for 10pt font. let kBaseLineSkipMultiplier = CGFloat(1.2) // default base line stretch is 12 pt for 10pt font.
let kLineSkipMultiplier = CGFloat(0.1) // default is 1pt for 10pt font. let kLineSkipMultiplier = CGFloat(0.1) // default is 1pt for 10pt font.
@@ -1599,8 +1564,7 @@ class MTTypesetter {
let displays = self.typesetCells(table, columnWidths:&columnWidths) let displays = self.typesetCells(table, columnWidths:&columnWidths)
// Position all the columns in each row // Position all the columns in each row
var rowDisplays = [MTDisplay]() // NSMutableArray(capacity: table!.cells.count) var rowDisplays = [MTDisplay]()
rowDisplays.reserveCapacity(table!.cells.count)
for row in displays { for row in displays {
let rowDisplay = self.makeRowWithColumns(row, forTable:table, columnWidths:columnWidths) let rowDisplay = self.makeRowWithColumns(row, forTable:table, columnWidths:columnWidths)
rowDisplays.append(rowDisplay!) rowDisplays.append(rowDisplay!)
@@ -1616,16 +1580,14 @@ class MTTypesetter {
// Typeset every cell in the table. As a side-effect calculate the max column width of each column. // Typeset every cell in the table. As a side-effect calculate the max column width of each column.
func typesetCells(_ table:MTMathTable?, columnWidths: inout [CGFloat]) -> [[MTDisplay]] { func typesetCells(_ table:MTMathTable?, columnWidths: inout [CGFloat]) -> [[MTDisplay]] {
var displays = [[MTDisplay]]() var displays = [[MTDisplay]]()
displays.reserveCapacity(table!.numRows)
for row in table!.cells { for row in table!.cells {
var colDisplays = [MTDisplay]() //NSMutableArray(capacity: row.count) var colDisplays = [MTDisplay]()
colDisplays.reserveCapacity(row.count)
displays.append(colDisplays)
for i in 0..<row.count { for i in 0..<row.count {
let disp = MTTypesetter.createLineForMathList(row[i], font:font, style:style) let disp = MTTypesetter.createLineForMathList(row[i], font:font, style:style)
columnWidths[i] = max(disp!.width, columnWidths[i]) columnWidths[i] = max(disp!.width, columnWidths[i])
colDisplays.append(disp!) colDisplays.append(disp!)
} }
displays.append(colDisplays)
} }
return displays return displays
} }

View File

@@ -51,7 +51,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(display.width, line.width); XCTAssertEqual(display.width, line.width);
XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01) XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01)
XCTAssertEqual(display.descent, 0.24, accuracy: 0.01) XCTAssertEqual(display.descent, 0.22, accuracy: 0.01)
XCTAssertEqual(display.width, 11.44, accuracy: 0.01) XCTAssertEqual(display.width, 11.44, accuracy: 0.01)
} }
@@ -81,7 +81,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(display.width, line.width); XCTAssertEqual(display.width, line.width);
XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01) XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.12, accuracy: 0.01) XCTAssertEqual(display.descent, 4.10, accuracy: 0.01)
XCTAssertEqual(display.width, 44.86, accuracy: 0.01) XCTAssertEqual(display.width, 44.86, accuracy: 0.01)
} }
@@ -111,7 +111,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(display.width, line.width); XCTAssertEqual(display.width, line.width);
XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01) XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.12, accuracy: 0.01) XCTAssertEqual(display.descent, 4.10, accuracy: 0.01)
XCTAssertEqual(display.width, 45.56, accuracy: 0.01) XCTAssertEqual(display.width, 45.56, accuracy: 0.01)
} }
@@ -141,11 +141,11 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(display.width, line.width); XCTAssertEqual(display.width, line.width);
XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01) XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.12, accuracy: 0.01) XCTAssertEqual(display.descent, 4.10, accuracy: 0.01)
XCTAssertEqual(display.width, 92.36, accuracy: 0.01) XCTAssertEqual(display.width, 92.36, accuracy: 0.01)
} }
// #define XCTAssertTrue(NSEqualPoints(p1, p2, accuracy, ...) \ // #define XCTAssertTrue(CGPointEqualToPoint(p1, p2, accuracy, ...) \
// XCTAssertEqual(p1.x, p2.x, accuracy, __VA_ARGS__); \ // XCTAssertEqual(p1.x, p2.x, accuracy, __VA_ARGS__); \
// XCTAssertEqual(p1.y, p2.y, accuracy, __VA_ARGS__) // XCTAssertEqual(p1.y, p2.y, accuracy, __VA_ARGS__)
// //
@@ -184,7 +184,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertTrue(sub1 is MTMathListDisplay) XCTAssertTrue(sub1 is MTMathListDisplay)
let display2 = sub1 as! MTMathListDisplay let display2 = sub1 as! MTMathListDisplay
XCTAssertEqual(display2.type, .superscript) XCTAssertEqual(display2.type, .superscript)
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(11.44, 7.26))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(11.44, 7.26)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, 0); XCTAssertEqual(display2.index, 0);
@@ -200,7 +200,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 16.584, accuracy: 0.01) XCTAssertEqual(display.ascent, 16.584, accuracy: 0.01)
XCTAssertEqual(display.descent, 0.24, accuracy: 0.01) XCTAssertEqual(display.descent, 0.22, accuracy: 0.01)
XCTAssertEqual(display.width, 18.44, accuracy: 0.01) XCTAssertEqual(display.width, 18.44, accuracy: 0.01)
} }
@@ -234,7 +234,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertTrue(sub1 is MTMathListDisplay); XCTAssertTrue(sub1 is MTMathListDisplay);
let display2 = sub1 as! MTMathListDisplay let display2 = sub1 as! MTMathListDisplay
XCTAssertEqual(display2.type, .ssubscript); XCTAssertEqual(display2.type, .ssubscript);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(11.44, -4.94))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(11.44, -4.94)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)))
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, 0); XCTAssertEqual(display2.index, 0);
@@ -250,7 +250,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01) XCTAssertEqual(display.ascent, 8.834, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.954, accuracy: 0.01) XCTAssertEqual(display.descent, 4.940, accuracy: 0.01)
XCTAssertEqual(display.width, 18.44, accuracy: 0.01) XCTAssertEqual(display.width, 18.44, accuracy: 0.01)
} }
@@ -287,7 +287,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertTrue(sub1 is MTMathListDisplay); XCTAssertTrue(sub1 is MTMathListDisplay);
let display2 = sub1 as! MTMathListDisplay let display2 = sub1 as! MTMathListDisplay
XCTAssertEqual(display2.type, .superscript); XCTAssertEqual(display2.type, .superscript);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(11.44, 7.26))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(11.44, 7.26)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, 0); XCTAssertEqual(display2.index, 0);
@@ -306,7 +306,7 @@ final class MTTypesetterTests: XCTestCase {
let display3 = sub2 as! MTMathListDisplay let display3 = sub2 as! MTMathListDisplay
XCTAssertEqual(display3.type, .ssubscript); XCTAssertEqual(display3.type, .ssubscript);
// Positioned differently when both subscript and superscript present. // Positioned differently when both subscript and superscript present.
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(11.44, -5.278))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(11.44, -5.264)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)))
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, 0); XCTAssertEqual(display3.index, 0);
@@ -322,7 +322,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 16.584, accuracy: 0.01) XCTAssertEqual(display.ascent, 16.584, accuracy: 0.01)
XCTAssertEqual(display.descent, 5.292, accuracy: 0.01) XCTAssertEqual(display.descent, 5.264, accuracy: 0.01)
XCTAssertEqual(display.width, 18.44, accuracy: 0.01) XCTAssertEqual(display.width, 18.44, accuracy: 0.01)
} }
@@ -354,7 +354,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = radical.radicand! let display2 = radical.radicand!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(16.66, 0))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(16.66, 0)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -371,7 +371,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 19.34, accuracy: 0.01) XCTAssertEqual(display.ascent, 19.34, accuracy: 0.01)
XCTAssertEqual(display.descent, 1.48, accuracy: 0.01) XCTAssertEqual(display.descent, 1.46, accuracy: 0.01)
XCTAssertEqual(display.width, 26.66, accuracy: 0.01) XCTAssertEqual(display.width, 26.66, accuracy: 0.01)
} }
@@ -406,7 +406,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = radical.radicand! let display2 = radical.radicand!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(16.66, 0))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(16.66, 0)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -423,7 +423,7 @@ final class MTTypesetterTests: XCTestCase {
let display3 = radical.degree! let display3 = radical.degree!
XCTAssertEqual(display3.type, .regular); XCTAssertEqual(display3.type, .regular);
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(6.12, 10.716))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(6.12, 10.728)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)));
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, NSNotFound); XCTAssertEqual(display3.index, NSNotFound);
@@ -440,7 +440,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 19.34, accuracy: 0.01) XCTAssertEqual(display.ascent, 19.34, accuracy: 0.01)
XCTAssertEqual(display.descent, 1.48, accuracy: 0.01) XCTAssertEqual(display.descent, 1.46, accuracy: 0.01)
XCTAssertEqual(display.width, 26.66, accuracy: 0.01) XCTAssertEqual(display.width, 26.66, accuracy: 0.01)
} }
@@ -475,7 +475,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = fraction.numerator! let display2 = fraction.numerator!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(0, 13.54))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(0, 13.54)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -492,7 +492,7 @@ final class MTTypesetterTests: XCTestCase {
let display3 = fraction.denominator! let display3 = fraction.denominator!
XCTAssertEqual(display3.type, .regular); XCTAssertEqual(display3.type, .regular);
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(0, -13.72))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(0, -13.72)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)));
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, NSNotFound); XCTAssertEqual(display3.index, NSNotFound);
@@ -509,7 +509,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 26.86, accuracy: 0.01) XCTAssertEqual(display.ascent, 26.86, accuracy: 0.01)
XCTAssertEqual(display.descent, 14.18, accuracy: 0.01) XCTAssertEqual(display.descent, 14.16, accuracy: 0.01)
XCTAssertEqual(display.width, 10, accuracy: 0.01) XCTAssertEqual(display.width, 10, accuracy: 0.01)
} }
@@ -544,7 +544,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = fraction.numerator! let display2 = fraction.numerator!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(0, 13.54))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(0, 13.54)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -561,7 +561,7 @@ final class MTTypesetterTests: XCTestCase {
let display3 = fraction.denominator! let display3 = fraction.denominator!
XCTAssertEqual(display3.type, .regular); XCTAssertEqual(display3.type, .regular);
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(0, -13.72))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(0, -13.72)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)));
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, NSNotFound); XCTAssertEqual(display3.index, NSNotFound);
@@ -578,7 +578,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 26.86, accuracy: 0.01) XCTAssertEqual(display.ascent, 26.86, accuracy: 0.01)
XCTAssertEqual(display.descent, 14.18, accuracy: 0.01) XCTAssertEqual(display.descent, 14.16, accuracy: 0.01)
XCTAssertEqual(display.width, 10, accuracy: 0.01) XCTAssertEqual(display.width, 10, accuracy: 0.01)
} }
@@ -627,13 +627,13 @@ final class MTTypesetterTests: XCTestCase {
let fraction = subFrac as! MTFractionDisplay let fraction = subFrac as! MTFractionDisplay
XCTAssertTrue(NSEqualRanges(fraction.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(fraction.range, NSMakeRange(0, 1)));
XCTAssertFalse(fraction.hasScript); XCTAssertFalse(fraction.hasScript);
XCTAssertTrue(NSEqualPoints(fraction.position, CGPointMake(14.72, 0))) XCTAssertTrue(CGPointEqualToPoint(fraction.position, CGPointMake(14.72, 0)))
XCTAssertNotNil(fraction.numerator); XCTAssertNotNil(fraction.numerator);
XCTAssertNotNil(fraction.denominator); XCTAssertNotNil(fraction.denominator);
let display2 = fraction.numerator! let display2 = fraction.numerator!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(14.72, 13.54))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(14.72, 13.54)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -650,7 +650,7 @@ final class MTTypesetterTests: XCTestCase {
let display3 = fraction.denominator! let display3 = fraction.denominator!
XCTAssertEqual(display3.type, .regular); XCTAssertEqual(display3.type, .regular);
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(14.72, -13.72))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(14.72, -13.72)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)));
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, NSNotFound); XCTAssertEqual(display3.index, NSNotFound);
@@ -668,13 +668,13 @@ final class MTTypesetterTests: XCTestCase {
let subRight = display0.subDisplays[2]; let subRight = display0.subDisplays[2];
XCTAssertTrue(subRight is MTGlyphDisplay); XCTAssertTrue(subRight is MTGlyphDisplay);
let glyph2 = subRight as! MTGlyphDisplay let glyph2 = subRight as! MTGlyphDisplay
XCTAssertTrue(NSEqualPoints(glyph2.position, CGPointMake(24.72, 0))) XCTAssertTrue(CGPointEqualToPoint(glyph2.position, CGPointMake(24.72, 0)))
XCTAssertTrue(NSEqualRanges(glyph2.range, NSMakeRange(NSNotFound, 0)), "Got \(glyph2.range) instead") XCTAssertTrue(NSEqualRanges(glyph2.range, NSMakeRange(NSNotFound, 0)), "Got \(glyph2.range) instead")
XCTAssertFalse(glyph2.hasScript); XCTAssertFalse(glyph2.hasScript);
// dimensions // dimensions
XCTAssertEqual(display.ascent, 28.93, accuracy: 0.001); XCTAssertEqual(display.ascent, 28.92, accuracy: 0.001);
XCTAssertEqual(display.descent, 18.93, accuracy: 0.001); XCTAssertEqual(display.descent, 18.92, accuracy: 0.001);
XCTAssertEqual(display.width, 39.44, accuracy: 0.001); XCTAssertEqual(display.width, 39.44, accuracy: 0.001);
} }
@@ -706,12 +706,12 @@ final class MTTypesetterTests: XCTestCase {
let line2 = sub1 as! MTCTLineDisplay let line2 = sub1 as! MTCTLineDisplay
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
XCTAssertEqual(line2.attributedString?.string, "𝑥"); XCTAssertEqual(line2.attributedString?.string, "𝑥");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(27.893, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(27.893, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
XCTAssertEqual(display.ascent, 13.14, accuracy: 0.01) XCTAssertEqual(display.ascent, 13.14, accuracy: 0.01)
XCTAssertEqual(display.descent, 0.24, accuracy: 0.01) XCTAssertEqual(display.descent, 0.22, accuracy: 0.01)
XCTAssertEqual(display.width, 39.33, accuracy: 0.01) XCTAssertEqual(display.width, 39.33, accuracy: 0.01)
} }
@@ -742,12 +742,12 @@ final class MTTypesetterTests: XCTestCase {
let line2 = sub1 as! MTCTLineDisplay let line2 = sub1 as! MTCTLineDisplay
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
XCTAssertEqual(line2.attributedString?.string, "𝑥"); XCTAssertEqual(line2.attributedString?.string, "𝑥");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(23.313, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(23.313, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
XCTAssertEqual(display.ascent, 27.23, accuracy: 0.01) XCTAssertEqual(display.ascent, 27.22, accuracy: 0.01)
XCTAssertEqual(display.descent, 17.23, accuracy: 0.01) XCTAssertEqual(display.descent, 17.22, accuracy: 0.01)
XCTAssertEqual(display.width, 34.753, accuracy: 0.01) XCTAssertEqual(display.width, 34.753, accuracy: 0.01)
} }
@@ -775,7 +775,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertTrue(sub0 is MTMathListDisplay); XCTAssertTrue(sub0 is MTMathListDisplay);
let display0 = sub0 as! MTMathListDisplay let display0 = sub0 as! MTMathListDisplay
XCTAssertEqual(display0.type, .superscript); XCTAssertEqual(display0.type, .superscript);
XCTAssertTrue(NSEqualPoints(display0.position, CGPointMake(19.98, 23.73))) XCTAssertTrue(CGPointEqualToPoint(display0.position, CGPointMake(19.98, 23.72)))
XCTAssertTrue(NSEqualRanges(display0.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display0.range, NSMakeRange(0, 1)))
XCTAssertFalse(display0.hasScript); XCTAssertFalse(display0.hasScript);
XCTAssertEqual(display0.index, 0); XCTAssertEqual(display0.index, 0);
@@ -794,7 +794,7 @@ final class MTTypesetterTests: XCTestCase {
let display1 = sub1 as! MTMathListDisplay let display1 = sub1 as! MTMathListDisplay
XCTAssertEqual(display1.type, .ssubscript); XCTAssertEqual(display1.type, .ssubscript);
// Due to italic correction, positioned before subscript. // Due to italic correction, positioned before subscript.
XCTAssertTrue(NSEqualPoints(display1.position, CGPointMake(8.16, -20.03))) XCTAssertTrue(CGPointEqualToPoint(display1.position, CGPointMake(8.16, -20.02)))
XCTAssertTrue(NSEqualRanges(display1.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display1.range, NSMakeRange(0, 1)))
XCTAssertFalse(display1.hasScript); XCTAssertFalse(display1.hasScript);
XCTAssertEqual(display1.index, 0); XCTAssertEqual(display1.index, 0);
@@ -820,12 +820,12 @@ final class MTTypesetterTests: XCTestCase {
let line2 = sub3 as! MTCTLineDisplay let line2 = sub3 as! MTCTLineDisplay
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
XCTAssertEqual(line2.attributedString?.string, "𝑥"); XCTAssertEqual(line2.attributedString?.string, "𝑥");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(31.433, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(31.433, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line1.hasScript); XCTAssertFalse(line1.hasScript);
XCTAssertEqual(display.ascent, 33.054, accuracy: 0.001); XCTAssertEqual(display.ascent, 33.044, accuracy: 0.001);
XCTAssertEqual(display.descent, 20.352, accuracy: 0.001); XCTAssertEqual(display.descent, 20.328, accuracy: 0.001);
XCTAssertEqual(display.width, 42.873, accuracy: 0.001); XCTAssertEqual(display.width, 42.873, accuracy: 0.001);
} }
@@ -858,7 +858,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = largeOp.lowerLimit! let display2 = largeOp.lowerLimit!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(6.89, -12.02))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(6.89, -12.09)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -877,12 +877,12 @@ final class MTTypesetterTests: XCTestCase {
let line2 = sub3 as! MTCTLineDisplay let line2 = sub3 as! MTCTLineDisplay
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
XCTAssertEqual(line2.attributedString?.string, "𝑥"); XCTAssertEqual(line2.attributedString?.string, "𝑥");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(31.1133, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(31.1133, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line1.hasScript); XCTAssertFalse(line1.hasScript);
XCTAssertEqual(display.ascent, 13.88, accuracy: 0.01) XCTAssertEqual(display.ascent, 13.88, accuracy: 0.01)
XCTAssertEqual(display.descent, 12.188, accuracy: 0.01) XCTAssertEqual(display.descent, 12.154, accuracy: 0.01)
XCTAssertEqual(display.width, 42.553, accuracy: 0.01) XCTAssertEqual(display.width, 42.553, accuracy: 0.01)
} }
@@ -916,7 +916,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = largeOp.lowerLimit! let display2 = largeOp.lowerLimit!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointMake(10.94, -21.674))) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointMake(10.94, -21.664)))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)))
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -932,7 +932,7 @@ final class MTTypesetterTests: XCTestCase {
let displayU = largeOp.upperLimit! let displayU = largeOp.upperLimit!
XCTAssertEqual(displayU.type, .regular); XCTAssertEqual(displayU.type, .regular);
XCTAssertTrue(NSEqualPoints(displayU.position, CGPointMake(7.44, 23.178))) XCTAssertTrue(CGPointEqualToPoint(displayU.position, CGPointMake(7.44, 23.154)))
XCTAssertTrue(NSEqualRanges(displayU.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(displayU.range, NSMakeRange(0, 1)))
XCTAssertFalse(displayU.hasScript); XCTAssertFalse(displayU.hasScript);
XCTAssertEqual(displayU.index, NSNotFound); XCTAssertEqual(displayU.index, NSNotFound);
@@ -951,12 +951,12 @@ final class MTTypesetterTests: XCTestCase {
let line2 = sub3 as! MTCTLineDisplay let line2 = sub3 as! MTCTLineDisplay
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
XCTAssertEqual(line2.attributedString?.string, "𝑥"); XCTAssertEqual(line2.attributedString?.string, "𝑥");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(32.2133, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(32.2133, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(1, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
XCTAssertEqual(display.ascent, 29.366, accuracy: 0.001); XCTAssertEqual(display.ascent, 29.342, accuracy: 0.001);
XCTAssertEqual(display.descent, 21.996, accuracy: 0.001); XCTAssertEqual(display.descent, 21.972, accuracy: 0.001);
XCTAssertEqual(display.width, 43.653, accuracy: 0.001); XCTAssertEqual(display.width, 43.653, accuracy: 0.001);
} }
@@ -1001,7 +1001,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertTrue(sub3 is MTMathListDisplay); XCTAssertTrue(sub3 is MTMathListDisplay);
let display3 = sub3 as! MTMathListDisplay let display3 = sub3 as! MTMathListDisplay
XCTAssertEqual(display3.type, .regular); XCTAssertEqual(display3.type, .regular);
XCTAssertTrue(NSEqualPoints(display3.position, CGPointMake(7.78, 0))) XCTAssertTrue(CGPointEqualToPoint(display3.position, CGPointMake(7.78, 0)))
XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display3.range, NSMakeRange(0, 1)));
XCTAssertFalse(display3.hasScript); XCTAssertFalse(display3.hasScript);
XCTAssertEqual(display3.index, NSNotFound); XCTAssertEqual(display3.index, NSNotFound);
@@ -1019,7 +1019,7 @@ final class MTTypesetterTests: XCTestCase {
let subRight = display2.subDisplays[2]; let subRight = display2.subDisplays[2];
XCTAssertTrue(subRight is MTGlyphDisplay); XCTAssertTrue(subRight is MTGlyphDisplay);
let glyph2 = subRight as! MTGlyphDisplay let glyph2 = subRight as! MTGlyphDisplay
XCTAssertTrue(NSEqualPoints(glyph2.position, CGPointMake(19.22, 0))) XCTAssertTrue(CGPointEqualToPoint(glyph2.position, CGPointMake(19.22, 0)))
XCTAssertTrue(NSEqualRanges(glyph2.range, NSMakeRange(NSNotFound, 0)), "Got \(glyph2.range) instead"); XCTAssertTrue(NSEqualRanges(glyph2.range, NSMakeRange(NSNotFound, 0)), "Got \(glyph2.range) instead");
XCTAssertFalse(glyph2.hasScript); XCTAssertFalse(glyph2.hasScript);
@@ -1028,8 +1028,8 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(display.descent, display2.descent); XCTAssertEqual(display.descent, display2.descent);
XCTAssertEqual(display.width, display2.width); XCTAssertEqual(display.width, display2.width);
XCTAssertEqual(display.ascent, 14.97, accuracy: 0.001); XCTAssertEqual(display.ascent, 14.96, accuracy: 0.001);
XCTAssertEqual(display.descent, 4.97, accuracy: 0.001); XCTAssertEqual(display.descent, 4.96, accuracy: 0.001);
XCTAssertEqual(display.width, 27, accuracy: 0.01) XCTAssertEqual(display.width, 27, accuracy: 0.01)
} }
@@ -1060,7 +1060,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = overline.inner! let display2 = overline.inner!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -1077,7 +1077,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 17.32, accuracy: 0.01) XCTAssertEqual(display.ascent, 17.32, accuracy: 0.01)
XCTAssertEqual(display.descent, 0.02, accuracy: 0.01) XCTAssertEqual(display.descent, 0.00, accuracy: 0.01)
XCTAssertEqual(display.width, 10, accuracy: 0.01) XCTAssertEqual(display.width, 10, accuracy: 0.01)
} }
@@ -1108,7 +1108,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = underline.inner! let display2 = underline.inner!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -1125,7 +1125,7 @@ final class MTTypesetterTests: XCTestCase {
// dimensions // dimensions
XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01) XCTAssertEqual(display.ascent, 13.32, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.02, accuracy: 0.01) XCTAssertEqual(display.descent, 4.00, accuracy: 0.01)
XCTAssertEqual(display.width, 10, accuracy: 0.01) XCTAssertEqual(display.width, 10, accuracy: 0.01)
} }
@@ -1160,7 +1160,7 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertEqual(line2.atoms.count, 1); XCTAssertEqual(line2.atoms.count, 1);
// The x is italicized // The x is italicized
XCTAssertEqual(line2.attributedString?.string, "𝑦"); XCTAssertEqual(line2.attributedString?.string, "𝑦");
XCTAssertTrue(NSEqualPoints(line2.position, CGPointMake(21.44, 0))) XCTAssertTrue(CGPointEqualToPoint(line2.position, CGPointMake(21.44, 0)))
XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(2, 1)), "Got \(line2.range) instead") XCTAssertTrue(NSEqualRanges(line2.range, NSMakeRange(2, 1)), "Got \(line2.range) instead")
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
@@ -1182,8 +1182,8 @@ final class MTTypesetterTests: XCTestCase {
let display = MTTypesetter.createLineForMathList(list, font:self.font, style:.display)! let display = MTTypesetter.createLineForMathList(list, font:self.font, style:.display)!
// dimensions // dimensions
XCTAssertEqual(display.ascent, 49.18, accuracy: 0.01) XCTAssertEqual(display.ascent, 49.16, accuracy: 0.01)
XCTAssertEqual(display.descent, 21.308, accuracy: 0.01) XCTAssertEqual(display.descent, 21.288, accuracy: 0.01)
XCTAssertEqual(display.width, 82.569, accuracy: 0.01) XCTAssertEqual(display.width, 82.569, accuracy: 0.01)
} }
@@ -1231,12 +1231,12 @@ final class MTTypesetterTests: XCTestCase {
let display2 = sub0 as! MTMathListDisplay let display2 = sub0 as! MTMathListDisplay
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)))
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
XCTAssertEqual(display2.subDisplays.count, 3); XCTAssertEqual(display2.subDisplays.count, 3);
let rowPos = [ 30.31, -2.67, -31.95 ] let rowPos = [ 30.28, -2.68, -31.95 ]
// alignment is right, center, left. // alignment is right, center, left.
let cellPos = [ [ 35.89, 65.89, 129.438 ], [ 45.89, 76.94, 129.438 ], [ 0, 87.66, 129.438] ] let cellPos = [ [ 35.89, 65.89, 129.438 ], [ 45.89, 76.94, 129.438 ], [ 0, 87.66, 129.438] ]
// check the 3 rows of the matrix // check the 3 rows of the matrix
@@ -1246,7 +1246,7 @@ final class MTTypesetterTests: XCTestCase {
let row = sub0i as! MTMathListDisplay let row = sub0i as! MTMathListDisplay
XCTAssertEqual(row.type, .regular) XCTAssertEqual(row.type, .regular)
XCTAssertTrue(NSEqualPoints(row.position, CGPointMake(0, rowPos[i]))) XCTAssertTrue(CGPointEqualToPoint(row.position, CGPointMake(0, rowPos[i])))
XCTAssertTrue(NSEqualRanges(row.range, NSMakeRange(0, 3))); XCTAssertTrue(NSEqualRanges(row.range, NSMakeRange(0, 3)));
XCTAssertFalse(row.hasScript); XCTAssertFalse(row.hasScript);
XCTAssertEqual(row.index, NSNotFound); XCTAssertEqual(row.index, NSNotFound);
@@ -1258,7 +1258,7 @@ final class MTTypesetterTests: XCTestCase {
let col = sub0ij as! MTMathListDisplay let col = sub0ij as! MTMathListDisplay
XCTAssertEqual(col.type, .regular); XCTAssertEqual(col.type, .regular);
XCTAssertTrue(NSEqualPoints(col.position, CGPointMake(cellPos[i][j], 0))) XCTAssertTrue(CGPointEqualToPoint(col.position, CGPointMake(cellPos[i][j], 0)))
XCTAssertFalse(col.hasScript) XCTAssertFalse(col.hasScript)
XCTAssertEqual(col.index, NSNotFound); XCTAssertEqual(col.index, NSNotFound);
} }
@@ -1294,7 +1294,7 @@ final class MTTypesetterTests: XCTestCase {
// These large operators are rendered differently; // These large operators are rendered differently;
XCTAssertTrue(sub0 is MTGlyphDisplay); XCTAssertTrue(sub0 is MTGlyphDisplay);
let glyph = sub0 as! MTGlyphDisplay let glyph = sub0 as! MTGlyphDisplay
XCTAssertTrue(NSEqualPoints(glyph.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(glyph.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1)))
XCTAssertFalse(glyph.hasScript); XCTAssertFalse(glyph.hasScript);
} else { } else {
@@ -1395,9 +1395,9 @@ final class MTTypesetterTests: XCTestCase {
func testStyleChanges() throws { func testStyleChanges() throws {
let frac = MTMathAtomFactory.fraction(withNumeratorString: "1", denominatorString: "2") let frac = MTMathAtomFactory.fraction(withNumeratorString: "1", denominatorString: "2")
let list = MTMathList(atom: frac) let list = MTMathList(atoms: [frac])
// let style = MTMathStyle(style: .text) let style = MTMathStyle(style: .text)
let textList = MTMathList(atom: frac) let textList = MTMathList(atoms: [style, frac])
// This should make the display same as text. // This should make the display same as text.
let display = MTTypesetter.createLineForMathList(textList, font:self.font, style:.display)! let display = MTTypesetter.createLineForMathList(textList, font:self.font, style:.display)!
@@ -1486,7 +1486,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = accentDisp.accentee! let display2 = accentDisp.accentee!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 1)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -1502,13 +1502,13 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
let glyph = accentDisp.accent! let glyph = accentDisp.accent!
XCTAssertTrue(NSEqualPoints(glyph.position, CGPointMake(11.86, 0))) XCTAssertTrue(CGPointEqualToPoint(glyph.position, CGPointMake(11.86, 0)))
XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1)))
XCTAssertFalse(glyph.hasScript); XCTAssertFalse(glyph.hasScript);
// dimensions // dimensions
XCTAssertEqual(display.ascent, 14.68, accuracy: 0.01) XCTAssertEqual(display.ascent, 14.68, accuracy: 0.01)
XCTAssertEqual(display.descent, 0.24, accuracy: 0.01) XCTAssertEqual(display.descent, 0.22, accuracy: 0.01)
XCTAssertEqual(display.width, 11.44, accuracy: 0.01) XCTAssertEqual(display.width, 11.44, accuracy: 0.01)
} }
@@ -1538,7 +1538,7 @@ final class MTTypesetterTests: XCTestCase {
let display2 = accentDisp.accentee! let display2 = accentDisp.accentee!
XCTAssertEqual(display2.type, .regular); XCTAssertEqual(display2.type, .regular);
XCTAssertTrue(NSEqualPoints(display2.position, CGPointZero)) XCTAssertTrue(CGPointEqualToPoint(display2.position, CGPointZero))
XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 4))); XCTAssertTrue(NSEqualRanges(display2.range, NSMakeRange(0, 4)));
XCTAssertFalse(display2.hasScript); XCTAssertFalse(display2.hasScript);
XCTAssertEqual(display2.index, NSNotFound); XCTAssertEqual(display2.index, NSNotFound);
@@ -1554,13 +1554,13 @@ final class MTTypesetterTests: XCTestCase {
XCTAssertFalse(line2.hasScript); XCTAssertFalse(line2.hasScript);
let glyph = accentDisp.accent! let glyph = accentDisp.accent!
XCTAssertTrue(NSEqualPoints(glyph.position, CGPointMake(3.47, 0))) XCTAssertTrue(CGPointEqualToPoint(glyph.position, CGPointMake(3.47, 0)))
XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1))) XCTAssertTrue(NSEqualRanges(glyph.range, NSMakeRange(0, 1)))
XCTAssertFalse(glyph.hasScript); XCTAssertFalse(glyph.hasScript);
// dimensions // dimensions
XCTAssertEqual(display.ascent, 14.98, accuracy: 0.01) XCTAssertEqual(display.ascent, 14.98, accuracy: 0.01)
XCTAssertEqual(display.descent, 4.12, accuracy: 0.01) XCTAssertEqual(display.descent, 4.10, accuracy: 0.01)
XCTAssertEqual(display.width, 44.86, accuracy: 0.01) XCTAssertEqual(display.width, 44.86, accuracy: 0.01)
} }