Merge pull request #28 from 07akioni/main

Fix fontSize arg is not applied to MTMathImage
This commit is contained in:
mgriebling
2024-09-14 08:18:37 -04:00
committed by GitHub

View File

@@ -16,8 +16,16 @@ import Foundation
#endif
public class MTMathImage {
public var font: MTFont? = nil
public let fontSize: CGFloat
public var font: MTFont? = MTFontManager.fontManager.defaultFont
public var fontSize:CGFloat {
set {
_fontSize = newValue
let font = font?.copy(withSize: newValue)
self.font = font // also forces an update
}
get { _fontSize }
}
private var _fontSize:CGFloat = 0
public let textColor: MTColor
public let labelMode: MTMathUILabelMode
@@ -30,10 +38,10 @@ public class MTMathImage {
public init(latex: String, fontSize: CGFloat, textColor: MTColor, labelMode: MTMathUILabelMode = .display, textAlignment: MTTextAlignment = .center) {
self.latex = latex
self.fontSize = fontSize
self.textColor = textColor
self.labelMode = labelMode
self.textAlignment = textAlignment
self.fontSize = fontSize
}
}
extension MTMathImage {
@@ -65,9 +73,7 @@ extension MTMathImage {
let textY = (availableHeight - height) / 2 + displayList.descent + contentInsets.bottom
displayList.position = CGPoint(x: textX, y: textY)
}
if font == nil {
self.font = MTFontManager.fontManager.defaultFont
}
var error: NSError?
guard let mathList = MTMathListBuilder.build(fromString: latex, error: &error), error == nil,
let displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle) else {