Prechádzať zdrojové kódy

【fix】【Form】列表框-外观-字体A,调整字体时,崩溃(必现)。bug修复

tangchao 10 mesiacov pred
rodič
commit
7f60074bb9

+ 13 - 13
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/FormProperties/KMAnnotationChoiceWidgetAppearanceViewController.swift

@@ -382,7 +382,7 @@ private enum KMPDFAnnotationFontWeightType: Int {
         let fontWindowController = KMAnnotationFontWindowController.initWindowController(fontModel)
         let window = fontWindowController.window
         fontWindowController.callback = { [weak self] model in
-            self!.colorPickerView.color = model.fontColor
+            self?.colorPickerView.color = model.fontColor
             
             DispatchQueue.global(qos: .default).async { [self]
                 let fonts = NSFontManager.shared.availableFontFamilies
@@ -411,18 +411,18 @@ private enum KMPDFAnnotationFontWeightType: Int {
                     }
                 }
             }
-            let selectedStyleIndex = self!.setFontStyleWithFontName(model.fontName, currentStyle: model.fontWeight)
-            self!.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
-            self!.fontSizeComboBox.stringValue = String(format: "%.f pt", model.fontSize)
+            let selectedStyleIndex = self?.setFontStyleWithFontName(model.fontName, currentStyle: model.fontWeight) ?? 0
+            self?.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
+            self?.fontSizeComboBox.stringValue = String(format: "%.f pt", model.fontSize)
             
-            if self!.annotationModel.annotations != nil {
+            if self?.annotationModel.annotations != nil {
                 let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: model.fontName, .face: model.fontWeight])
                 let annotationFont = NSFont(descriptor: attributeFontDescriptor, size: model.fontSize)
 
                 for tAnnotation in self!.annotations {
                     if tAnnotation is CPDFAnnotation {
-                        (tAnnotation as! CPDFButtonWidgetAnnotation).font = annotationFont
-                        (tAnnotation as! CPDFButtonWidgetAnnotation).fontColor = model.fontColor
+                        (tAnnotation as? CPDFWidgetAnnotation)?.font = annotationFont
+                        (tAnnotation as? CPDFWidgetAnnotation)?.fontColor = model.fontColor
 //                        if model.fontAlignment == .left {
 //                            (tAnnotation as! CPDFButtonWidgetAnnotation).alignment = .left
 //                        } else if model.fontAlignment == .center {
@@ -434,15 +434,15 @@ private enum KMPDFAnnotationFontWeightType: Int {
                 }
                 self!.updateAnnotation()
             } else {
-                self!.annotationModel.setFontName(model.fontName)
-                self!.annotationModel.setFontSize(model.fontSize)
-                self!.annotationModel.setFontColor(model.fontColor)
+                self?.annotationModel.setFontName(model.fontName)
+                self?.annotationModel.setFontSize(model.fontSize)
+                self?.annotationModel.setFontColor(model.fontColor)
                 if model.fontAlignment == .left {
-                    self!.annotationModel.setAlignment(.left)
+                    self?.annotationModel.setAlignment(.left)
                 } else if model.fontAlignment == .center {
-                    self!.annotationModel.setAlignment(.center)
+                    self?.annotationModel.setAlignment(.center)
                 } else if model.fontAlignment == .right {
-                    self!.annotationModel.setAlignment(.right)
+                    self?.annotationModel.setAlignment(.right)
                 }
             }
         }

+ 3 - 0
PDF Office/PDF Master/Class/README.md

@@ -107,6 +107,9 @@
 ## 笔记类型窗口
 * KMNotesPanelController
 
+## 字体设置窗口
+* KMAnnotationFontWindowController
+
 ## xxx
 
 [sign in](https://www.baidu.com) the [dashboard](https://www.baidu.com). to [sign up](https://www.baidu.com)