Passing all internal tests.
This commit is contained in:
@@ -146,19 +146,25 @@ class MTCTLineDisplay : MTDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
// func set(attrString: NSAttributedString?) {
|
||||
// attributedString = attrString
|
||||
// line = CTLineCreateWithAttributedString(attributedString!)
|
||||
// }
|
||||
|
||||
func set(textColor:MTColor) {
|
||||
self.textColor = textColor
|
||||
let attrStr = NSMutableAttributedString(attributedString: self.attributedString!)
|
||||
let foregroundColor = NSAttributedString.Key(kCTForegroundColorAttributeName as String)
|
||||
attrStr.addAttribute(foregroundColor, value:self.textColor!.cgColor, range:NSMakeRange(0, attrStr.length))
|
||||
self.attributedString = attrStr
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
let attrStr = NSMutableAttributedString(attributedString: self.attributedString!)
|
||||
let foregroundColor = NSAttributedString.Key(kCTForegroundColorAttributeName as String)
|
||||
attrStr.addAttribute(foregroundColor, value:self.textColor!.cgColor, range:NSMakeRange(0, attrStr.length))
|
||||
self.attributedString = attrStr
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
// func set(textColor:MTColor) {
|
||||
// self.textColor = textColor
|
||||
// let attrStr = NSMutableAttributedString(attributedString: self.attributedString!)
|
||||
// let foregroundColor = NSAttributedString.Key(kCTForegroundColorAttributeName as String)
|
||||
// attrStr.addAttribute(foregroundColor, value:self.textColor!.cgColor, range:NSMakeRange(0, attrStr.length))
|
||||
// self.attributedString = attrStr
|
||||
// }
|
||||
|
||||
func computeDimensions(_ font:MTFont?) {
|
||||
let runs = CTLineGetGlyphRuns(line) as NSArray
|
||||
for obj in runs {
|
||||
@@ -229,20 +235,30 @@ class MTMathListDisplay : MTDisplay {
|
||||
self.recomputeDimensions()
|
||||
}
|
||||
|
||||
func setType(_ type:LinePosition) {
|
||||
self.type = type
|
||||
}
|
||||
// func setType(_ type:LinePosition) {
|
||||
// self.type = type
|
||||
// }
|
||||
//
|
||||
// func setIndex(_ index:Int) {
|
||||
// self.index = index
|
||||
// }
|
||||
|
||||
func setIndex(_ index:Int) {
|
||||
self.index = index
|
||||
}
|
||||
|
||||
func setTextColor(_ textColor:MTColor) {
|
||||
// Set the color on all subdisplays
|
||||
self.textColor = textColor
|
||||
for displayAtom in self.subDisplays {
|
||||
displayAtom.textColor = textColor
|
||||
// func setTextColor(_ textColor:MTColor) {
|
||||
// // Set the color on all subdisplays
|
||||
// self.textColor = textColor
|
||||
// for displayAtom in self.subDisplays {
|
||||
// displayAtom.textColor = textColor
|
||||
// }
|
||||
// }
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
for displayAtom in self.subDisplays {
|
||||
displayAtom.textColor = newValue
|
||||
}
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
func draw(context: CGContext) {
|
||||
@@ -341,16 +357,22 @@ class MTFractionDisplay : MTDisplay {
|
||||
numerator?.position = CGPointMake(self.position.x + (self.width - numerator!.width)/2, self.position.y + self.numeratorUp)
|
||||
}
|
||||
|
||||
func setPosition(_ position: CGPoint) {
|
||||
super.position = position
|
||||
self.updateDenominatorPosition()
|
||||
self.updateNumeratorPosition()
|
||||
override var position: CGPoint {
|
||||
set {
|
||||
super.position = newValue
|
||||
self.updateDenominatorPosition()
|
||||
self.updateNumeratorPosition()
|
||||
}
|
||||
get { super.position }
|
||||
}
|
||||
|
||||
func setTextColor(_ textColor:MTColor) {
|
||||
super.textColor = textColor
|
||||
numerator?.textColor = textColor
|
||||
denominator?.textColor = textColor
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
numerator?.textColor = newValue
|
||||
denominator?.textColor = newValue
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
override func draw(_ context:CGContext) {
|
||||
@@ -387,6 +409,23 @@ class MTRadicalDisplay : MTDisplay {
|
||||
*/
|
||||
var degree:MTMathListDisplay?
|
||||
|
||||
override var position: CGPoint {
|
||||
set {
|
||||
super.position = newValue
|
||||
self.updateRadicandPosition()
|
||||
}
|
||||
get { super.position }
|
||||
}
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
self.radicand!.textColor = newValue
|
||||
self.degree!.textColor = newValue
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
private var _radicalGlyph:MTDisplay?
|
||||
private var _radicalShift:CGFloat=0
|
||||
|
||||
@@ -430,10 +469,10 @@ class MTRadicalDisplay : MTDisplay {
|
||||
self.updateRadicandPosition()
|
||||
}
|
||||
|
||||
func setPosition(_ position:CGPoint) {
|
||||
super.position = position
|
||||
self.updateRadicandPosition()
|
||||
}
|
||||
// func setPosition(_ position:CGPoint) {
|
||||
// super.position = position
|
||||
// self.updateRadicandPosition()
|
||||
// }
|
||||
|
||||
func updateRadicandPosition() {
|
||||
// The position of the radicand includes the position of the MTRadicalDisplay
|
||||
@@ -443,11 +482,11 @@ class MTRadicalDisplay : MTDisplay {
|
||||
self.radicand!.position = CGPointMake(self.position.x + _radicalShift + _radicalGlyph!.width, self.position.y);
|
||||
}
|
||||
|
||||
func setTextColor(textColor:MTColor) {
|
||||
super.textColor = textColor
|
||||
self.radicand!.textColor = textColor
|
||||
self.degree!.textColor = textColor
|
||||
}
|
||||
// func setTextColor(textColor:MTColor) {
|
||||
// super.textColor = textColor
|
||||
// self.radicand!.textColor = textColor
|
||||
// self.degree!.textColor = textColor
|
||||
// }
|
||||
|
||||
func draw(context: CGContext) {
|
||||
// draw the radicand & degree at its position
|
||||
@@ -662,14 +701,23 @@ class MTLargeOpLimitsDisplay : MTDisplay {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setPosition(_ position:CGPoint) {
|
||||
super.position = position;
|
||||
self.updateLowerLimitPosition()
|
||||
self.updateUpperLimitPosition()
|
||||
self.updateNucleusPosition()
|
||||
|
||||
override var position: CGPoint {
|
||||
set {
|
||||
self.updateLowerLimitPosition()
|
||||
self.updateUpperLimitPosition()
|
||||
self.updateNucleusPosition()
|
||||
}
|
||||
get { super.position }
|
||||
}
|
||||
|
||||
// func setPosition(_ position:CGPoint) {
|
||||
// super.position = position;
|
||||
// self.updateLowerLimitPosition()
|
||||
// self.updateUpperLimitPosition()
|
||||
// self.updateNucleusPosition()
|
||||
// }
|
||||
|
||||
func updateLowerLimitPosition() {
|
||||
if self.lowerLimit != nil {
|
||||
// The position of the lower limit includes the position of the MTLargeOpLimitsDisplay
|
||||
@@ -696,14 +744,24 @@ class MTLargeOpLimitsDisplay : MTDisplay {
|
||||
// Center the nucleus
|
||||
nucleus?.position = CGPointMake(self.position.x + (self.width - nucleus!.width)/2, self.position.y);
|
||||
}
|
||||
|
||||
func setTextColor(_ textColor:MTColor) {
|
||||
super.textColor = textColor
|
||||
self.upperLimit?.textColor = textColor
|
||||
self.lowerLimit?.textColor = textColor
|
||||
nucleus?.textColor = textColor
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
self.upperLimit?.textColor = newValue
|
||||
self.lowerLimit?.textColor = newValue
|
||||
nucleus?.textColor = newValue
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
// func setTextColor(_ textColor:MTColor) {
|
||||
// super.textColor = textColor
|
||||
// self.upperLimit?.textColor = textColor
|
||||
// self.lowerLimit?.textColor = textColor
|
||||
// nucleus?.textColor = textColor
|
||||
// }
|
||||
|
||||
override func draw(_ context:CGContext) {
|
||||
// Draw the elements.
|
||||
self.upperLimit?.draw(context)
|
||||
@@ -732,11 +790,27 @@ class MTLineDisplay : MTDisplay {
|
||||
self.position = position;
|
||||
self.range = range;
|
||||
}
|
||||
|
||||
func setTextColor(_ textColor:MTColor) {
|
||||
super.textColor = textColor
|
||||
inner?.textColor = textColor
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
inner?.textColor = newValue
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
override var position: CGPoint {
|
||||
set {
|
||||
super.position = newValue
|
||||
self.updateInnerPosition()
|
||||
}
|
||||
get { super.position }
|
||||
}
|
||||
|
||||
// func setTextColor(_ textColor:MTColor) {
|
||||
// super.textColor = textColor
|
||||
// inner?.textColor = textColor
|
||||
// }
|
||||
|
||||
override func draw(_ context:CGContext) {
|
||||
self.inner?.draw(context)
|
||||
@@ -757,10 +831,10 @@ class MTLineDisplay : MTDisplay {
|
||||
context.restoreGState();
|
||||
}
|
||||
|
||||
func setPosition(_ position:CGPoint) {
|
||||
super.position = position;
|
||||
self.updateInnerPosition()
|
||||
}
|
||||
// func setPosition(_ position:CGPoint) {
|
||||
// super.position = position;
|
||||
// self.updateInnerPosition()
|
||||
// }
|
||||
|
||||
func updateInnerPosition() {
|
||||
self.inner?.position = CGPointMake(self.position.x, self.position.y);
|
||||
@@ -789,16 +863,33 @@ class MTAccentDisplay : MTDisplay {
|
||||
self.accentee?.position = CGPoint.zero
|
||||
self.range = range
|
||||
}
|
||||
|
||||
func setTextColor(_ textColor:MTColor) {
|
||||
super.textColor = textColor
|
||||
accentee?.textColor = textColor
|
||||
accent?.textColor = textColor
|
||||
|
||||
override var textColor: MTColor? {
|
||||
set {
|
||||
super.textColor = newValue
|
||||
accentee?.textColor = newValue
|
||||
accent?.textColor = newValue
|
||||
}
|
||||
get { super.textColor }
|
||||
}
|
||||
|
||||
func setPosition(_ position:CGPoint) {
|
||||
super.position = position
|
||||
self.updateAccenteePosition()
|
||||
// func setTextColor(_ textColor:MTColor) {
|
||||
// super.textColor = textColor
|
||||
// accentee?.textColor = textColor
|
||||
// accent?.textColor = textColor
|
||||
// }
|
||||
|
||||
// func setPosition(_ position:CGPoint) {
|
||||
// super.position = position
|
||||
// self.updateAccenteePosition()
|
||||
// }
|
||||
|
||||
override var position: CGPoint {
|
||||
set {
|
||||
super.position = newValue
|
||||
self.updateAccenteePosition()
|
||||
}
|
||||
get { super.position }
|
||||
}
|
||||
|
||||
func updateAccenteePosition() {
|
||||
|
||||
@@ -1079,40 +1079,39 @@ class MTTypesetter {
|
||||
}
|
||||
|
||||
func makeRadical(_ radicand:MTMathList?, range:NSRange) -> MTRadicalDisplay? {
|
||||
let innerDisplay = MTTypesetter.createLineForMathList(radicand, font:font, style:style, cramped:true)
|
||||
var clearance : CGFloat = self.radicalVerticalGap()
|
||||
let radicalRuleThickness : CGFloat = styleFont.mathTable!.radicalRuleThickness
|
||||
let radicalHeight = innerDisplay!.ascent + innerDisplay!.descent + clearance + radicalRuleThickness;
|
||||
|
||||
let glyph = self.getRadicalGlyphWithHeight(radicalHeight)
|
||||
let innerDisplay = MTTypesetter.createLineForMathList(radicand, font:font, style:style, cramped:true)!
|
||||
var clearance = self.radicalVerticalGap()
|
||||
let radicalRuleThickness = styleFont.mathTable!.radicalRuleThickness
|
||||
let radicalHeight = innerDisplay.ascent + innerDisplay.descent + clearance + radicalRuleThickness
|
||||
|
||||
let glyph = self.getRadicalGlyphWithHeight(radicalHeight)!
|
||||
|
||||
// Note this is a departure from Latex. Latex assumes that glyphAscent == thickness.
|
||||
// Open type math makes no such assumption, and ascent and descent are independent of the thickness.
|
||||
// Latex computes delta as descent - (h(inner) + d(inner) + clearance)
|
||||
// but since we may not have ascent == thickness, we modify the delta calculation slightly.
|
||||
// If the font designer followes Latex conventions, it will be identical.
|
||||
let delta : CGFloat = (glyph!.descent + glyph!.ascent) - (innerDisplay!.ascent + innerDisplay!.descent + clearance + radicalRuleThickness);
|
||||
let delta = (glyph.descent + glyph.ascent) - (innerDisplay.ascent + innerDisplay.descent + clearance + radicalRuleThickness)
|
||||
if delta > 0 {
|
||||
clearance += delta/2; // increase the clearance to center the radicand inside the sign.
|
||||
clearance += delta/2 // increase the clearance to center the radicand inside the sign.
|
||||
}
|
||||
|
||||
// we need to shift the radical glyph up, to coincide with the baseline of inner.
|
||||
// The new ascent of the radical glyph should be thickness + adjusted clearance + h(inner)
|
||||
let radicalAscent = radicalRuleThickness + clearance + innerDisplay!.ascent;
|
||||
let shiftUp = radicalAscent - glyph!.ascent; // Note: if the font designer followed latex conventions, this is the same as glyphAscent == thickness.
|
||||
glyph!.shiftDown = -shiftUp;
|
||||
let radicalAscent = radicalRuleThickness + clearance + innerDisplay.ascent
|
||||
let shiftUp = radicalAscent - glyph.ascent // Note: if the font designer followed latex conventions, this is the same as glyphAscent == thickness.
|
||||
glyph.shiftDown = -shiftUp
|
||||
|
||||
let radical = MTRadicalDisplay(withRadicand: innerDisplay, glyph: glyph!, position: currentPosition, range: range)
|
||||
radical.ascent = radicalAscent + styleFont.mathTable!.radicalExtraAscender;
|
||||
radical.topKern = styleFont.mathTable!.radicalExtraAscender;
|
||||
radical.lineThickness = radicalRuleThickness;
|
||||
let radical = MTRadicalDisplay(withRadicand: innerDisplay, glyph: glyph, position: currentPosition, range: range)
|
||||
radical.ascent = radicalAscent + styleFont.mathTable!.radicalExtraAscender
|
||||
radical.topKern = styleFont.mathTable!.radicalExtraAscender
|
||||
radical.lineThickness = radicalRuleThickness
|
||||
// Note: Until we have radical construction from parts, it is possible that glyphAscent+glyphDescent is less
|
||||
// than the requested height of the glyph (i.e. radicalHeight), so in the case the innerDisplay has a larger
|
||||
// descent we use the innerDisplay's descent.
|
||||
radical.descent = max(glyph!.ascent + glyph!.descent - radicalAscent, innerDisplay!.descent);
|
||||
radical.width = glyph!.width + innerDisplay!.width;
|
||||
return radical;
|
||||
radical.descent = max(glyph.ascent + glyph.descent - radicalAscent, innerDisplay.descent)
|
||||
radical.width = glyph.width + innerDisplay.width
|
||||
return radical
|
||||
}
|
||||
|
||||
// MARK: - Glyphs
|
||||
@@ -1170,9 +1169,7 @@ class MTTypesetter {
|
||||
}
|
||||
|
||||
func constructGlyphWithParts(_ parts:[GlyphPart], glyphHeight:CGFloat, glyphs:inout [NSNumber], offsets:inout [NSNumber], height:inout CGFloat) {
|
||||
// assert(!glyphs.isEmpty)
|
||||
// assert(!offsets.isEmpty)
|
||||
|
||||
// Loop forever until the glyph height is valid
|
||||
for numExtenders in 0..<Int.max {
|
||||
var glyphsRv = [NSNumber]()
|
||||
var offsetsRv = [NSNumber]()
|
||||
|
||||
Reference in New Issue
Block a user