Browse Source

【偏好设置】字体设置项补充

tangchao 1 year ago
parent
commit
cb1156d8c2

+ 28 - 0
PDF Office/PDF Master/Class/Preference/Controller/KMNotesPreferences.swift

@@ -271,6 +271,16 @@ class KMNotesPreferences: NSViewController {
         // SKFreeTextNoteAlignmentKey
         // SKAnchoredNoteFontNameKey
         // SKAnchoredNoteFontSizeKey
+        
+        let textFontName = KMPreference.shared.markupFontTextString
+        let textFontSize = KMPreference.shared.markupTextFontSize
+        let textFont = NSFont(name: textFontName, size: textFontSize.cgFloat)
+        self.fontWell1.font = textFont
+        
+        let noteFontName = KMPreference.shared.markupFontNoteString
+        let noteFontSize = KMPreference.shared.markupNoteFontSize
+        let noteFont = NSFont(name: noteFontName, size: noteFontSize.cgFloat)
+        self.fontWell2.font = noteFont
     }
     
     private func _initActions() {
@@ -300,6 +310,11 @@ class KMNotesPreferences: NSViewController {
         self.strikeThroughColorWell.action = #selector(strikeThroughColorWellAction)
         self.freehandColorWell.target = self
         self.freehandColorWell.action = #selector(freehandColorWellAction)
+        
+        self.fontWell1.target = self
+        self.fontWell1.action = #selector(textFontWellAction)
+        self.fontWell2.target = self
+        self.fontWell2.action = #selector(anchoredFontWellAction)
     }
     
     @objc func textColorWellAction(_ sender: NSColorWell) {
@@ -349,6 +364,19 @@ class KMNotesPreferences: NSViewController {
     @objc func freehandColorWellAction(_ sender: NSColorWell) {
         KMPreference.shared.markupPenColor = sender.color
     }
+    
+    // MARK: - Font
+    
+    @objc func textFontWellAction(_ sender: KMFontWell) {
+//        KMPrint("\(sender.fontName),\(sender.fontSize)")
+        KMPreference.shared.markupFontTextString = sender.fontName ?? ""
+        KMPreference.shared.markupTextFontSize = Float(sender.fontSize)
+    }
+    
+    @objc func anchoredFontWellAction(_ sender: KMFontWell) {
+        KMPreference.shared.markupFontNoteString = sender.fontName ?? ""
+        KMPreference.shared.markupNoteFontSize = Float(sender.fontSize)
+    }
 }
 
 extension KMNotesPreferences: KMPreferencePane {

+ 53 - 2
PDF Office/PDF Master/Class/Preference/Tools/KMPreferenceManager.swift

@@ -83,6 +83,11 @@ private let KMMarkupFontTextStringKey: KMPreferenceKey = "KMMarkupFontTextString
 private let KMMarkupFontTextAligmentKey: KMPreferenceKey = "KMMarkupFontTextAligmentKey"
 private let KMMarkupFontNoteStringKey: KMPreferenceKey = "KMMarkupFontNoteStringKey"
 
+// Tip: 新补充
+
+private let KMMarkupTextFontSizeKey: KMPreferenceKey = "KMMarkupTextFontSizeKey"
+private let KMMarkupNoteFontSizeKey: KMPreferenceKey = "KMMarkupNoteFontSizeKey"
+
 /// 偏好设置已改变
 private let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
 
@@ -166,6 +171,11 @@ typealias KMPreference = KMPreferenceManager
     public static let markupFontTextAligmentKey                 = KMMarkupFontTextAligmentKey
     public static let markupFontNoteStringKey                   = KMMarkupFontNoteStringKey
     
+    // Tip: - 新补充
+    
+    public static let markupTextFontSizeKey                     = KMMarkupTextFontSizeKey
+    public static let markupNoteFontSizeKey                     = KMMarkupNoteFontSizeKey
+    
     override init() {
         super.init()
         
@@ -341,7 +351,9 @@ typealias KMPreference = KMPreferenceManager
                     KMMarkupColorRectangleBorderKey,
                     KMMarkupFontTextStringKey,
                     KMMarkupFontTextAligmentKey,
-                    KMMarkupFontNoteStringKey]
+                    KMMarkupFontNoteStringKey,
+                    // 新补充
+                    KMMarkupTextFontSizeKey, KMMarkupNoteFontSizeKey]
         }
         return []
     }
@@ -402,7 +414,10 @@ typealias KMPreference = KMPreferenceManager
                                                          KMMarkupColorArrowKey : self.markupArrowColorValues,
                                                      KMMarkupFontTextStringKey : KMDefaultFontName,
                                                    KMMarkupFontTextAligmentKey : 0,
-                                                     KMMarkupFontNoteStringKey : KMDefaultFontName],
+                                                     KMMarkupFontNoteStringKey : KMDefaultFontName,
+                                                     // 新补充
+                                                       KMMarkupTextFontSizeKey : self.textFontSizeDefaultValue(),
+                                                       KMMarkupNoteFontSizeKey : self.noteFontSizeDefaultValue()],
                 KMPreferenceGroup.infomation.rawValue : [:],
                 KMPreferenceGroup.other.rawValue : [:]]
     }
@@ -488,6 +503,14 @@ extension KMPreferenceManager {
     @inline (__always) func invertBarDefaultValue() -> Bool {
         return false
     }
+    
+    @inline (__always) func textFontSizeDefaultValue() -> Float {
+        return 11.0
+    }
+    
+    @inline (__always) func noteFontSizeDefaultValue() -> Float {
+        return 12.0
+    }
 }
 
 //protocol KMPreferenceManagerColorPart: NSObjectProtocol {
@@ -1192,6 +1215,28 @@ extension KMPreferenceManager {
             let _ = self.setColor(newValue, forKey: KMPreference.markupColorArrowKey)
         }
     }
+    
+    var markupTextFontSize: Float {
+        get {
+            return self.getData(forKey: KMPreference.markupTextFontSizeKey) as? Float ?? self.textFontSizeDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.markupTextFontSizeKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.markupTextFontSizeKey)
+        }
+    }
+    
+    var markupNoteFontSize: Float {
+        get {
+            return self.getData(forKey: KMPreference.markupNoteFontSizeKey) as? Float ?? self.noteFontSizeDefaultValue()
+        }
+        set {
+            self.syncDataToPDFView(newValue, forKey: KMPreference.markupNoteFontSizeKey)
+            
+            _ = self.setData(data: newValue, forKey: KMPreference.markupNoteFontSizeKey)
+        }
+    }
 }
 
 // MARK: -
@@ -1312,6 +1357,12 @@ extension KMPreferenceManager {
             UserDefaults.standard.synchronize()
         } else if (key == KMMarkupFontNoteStringKey) {
 //            UserDefaults.standard.set(data, forKey: CFreeTextNoteAlignmentKey)
+//            UserDefaults.standard.synchronize()
+        } else if (key == KMMarkupTextFontSizeKey) {
+            UserDefaults.standard.set(data, forKey: CFreeTextNoteFontSizeKey)
+            UserDefaults.standard.synchronize()
+        } else if (key == KMMarkupNoteFontSizeKey) {
+//            UserDefaults.standard.set(data, forKey: CFreeTextNoteFontSizeKey)
 //            UserDefaults.standard.synchronize()
         }
     }

+ 22 - 14
PDF Office/PDF Master/Class/Preference/View/KMFontWell.swift

@@ -167,11 +167,10 @@ class KMFontWell: NSButton {
         }
     }
     
+    private var _pri_target: AnyObject?
+    private var _pri_action: Selector?
     /*
      @interface SKFontWell : NSButton {
-         id target;
-         SEL action;
-         
          NSMutableDictionary *bindingInfo;
      }
 
@@ -266,7 +265,7 @@ class KMFontWell: NSButton {
             return super.font
         }
         set {
-            let didChange = self.font?.isEqual(to: newValue) ?? false
+            let didChange = (self.font?.isEqual(to: newValue) == false)
             super.font = newValue
             if didChange {
                 self._fontChanged()
@@ -289,7 +288,25 @@ class KMFontWell: NSButton {
                 }
             }
 //            [self notifyFontBinding];
-            self.sendAction(self.action, to: self.target)
+            self.sendAction(self._pri_action, to: self._pri_target)
+        }
+    }
+    
+    override var target: AnyObject? {
+        get {
+            return self._pri_target
+        }
+        set {
+            self._pri_target = newValue
+        }
+    }
+    
+    override var action: Selector? {
+        get {
+            return self._pri_action
+        }
+        set {
+            self._pri_action = newValue
         }
     }
     
@@ -359,8 +376,6 @@ class KMFontWell: NSButton {
          }
      }
 
-
-
      - (void)changeAttributesFromFontManager:(id)sender {
          if ([self isActive] && [self hasTextColor]) {
              [self setTextColor:[[sender convertAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[self textColor], NSForegroundColorAttributeName, nil]] valueForKey:NSForegroundColorAttributeName]];
@@ -372,11 +387,8 @@ class KMFontWell: NSButton {
      #pragma mark Accessors
 
      - (SEL)action { return action; }
-
      - (void)setAction:(SEL)newAction { action = newAction; }
-
      - (id)target { return target; }
-
      - (void)setTarget:(id)newTarget { target = newTarget; }
 
      #pragma mark Binding support
@@ -512,11 +524,7 @@ class KMFontWell: NSButton {
      }
 
      @end
-
-
-     
      */
-    
 }
 
 // MARK: - Private Methods