Browse Source

偏好设置-Markup字体补充交互

tangchao 2 years ago
parent
commit
24fb9ec415

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 2
PDF Office/PDF Office.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -398,8 +398,8 @@
             filePath = "PDF Office/Class/Preference/Controller/KMPreferenceMarkupController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "156"
-            endingLineNumber = "156"
+            startingLineNumber = "146"
+            endingLineNumber = "146"
             landmarkName = "initData()"
             landmarkType = "7">
          </BreakpointContent>

+ 5 - 22
PDF Office/PDF Office/Class/Preference/Controller/KMPreferenceMarkupController.swift

@@ -24,17 +24,7 @@ class KMPreferenceMarkupController: NSViewController {
     @IBOutlet weak var aligementView: KMPreferenceAligementView!
     var currentColorItemView: KMPreferenceMarkupColorItemView?
     
-    var fontNames: [String] {
-        get {
-            var fontNames: Array<String> = []
-            for font in CPDFAnnotationModel.supportFonts() {
-                let fontDict: NSDictionary = font as! NSDictionary
-                let fontName: String = fontDict.allKeys.first as! String
-                fontNames.append(fontName)
-            }
-            return fontNames
-        }
-    }
+    lazy var fontNames = KMPreferenceManager.supportFonts
     
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -162,17 +152,9 @@ class KMPreferenceMarkupController: NSViewController {
             }
         }
         
-        let fontNames = self.fontNames
-        var value = KMPreferenceManager.shared.markupFontTextType
-        if (value == 0) {
-            self.textComboBox.stringValue = fontNames[0]
-        } else if (value == 1) {
-            self.textComboBox.stringValue = fontNames[1]
-        } else if (value == 2) {
-            self.textComboBox.stringValue = fontNames[2]
-        }
+        self.textComboBox.stringValue = KMPreferenceManager.shared.markupFontTextString
         
-        value = KMPreferenceManager.shared.markupFontTextAligmentType
+        var value = KMPreferenceManager.shared.markupFontTextAligmentType
         if (value == 0) {
             self.aligementView.selectIndex(index: 0)
         } else if (value == 1) {
@@ -181,6 +163,7 @@ class KMPreferenceMarkupController: NSViewController {
             self.aligementView.selectIndex(index: 2)
         }
         
+        let fontNames = self.fontNames
         value = KMPreferenceManager.shared.markupFontNoteType
         if (value == 0) {
             self.noteComboBox.stringValue = fontNames[0]
@@ -233,7 +216,7 @@ extension KMPreferenceMarkupController: NSComboBoxDelegate {
             if (index < 0) {
                 index = 0
             }
-            KMPreferenceManager.shared.markupFontTextType = index
+            KMPreferenceManager.shared.markupFontTextString = self.fontNames[index]
         } else if (self.noteComboBox.isEqual(to: notification.object)) {
             var index = self.noteComboBox.indexOfSelectedItem
             if (index < 0) {

+ 45 - 8
PDF Office/PDF Office/Class/Preference/Tools/KMPreferenceManager.swift

@@ -808,14 +808,14 @@ extension KMPreferenceManager {
         }
     }
     
-    var markupFontTextType: Int {
-        get {
-            return self.getData(forKey: KMMarkupFontTextTypeKey) as! Int
-        }
-        set {
-            let _ = self.setData(data: newValue, forKey: KMMarkupFontTextTypeKey)
-        }
-    }
+//    var markupFontTextType: Int {
+//        get {
+//            return self.getData(forKey: KMMarkupFontTextTypeKey) as! Int
+//        }
+//        set {
+//            let _ = self.setData(data: newValue, forKey: KMMarkupFontTextTypeKey)
+//        }
+//    }
     
     var markupFontTextAligmentType: Int {
         get {
@@ -836,6 +836,43 @@ extension KMPreferenceManager {
     }
 }
 
+// MARK: -
+// MARK: Additions
+
+fileprivate let kKMFreeTextDefaultFontName = "Helvetica"
+extension KMPreferenceManager {
+    var markupFontTextString: String {
+        get {
+            let string: String? = UserDefaults.standard.object(forKey: CFreeTextNoteFontNameKey) as? String
+            if (string == nil) {
+                return kKMFreeTextDefaultFontName
+            }
+            if (KMPreferenceManager.supportFonts.contains(string!)) {
+                return string!
+            }
+            return kKMFreeTextDefaultFontName
+        }
+        set {
+            if (KMPreferenceManager.supportFonts.contains(newValue)) {
+                UserDefaults.standard.set(newValue, forKey: CFreeTextNoteFontNameKey)
+                UserDefaults.standard.synchronize()
+            }
+        }
+    }
+    
+    class var supportFonts: [String] {
+        get {
+            var fontNames: Array<String> = []
+            for font in CPDFAnnotationModel.supportFonts() {
+                let fontDict: NSDictionary = font as! NSDictionary
+                let fontName: String = fontDict.allKeys.first as! String
+                fontNames.append(fontName)
+            }
+            return fontNames
+        }
+    }
+}
+
 // MARK: -
 // MARK: UserDefaults