Use superscript/subscript font feature

This commit is contained in:
Nate Weaver 2020-04-08 06:50:54 -05:00
parent 06b3d2f8e1
commit 57a6561733
1 changed files with 6 additions and 2 deletions

View File

@ -54,10 +54,14 @@ extension NSAttributedString {
if superscript != 0 {
let font = mutable.attribute(.font, at: range.location, effectiveRange: nil) as! NSFont
let size = font.pointSize * 0.6
let newFont = NSFont(descriptor: font.fontDescriptor, size: size)
let features: [NSFontDescriptor.FeatureKey: Any] = [.typeIdentifier: kVerticalPositionType, .selectorIdentifier: superscript > 0 ? kSuperiorsSelector : kInferiorsSelector]
let attributes: [NSFontDescriptor.AttributeName: Any] = [.featureSettings: [features]]
let descriptor = font.fontDescriptor.addingAttributes(attributes)
let newFont = NSFont(descriptor: descriptor, size: font.pointSize)
mutable.addAttribute(.font, value: newFont as Any, range: range)
mutable.addAttribute(.superscript, value: 0, range: range)
}
}