Sunset MathTable, created MTFontV2, MTFontMathTableV2 and MathImage, about to sunset MTMathImage

This commit is contained in:
Peter Tang
2023-09-15 09:53:54 +08:00
parent 2762cbee85
commit cea2188310
10 changed files with 338 additions and 65 deletions

View File

@@ -39,10 +39,10 @@ public enum MathFont: String, CaseIterable {
case .termesFont: return "TeXGyreTermesMath-Regular"
}
}
public func cgFont() -> CGFont? {
public func cgFont() -> CGFont {
BundleManager.manager.obtainCGFont(font: self)
}
public func ctFont(withSize size: CGFloat) -> CTFont? {
public func ctFont(withSize size: CGFloat) -> CTFont {
BundleManager.manager.obtainCTFont(font: self, withSize: size)
}
#if os(iOS)
@@ -55,16 +55,16 @@ public enum MathFont: String, CaseIterable {
NSFont(name: fontName, size: size)
}
#endif
internal func mathTable() -> NSDictionary? {
internal func mathTable() -> NSDictionary {
BundleManager.manager.obtainMathTable(font: self)
}
internal func get(nameForGlyph glyph: CGGlyph) -> String {
let name = cgFont()?.name(for: glyph) as? String
return name ?? ""
}
internal func get(glyphWithName name: String) -> CGGlyph? {
cgFont()?.getGlyphWithGlyphName(name: name as CFString)
}
// internal func get(nameForGlyph glyph: CGGlyph) -> String {
// let name = cgFont().name(for: glyph) as? String
// return name ?? ""
// }
// internal func get(glyphWithName name: String) -> CGGlyph {
// cgFont().getGlyphWithGlyphName(name: name as CFString)
// }
}
internal extension CTFont {
/** The size of this font in points. */
@@ -117,7 +117,6 @@ private class BundleManager {
version == "1.3" else {
throw FontError.invalidMathTable
}
//FIXME: mathTable = MTFontMathTable(withFont:self, mathTable:rawMathTable)
mathTables[mathFont] = rawMathTable
print("mathFonts bundle resource: \(mathFont.rawValue).plist registered.")
}
@@ -135,12 +134,15 @@ private class BundleManager {
initializedOnceAlready.toggle()
}
fileprivate func obtainCGFont(font: MathFont) -> CGFont? {
fileprivate func obtainCGFont(font: MathFont) -> CGFont {
if !initializedOnceAlready { registerAllBundleResources() }
return cgFonts[font]
guard let cfFont = cgFonts[font] else {
fatalError("\(#function) unable to locate CTFont \(font.fontName)")
}
return cfFont
}
fileprivate func obtainCTFont(font: MathFont, withSize size: CGFloat) -> CTFont? {
fileprivate func obtainCTFont(font: MathFont, withSize size: CGFloat) -> CTFont {
if !initializedOnceAlready { registerAllBundleResources() }
let fontPair = CTFontPair(font: font, size: size)
guard let ctFont = ctFonts[fontPair] else {
@@ -149,13 +151,16 @@ private class BundleManager {
ctFonts[fontPair] = ctFont
return ctFont
}
return nil
fatalError("\(#function) unable to locate CTFont \(font.fontName)")
}
return ctFont
}
fileprivate func obtainMathTable(font: MathFont) -> NSDictionary? {
fileprivate func obtainMathTable(font: MathFont) -> NSDictionary {
if !initializedOnceAlready { registerAllBundleResources() }
return mathTables[font]
guard let mathTable = mathTables[font] else {
fatalError("\(#function) unable to locate mathTable: \(font.rawValue).plist")
}
return mathTable
}
deinit {
ctFonts.removeAll()