Use a nested function for superscript/subscript features
This commit is contained in:
parent
fd672c5ce6
commit
b722e75d9e
@ -291,22 +291,23 @@ extension NSAttributedString {
|
|||||||
descriptor = descriptor.withSymbolicTraits(symbolicTraits)
|
descriptor = descriptor.withSymbolicTraits(symbolicTraits)
|
||||||
}
|
}
|
||||||
|
|
||||||
if styles.contains(.superscript) {
|
func verticalPositionFeature(forSuperscript: Bool) -> [FontDescriptor.FeatureKey: Any] {
|
||||||
#if canImport(AppKit)
|
#if canImport(AppKit)
|
||||||
let features: [FontDescriptor.FeatureKey: Any] = [.typeIdentifier: kVerticalPositionType, .selectorIdentifier: kSuperiorsSelector]
|
let features: [FontDescriptor.FeatureKey: Any] = [.typeIdentifier: kVerticalPositionType, .selectorIdentifier: forSuperscript ? kSuperiorsSelector : kInferiorsSelector]
|
||||||
#else
|
#else
|
||||||
let features: [FontDescriptor.FeatureKey: Any] = [.featureIdentifier: kVerticalPositionType, .typeIdentifier: kSuperiorsSelector]
|
let features: [FontDescriptor.FeatureKey: Any] = [.featureIdentifier: kVerticalPositionType, .typeIdentifier: forSuperscript ? kSuperiorsSelector : kInferiorsSelector]
|
||||||
#endif
|
#endif
|
||||||
|
return features
|
||||||
|
}
|
||||||
|
|
||||||
|
if styles.contains(.superscript) {
|
||||||
|
let features = verticalPositionFeature(forSuperscript: true)
|
||||||
let descriptorAttributes: [FontDescriptor.AttributeName: Any] = [.featureSettings: [features]]
|
let descriptorAttributes: [FontDescriptor.AttributeName: Any] = [.featureSettings: [features]]
|
||||||
descriptor = descriptor.addingAttributes(descriptorAttributes)
|
descriptor = descriptor.addingAttributes(descriptorAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if styles.contains(.subscript) {
|
if styles.contains(.subscript) {
|
||||||
#if canImport(AppKit)
|
let features = verticalPositionFeature(forSuperscript: false)
|
||||||
let features: [FontDescriptor.FeatureKey: Any] = [.typeIdentifier: kVerticalPositionType, .selectorIdentifier: kInferiorsSelector]
|
|
||||||
#else
|
|
||||||
let features: [FontDescriptor.FeatureKey: Any] = [.featureIdentifier: kVerticalPositionType, .typeIdentifier: kInferiorsSelector]
|
|
||||||
#endif
|
|
||||||
let descriptorAttributes: [FontDescriptor.AttributeName: Any] = [.featureSettings: [features]]
|
let descriptorAttributes: [FontDescriptor.AttributeName: Any] = [.featureSettings: [features]]
|
||||||
descriptor = currentDescriptor.addingAttributes(descriptorAttributes)
|
descriptor = currentDescriptor.addingAttributes(descriptorAttributes)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user