This commit is contained in:
Michael Griebling
2023-02-22 11:19:28 -05:00
parent dd2ae2a5f6
commit 18b334bf80

View File

@@ -190,8 +190,8 @@ class MTFontMathTable {
/** Returns an Array of all the vertical variants of the glyph if any. If /** Returns an Array of all the vertical variants of the glyph if any. If
there are no variants for the glyph, the array contains the given glyph. */ there are no variants for the glyph, the array contains the given glyph. */
func getVerticalVariantsForGlyph( _ glyph:CGGlyph) -> [NSNumber?] { func getVerticalVariantsForGlyph( _ glyph:CGGlyph) -> [NSNumber?] {
let variants = _mathTable[kVertVariants] as! NSDictionary let variants = _mathTable[kVertVariants] as! NSDictionary?
return self.getVariantsForGlyph(glyph, inDictionary: variants) return self.getVariantsForGlyph(glyph, inDictionary: variants!)
} }
/** Returns an Array of all the horizontal variants of the glyph if any. If /** Returns an Array of all the horizontal variants of the glyph if any. If
@@ -201,9 +201,9 @@ class MTFontMathTable {
return self.getVariantsForGlyph(glyph, inDictionary:variants) return self.getVariantsForGlyph(glyph, inDictionary:variants)
} }
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? NSDictionary let variantGlyphs = variants[glyphName] as! NSArray?
var glyphArray = [NSNumber]() var glyphArray = [NSNumber]()
if variantGlyphs == nil || variantGlyphs?.count == 0 { if variantGlyphs == nil || variantGlyphs?.count == 0 {
// 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.
@@ -223,9 +223,9 @@ class MTFontMathTable {
If there is no larger version, this returns the current glyph. If there is no larger version, this returns the current glyph.
*/ */
func getLargerGlyph(_ glyph:CGGlyph) -> CGGlyph { func getLargerGlyph(_ glyph:CGGlyph) -> CGGlyph {
let variants = _mathTable[kVertVariants] as! NSDictionary let variants = _mathTable[kVertVariants] as! NSDictionary?
let glyphName = self.font?.get(nameForGlyph: glyph) let glyphName = self.font?.get(nameForGlyph: glyph)
let variantGlyphs = variants[glyphName!] as? NSDictionary let variantGlyphs = variants![glyphName!] as! NSArray?
if variantGlyphs == nil || variantGlyphs?.count == 0 { if variantGlyphs == nil || variantGlyphs?.count == 0 {
// There are no extra variants, so just returnt the current glyph. // There are no extra variants, so just returnt the current glyph.
return glyph return glyph
@@ -249,9 +249,9 @@ class MTFontMathTable {
/** Returns the italic correction for the given glyph if any. If there /** Returns the italic correction for the given glyph if any. If there
isn't any this returns 0. */ isn't any this returns 0. */
func getItalicCorrection(_ glyph: CGGlyph) -> CGFloat { func getItalicCorrection(_ glyph: CGGlyph) -> CGFloat {
let italics = _mathTable[kItalic] as! NSDictionary let italics = _mathTable[kItalic] as! NSDictionary?
let glyphName = self.font?.get(nameForGlyph: glyph) let glyphName = self.font?.get(nameForGlyph: glyph)
let val = italics[glyphName!] as! NSNumber? let val = italics![glyphName!] as! NSNumber?
// if val is nil, this returns 0. // if val is nil, this returns 0.
return self.fontUnitsToPt(val?.intValue ?? 0) return self.fontUnitsToPt(val?.intValue ?? 0)
} }
@@ -264,9 +264,9 @@ class MTFontMathTable {
If there isn't any this returns -1. */ If there isn't any this returns -1. */
func getTopAccentAdjustment(_ glyph: CGGlyph) -> CGFloat { func getTopAccentAdjustment(_ glyph: CGGlyph) -> CGFloat {
var glyph = glyph var glyph = glyph
let accents = _mathTable[kAccents] as! NSDictionary let accents = _mathTable[kAccents] as! NSDictionary?
let glyphName = self.font?.get(nameForGlyph: glyph) let glyphName = self.font?.get(nameForGlyph: glyph)
let val = accents[glyphName!] as! NSNumber? let val = accents![glyphName!] as! NSNumber?
if let val = val { if let val = val {
return self.fontUnitsToPt(val.intValue) return self.fontUnitsToPt(val.intValue)
} else { } else {
@@ -288,20 +288,20 @@ class MTFontMathTable {
/** Returns an array of the glyph parts to be used for constructing vertical variants /** Returns an array of the glyph parts to be used for constructing vertical variants
of this glyph. If there is no glyph assembly defined, returns an empty array. */ of this glyph. If there is no glyph assembly defined, returns an empty array. */
func getVerticalGlyphAssembly(forGlyph glyph:CGGlyph) -> [GlyphPart] { func getVerticalGlyphAssembly(forGlyph glyph:CGGlyph) -> [GlyphPart] {
let assemblyTable = _mathTable[kVertAssembly] as! NSDictionary let assemblyTable = _mathTable[kVertAssembly] as! NSDictionary?
let glyphName = self.font?.get(nameForGlyph: glyph) let glyphName = self.font?.get(nameForGlyph: glyph)
let assemblyInfo = assemblyTable[glyphName!] as! NSDictionary let assemblyInfo = assemblyTable![glyphName!] as! NSDictionary?
if assemblyInfo.count == 0 { if assemblyInfo == nil {
// No vertical assembly defined for glyph // No vertical assembly defined for glyph
return [] return []
} }
let parts = assemblyInfo[kAssemblyParts] as! [GlyphPart] let parts = assemblyInfo![kAssemblyParts] as! NSArray?
if parts.count == 0 { if parts == nil {
// parts should always have been defined, but if it isn't return nil // parts should always have been defined, but if it isn't return nil
return [] return []
} }
var rv = [GlyphPart]() var rv = [GlyphPart]()
for part in parts { for part in parts! {
let partInfo = part as! NSDictionary? let partInfo = part as! NSDictionary?
var part = GlyphPart() var part = GlyphPart()
let adv = partInfo!["advance"] as! NSNumber? let adv = partInfo!["advance"] as! NSNumber?