Procházet zdrojové kódy

fix bugs and add font

alqindiirsyam před 2 roky
rodič
revize
570316517e

+ 18 - 0
appbuilder-ios/DigiXLite/DigiXLite/Source/DigiX.swift

@@ -1544,6 +1544,8 @@ struct LibFontName {
     static let regular = "Inter-Regular"
     static let bold = "Inter-SemiBold"
     static let italic = "Inter-Italic"
+    static let medium = "Inter-Medium"
+    static let boldItalic = "Inter-SemiBoldItalic"
 }
 
 extension UIFontDescriptor.AttributeName {
@@ -1558,6 +1560,17 @@ extension UIFont {
         jbs_registerFont(withFilenameString: LibFontName.regular)
         return UIFont(name: LibFontName.regular, size: size)
     }
+    
+    @objc class func libSystemFontWeight(ofSize size: CGFloat, weight: UIFont.Weight) -> UIFont? {
+        if weight == .medium {
+            jbs_registerFont(withFilenameString: LibFontName.medium)
+            return UIFont(name: LibFontName.medium, size: size)
+        } else if weight == .semibold {
+            jbs_registerFont(withFilenameString: LibFontName.boldItalic)
+            return UIFont(name: LibFontName.boldItalic, size: size)
+        }
+        return UIFont(name: LibFontName.regular, size: size)
+    }
 
     @objc class func libBoldSystemFont(ofSize size: CGFloat) -> UIFont? {
         jbs_registerFont(withFilenameString: LibFontName.bold)
@@ -1600,6 +1613,11 @@ extension UIFont {
             let mySystemFontMethod = class_getClassMethod(self, #selector(libSystemFont(ofSize:))) {
             method_exchangeImplementations(systemFontMethod, mySystemFontMethod)
         }
+        
+        if let systemFontWeightMethod = class_getClassMethod(self, #selector(systemFont(ofSize:weight:))),
+           let mySystemFontWeightMethod = class_getClassMethod(self, #selector(libSystemFontWeight(ofSize:weight:))) {
+            method_exchangeImplementations(systemFontWeightMethod, mySystemFontWeightMethod)
+        }
 
         if let boldSystemFontMethod = class_getClassMethod(self, #selector(boldSystemFont(ofSize:))),
             let myBoldSystemFontMethod = class_getClassMethod(self, #selector(libBoldSystemFont(ofSize:))) {

+ 17 - 1
appbuilder-ios/DigiXLite/DigiXLite/Source/Extension.swift

@@ -632,12 +632,14 @@ extension String {
         let font = UIFont.systemFont(ofSize: 12)
         let boldFont = UIFont.boldSystemFont(ofSize: 12)
         let italicFont = UIFont.italicSystemFont(ofSize: 12)
+        let boldItalicFont = UIFont.systemFont(ofSize: 12, weight: .semibold)
         let textUTF8 = String(self.utf8)
         let finalText = NSMutableAttributedString(string: textUTF8, attributes: [NSAttributedString.Key.font: font])
         let boldSign: Character = "*"
         let italicSign: Character = "_"
         let underlineSign: Character = "^"
         let strikethroughSign: Character = "~"
+        var locationBold: [NSRange] = []
         
         //Bold
         let rangeBold = getRangeOfWordWithSign(sentence: textUTF8, sign: boldSign)
@@ -668,6 +670,7 @@ extension String {
                 let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
                 let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
                 totalEmoji = countEmoji + countEmojiBefore
+                locationBold.append(NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
                 finalText.addAttribute(.font, value: boldFont, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
                 if !isEditing{
                     finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
@@ -712,7 +715,11 @@ extension String {
                 let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
                 let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
                 totalEmoji = countEmoji + countEmojiBefore
-                finalText.addAttribute(.font, value: italicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                if isIntInRangeList((rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange - lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, rangeList: locationBold) {
+                    finalText.addAttribute(.font, value: boldItalicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                } else {
+                    finalText.addAttribute(.font, value: italicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                }
                 if !isEditing{
                     finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
                     finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
@@ -847,6 +854,15 @@ extension String {
         return finalText
     }
     
+    func isIntInRangeList(_ intValue: Int, rangeList: [NSRange]) -> Bool {
+        for range in rangeList {
+            if intValue >= range.location && intValue < range.location + range.length {
+                return true
+            }
+        }
+        return false
+    }
+    
     func checkCharBefore(char: String) -> Bool {
         return char == " " || char == "\n"
     }

+ 17 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/Extension.swift

@@ -632,12 +632,14 @@ extension String {
         let font = UIFont.systemFont(ofSize: 12)
         let boldFont = UIFont.boldSystemFont(ofSize: 12)
         let italicFont = UIFont.italicSystemFont(ofSize: 12)
+        let boldItalicFont = UIFont.systemFont(ofSize: 12, weight: .semibold)
         let textUTF8 = String(self.utf8)
         let finalText = NSMutableAttributedString(string: textUTF8, attributes: [NSAttributedString.Key.font: font])
         let boldSign: Character = "*"
         let italicSign: Character = "_"
         let underlineSign: Character = "^"
         let strikethroughSign: Character = "~"
+        var locationBold: [NSRange] = []
         
         //Bold
         let rangeBold = getRangeOfWordWithSign(sentence: textUTF8, sign: boldSign)
@@ -668,6 +670,7 @@ extension String {
                 let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
                 let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
                 totalEmoji = countEmoji + countEmojiBefore
+                locationBold.append(NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
                 finalText.addAttribute(.font, value: boldFont, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
                 if !isEditing{
                     finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
@@ -712,7 +715,11 @@ extension String {
                 let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
                 let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
                 totalEmoji = countEmoji + countEmojiBefore
-                finalText.addAttribute(.font, value: italicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                if isIntInRangeList((rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange - lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, rangeList: locationBold) {
+                    finalText.addAttribute(.font, value: boldItalicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                } else {
+                    finalText.addAttribute(.font, value: italicFont, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
+                }
                 if !isEditing{
                     finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
                     finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
@@ -847,6 +854,15 @@ extension String {
         return finalText
     }
     
+    func isIntInRangeList(_ intValue: Int, rangeList: [NSRange]) -> Bool {
+        for range in rangeList {
+            if intValue >= range.location && intValue < range.location + range.length {
+                return true
+            }
+        }
+        return false
+    }
+    
     func checkCharBefore(char: String) -> Bool {
         return char == " " || char == "\n"
     }

+ 18 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -1544,6 +1544,8 @@ struct LibFontName {
     static let regular = "Poppins-Regular"
     static let bold = "Poppins-SemiBold"
     static let italic = "Poppins-Italic"
+    static let medium = "Poppins-Medium"
+    static let boldItalic = "Poppins-SemiBoldItalic"
 }
 
 extension UIFontDescriptor.AttributeName {
@@ -1558,6 +1560,17 @@ extension UIFont {
         jbs_registerFont(withFilenameString: LibFontName.regular)
         return UIFont(name: LibFontName.regular, size: size)
     }
+    
+    @objc class func libSystemFontWeight(ofSize size: CGFloat, weight: UIFont.Weight) -> UIFont? {
+        if weight == .medium {
+            jbs_registerFont(withFilenameString: LibFontName.medium)
+            return UIFont(name: LibFontName.medium, size: size)
+        } else if weight == .semibold {
+            jbs_registerFont(withFilenameString: LibFontName.boldItalic)
+            return UIFont(name: LibFontName.boldItalic, size: size)
+        }
+        return UIFont(name: LibFontName.regular, size: size)
+    }
 
     @objc class func libBoldSystemFont(ofSize size: CGFloat) -> UIFont? {
         jbs_registerFont(withFilenameString: LibFontName.bold)
@@ -1600,6 +1613,11 @@ extension UIFont {
             let mySystemFontMethod = class_getClassMethod(self, #selector(libSystemFont(ofSize:))) {
             method_exchangeImplementations(systemFontMethod, mySystemFontMethod)
         }
+        
+        if let systemFontWeightMethod = class_getClassMethod(self, #selector(systemFont(ofSize:weight:))),
+           let mySystemFontWeightMethod = class_getClassMethod(self, #selector(libSystemFontWeight(ofSize:weight:))) {
+            method_exchangeImplementations(systemFontWeightMethod, mySystemFontWeightMethod)
+        }
 
         if let boldSystemFontMethod = class_getClassMethod(self, #selector(boldSystemFont(ofSize:))),
             let myBoldSystemFontMethod = class_getClassMethod(self, #selector(libBoldSystemFont(ofSize:))) {