Procházet zdrojové kódy

【注释】修复字体Style切换偶现崩溃

wanjun před 6 měsíci
rodič
revize
4f2c39c5a4

+ 12 - 10
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.swift

@@ -2338,7 +2338,8 @@ let KMColorPickerViewHeight: CGFloat = 64
     }
     
     func annotationFontReload() {
-        DispatchQueue.global(qos: .default).async { [self] in
+        DispatchQueue.global(qos: .default).async { [weak self] in
+            guard let self = self else { return }
             let fonts = NSFontManager.shared.availableFontFamilies
             let menu = NSMenu()
             var selectedIndex = 0
@@ -2350,26 +2351,27 @@ let KMColorPickerViewHeight: CGFloat = 64
                     item.attributedTitle = attributedString
                     menu.addItem(item)
                     
-                    if annotationType == .freeText || annotationType == .signText || annotationType == .signDate {
-                        if annotationModel?.fontName() == font.fontName {
+                    if self.annotationType == .freeText || self.annotationType == .signText || self.annotationType == .signDate {
+                        if self.annotationModel?.fontName() == font.fontName {
                             selectedIndex = index
                         }
                     }
                 }
             }
             
-            if annotationType == .freeText || annotationType == .signText || annotationType == .signDate {
-                if let data = annotationModel?.fontName() {
+            if self.annotationType == .freeText || self.annotationType == .signText || self.annotationType == .signDate {
+                if let data = self.annotationModel?.fontName() {
                     let freetextFont = NSFont(name: data, size: 16) ?? NSFont.systemFont(ofSize: 16)
                     if let family = freetextFont.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
                        let style = freetextFont.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
                         
-                        DispatchQueue.main.async { [self] in
-                            fontPopUpButton.menu = menu
-                            fontPopUpButton.selectItem(at: selectedIndex)
+                        DispatchQueue.main.async { [weak self] in
+                            guard let self = self else { return }
+                            self.fontPopUpButton.menu = menu
+                            self.fontPopUpButton.selectItem(at: selectedIndex)
                             
-                            let selectedStyleIndex = setFontStyle(fontName: family, currentStyle: style)
-                            fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
+                            let selectedStyleIndex = self.setFontStyle(fontName: family, currentStyle: style)
+                            self.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
                         }
                     }
                 }

+ 8 - 6
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/WindowController/KMAnnotationFontWindowController.swift

@@ -199,7 +199,8 @@ class KMFontModel: NSObject {
     }
 
     func annotationFontReload() {
-        DispatchQueue.global(qos: .default).async { [self] in
+        DispatchQueue.global(qos: .default).async { [weak self] in
+            guard let self = self else { return }
             let fonts = NSFontManager.shared.availableFontFamilies
             let menu = NSMenu()
             var selectedIndex = 0
@@ -219,12 +220,13 @@ class KMFontModel: NSObject {
                     }
                 }
             }
-            DispatchQueue.main.async { [self] in
-                fontComboBox.menu = menu
-                fontComboBox.selectItem(at: selectedIndex)
+            DispatchQueue.main.async { [weak self] in
+                guard let self = self else { return }
+                self.fontComboBox.menu = menu
+                self.fontComboBox.selectItem(at: selectedIndex)
                 
-                let selectedStyleIndex = setFontStyle(fontName: annotationFontModel!.fontName, currentStyle: annotationFontModel!.fontWeight)
-                fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
+                let selectedStyleIndex = self.setFontStyle(fontName: self.annotationFontModel!.fontName, currentStyle: self.annotationFontModel!.fontWeight)
+                self.fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
             }
         }
     }