Keep monospace fonts monospaced; use a variable for the current symbolic traits
This commit is contained in:
parent
db166ba0d7
commit
2a00b4a4a9
|
@ -20,7 +20,7 @@ extension NSAttributedString {
|
|||
|
||||
let size = baseFont.pointSize
|
||||
let baseDescriptor = baseFont.fontDescriptor
|
||||
let symbolicTraits = baseDescriptor.symbolicTraits
|
||||
let baseSymbolicTraits = baseDescriptor.symbolicTraits
|
||||
|
||||
let baseTraits = baseDescriptor.object(forKey: .traits) as! [NSFontDescriptor.TraitKey: Any]
|
||||
let baseWeight = baseTraits[.weight] as! NSFont.Weight
|
||||
|
@ -28,15 +28,21 @@ extension NSAttributedString {
|
|||
mutable.enumerateAttribute(.font, in: fullRange, options: []) { (font: Any?, range: NSRange, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
guard let font = font as? NSFont else { return }
|
||||
|
||||
var newSymbolicTraits = symbolicTraits
|
||||
var newSymbolicTraits = baseSymbolicTraits
|
||||
|
||||
if font.fontDescriptor.symbolicTraits.contains(.italic) {
|
||||
let symbolicTraits = font.fontDescriptor.symbolicTraits
|
||||
|
||||
if symbolicTraits.contains(.italic) {
|
||||
newSymbolicTraits.insert(.italic)
|
||||
}
|
||||
|
||||
if symbolicTraits.contains(.monoSpace) {
|
||||
newSymbolicTraits.insert(.monoSpace)
|
||||
}
|
||||
|
||||
var descriptor = baseDescriptor.withSymbolicTraits(newSymbolicTraits)
|
||||
|
||||
if font.fontDescriptor.symbolicTraits.contains(.bold) {
|
||||
if symbolicTraits.contains(.bold) {
|
||||
// If the base font is semibold (as timeline titles are), make the "bold"
|
||||
// text heavy for better contrast.
|
||||
|
||||
|
|
Loading…
Reference in New Issue