From 3b8334264cb5f9caa15194dcbafa295bdb13eb37 Mon Sep 17 00:00:00 2001 From: Ysy Date: Fri, 1 Mar 2019 15:19:18 +0800 Subject: [PATCH] Fix oblique type bug for Chinese The bug is: When you type Chinese and English at the same line with `oblique` format enable, and then when you delete all the English characters, the `oblique` format button won't be able to toggle again. --- Aztec/Classes/Extensions/UIFont+Traits.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Aztec/Classes/Extensions/UIFont+Traits.swift b/Aztec/Classes/Extensions/UIFont+Traits.swift index 839ff5fea..dd0dbf869 100644 --- a/Aztec/Classes/Extensions/UIFont+Traits.swift +++ b/Aztec/Classes/Extensions/UIFont+Traits.swift @@ -30,6 +30,15 @@ extension UIFont { // This is a very viable scenario, and our default handling mechanism for it is to // return the original, unmodified font. // + + // MARK: Fix oblique type for Chinese + if newTraits.contains(.traitItalic) && familyDescriptor.postscriptName.hasPrefix(".PingFangSC") { + newTraits.remove(.traitItalic) + if let newDescriptor = familyDescriptor.withSymbolicTraits(newTraits) { + return UIFont(descriptor: newDescriptor, size: pointSize) + } + } + return self }