Переглянути джерело

Merge branch 'develop_PDFReaderProNew' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderProNew

# Conflicts:
#	PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift
liujiajie 11 місяців тому
батько
коміт
96e014ce16
50 змінених файлів з 2424 додано та 1582 видалено
  1. 51 1
      PDF Office/PDF Master/AppDelegate.swift
  2. 10 8
      PDF Office/PDF Master/Class/Batch/Data/KMBackgroundObject.swift
  3. 2 2
      PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateBaseWindowController.swift
  4. 2 2
      PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateRightViewController.swift
  5. 2 2
      PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateSplitViewController.swift
  6. 3 3
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/Model/KMBatchAddHeaderFooterOperation.swift
  7. 2 2
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/KMHeaderFooterWindowController.swift
  8. 29 29
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/View/KMHeaderFooterView.swift
  9. 38 38
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/VC/KMBatchOperateAddHeaderFooterViewController.swift
  10. 1 1
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/View/KMHeaderFooterTableCellView.swift
  11. 8 8
      PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/WindowComtroller/KMHeaderFooterManagerWindowController.swift
  12. 7 2
      PDF Office/PDF Master/Class/PDFTools/Background/New/View/KMAddBackgroundView.swift
  13. 140 29
      PDF Office/PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift
  14. 1 1
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPreviewController.swift
  15. 7 7
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyInfoController.swift
  16. 4 0
      PDF Office/PDF Master/Class/PDFTools/Bates/Model/KMBatesModel.swift
  17. 4 4
      PDF Office/PDF Master/Class/PDFTools/Bates/Tools/KMBatesManager.swift
  18. 97 5
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Base/KMHeaderFooterAdjectiveModel.swift
  19. 4 4
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMCreateHeaderFooterController.swift
  20. 5 5
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPreviewController.swift
  21. 10 11
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyController.swift
  22. 6 6
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyInfoController.swift
  23. 11 13
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyMainController.swift
  24. 52 22
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Model/KMHeaderFooterModel.swift
  25. 2 2
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMDataVersionManager.swift
  26. 747 369
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMHeaderFooterManager.swift
  27. 1 1
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/View/KMHeaderFooterDateInfoView.swift
  28. 4 4
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/View/KMHeaderFooterMarginInfoView.swift
  29. 7 7
      PDF Office/PDF Master/Class/PDFTools/PageEdit/Base/KMPageEditSettingBaseModel.swift
  30. 2 2
      PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift
  31. 0 370
      PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController_dmg.swift
  32. 1 4
      PDF Office/PDF Master/Class/PDFTools/PageEdit/Model/KMPageEditSplitSettingModel.swift
  33. 3 1
      PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPDFEditToolbar.swift
  34. 5 5
      PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPageEditInsertTypeItemView.swift
  35. 2 0
      PDF Office/PDF Master/Class/PDFTools/Watermark/Base/KMWatermarkAdjectiveBaseModel.swift
  36. 2 2
      PDF Office/PDF Master/Class/PDFTools/Watermark/OCPart/KMWatermarkPDFView_OC.m
  37. 10 10
      PDF Office/PDF Master/Class/PDFTools/Watermark/Tools/KMWatermarkAdjectiveTools.swift
  38. 20 20
      PDF Office/PDF Master/Class/PDFTools/Watermark/View/KMWatermarkPDFView.swift
  39. 0 51
      PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/Base/KMPDFThumbViewBaseController.swift
  40. 29 21
      PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailView.swift
  41. 14 14
      PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.swift
  42. 75 67
      PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift
  43. 19 17
      PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarItemView.swift
  44. 15 21
      PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarView.swift
  45. 51 50
      PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift
  46. 2 6
      PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift
  47. 5 0
      PDF Office/PDF Master/Class/README.md
  48. 8 12
      PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj
  49. 128 0
      PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  50. 776 321
      PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+ 51 - 1
PDF Office/PDF Master/AppDelegate.swift

@@ -6,6 +6,7 @@
 //
 
 import Cocoa
+import UserNotifications
 
 @main
 class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
@@ -34,6 +35,47 @@ class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
     func applicationDidFinishLaunching(_ aNotification: Notification) {
         // Insert code here to initialize your application
         
+        //通知
+        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
+            if granted {
+                print("User authorized notifications")
+            } else {
+                print("User denied notifications")
+            }
+        }
+
+        /**本地推送测试
+         UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
+             if granted {
+                 // 创建本地推送通知
+                 let content = UNMutableNotificationContent()
+                 content.title = "Test Notification"
+                 content.body = "This is a test notification!"
+                 
+                 // 触发条件,例如延迟 5 秒触发
+                 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
+                 
+                 // 创建通知请求
+                 let request = UNNotificationRequest(identifier: "LocalNotification", content: content, trigger: trigger)
+                 
+                 // 添加通知请求到用户通知中心
+                 UNUserNotificationCenter.current().add(request) { error in
+                     if let error = error {
+                         print("Error adding notification request: \(error)")
+                     } else {
+                         print("Local notification scheduled")
+                     }
+                 }
+             } else {
+                 print("User denied notifications")
+             }
+         }
+         **/
+        
+        DispatchQueue.main.async {
+            NSApplication.shared.registerForRemoteNotifications()
+        }
+        
 #if VERSION_DMG
         let updater = SUUpdater.shared()
         updater?.delegate = self
@@ -256,7 +298,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
 
     
     func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
-        
+        let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
+        print("Device token:", token)
     }
     
     func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
@@ -861,3 +904,10 @@ extension AppDelegate {
         }
     }
 }
+
+extension AppDelegate: UNUserNotificationCenterDelegate {
+    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+        // 处理用户点击推送通知的操作
+        completionHandler()
+    }
+}

+ 10 - 8
PDF Office/PDF Master/Class/Batch/Data/KMBackgroundObject.swift

@@ -13,9 +13,9 @@ import Cocoa
     var imagePath: String?
     
     var rotation: Int = 0
-    var opacity: CGFloat = 0
+    var opacity: Double = 0
     
-    var scale: CGFloat = 0
+    var scale: Double = 0
     
     // (Top:0 Middle:1 Bottom:2)
     var verticalMode: Int = 0
@@ -31,11 +31,13 @@ import Cocoa
     private var _image: NSImage?
     var image: NSImage? {
         set {
-            self.image = newValue
+            self._image = newValue
         }
         get {
             if let data = self.imagePath, FileManager.default.fileExists(atPath: data) {
-                return NSImage(contentsOfFile: data)
+                if let img = NSImage(contentsOfFile: data) {
+                    return img
+                }
             }
             return self._image
         }
@@ -46,14 +48,14 @@ import Cocoa
     }
     
     required init?(coder: NSCoder) {
-        super.init()
+//        super.init()
         
         self.type = KMBackgroundType(rawValue: coder.decodeInteger(forKey: "type")) ?? .color
         self.color = coder.decodeObject(forKey: "color") as? NSColor ?? .clear
         self.imagePath = coder.decodeObject(forKey: "imagePath") as? String ?? ""
         self.rotation = coder.decodeInteger(forKey: "rotation")
-        self.opacity = CGFloat(coder.decodeFloat(forKey: "opacity"))
-        self.scale = CGFloat(coder.decodeFloat(forKey: "scale"))
+        self.opacity = coder.decodeDouble(forKey: "opacity")
+        self.scale = coder.decodeDouble(forKey: "scale")
         self.verticalMode = coder.decodeInteger(forKey: "verticalMode")
         self.verticalSpace = coder.decodeInteger(forKey: "verticalSpace")
         self.horizontalMode = coder.decodeInteger(forKey: "horizontalMode")
@@ -61,7 +63,7 @@ import Cocoa
         self.pagesString = coder.decodeObject(forKey: "pagesString") as? String ?? ""
         self.pageRangeType = KMBatchOperatePageChoice(rawValue: coder.decodeInteger(forKey: "pageRangeType")) ?? .All
         self.backgroundID = coder.decodeObject(forKey: "backgroundID") as? String ?? ""
-        self.image = coder.decodeObject(forKey: "image") as? NSImage
+        self._image = coder.decodeObject(forKey: "image") as? NSImage
     }
     
     //拷贝其他数据的值

+ 2 - 2
PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateBaseWindowController.swift

@@ -77,10 +77,10 @@ import Cocoa
     func backgroundInterfaceSelectBackGround(background: KMBackgroundModel) {
         (self.contentViewController as! KMBatchOperateSplitViewController).backgroundInterfaceSelectBackground(background)
     }
-    func headerFooterInterfaceSelectHeaderFooter(headerFooter: KMHeaderFooterModel) {
+    func headerFooterInterfaceSelectHeaderFooter(headerFooter: KMHeaderFooterObject) {
         (self.contentViewController as! KMBatchOperateSplitViewController).headerFooterInterfaceSelectHeaderFooter(headerFooter)
     }
-    func batesInterfaceSelectBates(headerFooter: KMHeaderFooterModel) {
+    func batesInterfaceSelectBates(headerFooter: KMHeaderFooterObject) {
         (self.contentViewController as! KMBatchOperateSplitViewController).headerFooterInterfaceSelectHeaderFooter(headerFooter)
     }
     

+ 2 - 2
PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateRightViewController.swift

@@ -201,13 +201,13 @@ class KMBatchOperateRightViewController: NSViewController{
         }
     }
     
-    func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterModel) {
+    func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterObject) {
         if self.currentType == .AddHeaderFooter {
             self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
         }
     }
     
-    func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterModel) {
+    func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterObject) {
         if self.currentType == .AddBates {
             self.addHeaderFooterViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter: headerFooter)
         }

+ 2 - 2
PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateSplitViewController.swift

@@ -54,10 +54,10 @@ class KMBatchOperateSplitViewController: NSSplitViewController{
     func backgroundInterfaceSelectBackground(_ background: KMBackgroundModel) {
         self.rightPropertiesViewController?.backgroundInterfaceSelectBackground(background)
     }
-    func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterModel) {
+    func headerFooterInterfaceSelectHeaderFooter(_ headerFooter: KMHeaderFooterObject) {
         self.rightPropertiesViewController?.headerFooterInterfaceSelectHeaderFooter(headerFooter)
     }
-    func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterModel) {
+    func batesInterfaceSelectBates(_ headerFooter: KMHeaderFooterObject) {
         self.rightPropertiesViewController?.batesInterfaceSelectBates(headerFooter)
     }
 }

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/Model/KMBatchAddHeaderFooterOperation.swift

@@ -12,11 +12,11 @@ let mainBundleIdentifier = Bundle.main.bundleIdentifier ?? ""
 let kTempSavePath = supportDirectory?.stringByAppendingPathComponent(mainBundleIdentifier)
 
 class KMBatchAddHeaderFooterOperation: KMBatchOperation{
-    var headerFooter: KMHeaderFooterModel?
+    var headerFooter: KMHeaderFooterObject?
     var pdfDocument: CPDFDocument?
     var password: String?
     
-    init(file: KMBatchOperateFile, headerFooter: KMHeaderFooterModel) {
+    init(file: KMBatchOperateFile, headerFooter: KMHeaderFooterObject) {
         super.init(file: file)
         self.headerFooter = headerFooter
         
@@ -270,7 +270,7 @@ func convertPageFormat(oldString: String, startPage: String, pageCount: String)
 }
 func convertDateFormat(oldString: String) -> String { 
     var newString = oldString
-    for dateFormat in KMHeaderFooterManager.defaultManager.dateFormatArray {
+    for dateFormat in KMHeaderFooterManager.defaultManager().dateFormatArray {
         if newString.contains(dateFormat) {
             let formatString = dateFormat.replacingOccurrences(of: "m", with: "M")
             let replace = "<<\(dateFormat)>>"

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/KMHeaderFooterWindowController.swift

@@ -7,12 +7,12 @@
 
 import Cocoa
 
-typealias KMHeaderFooterWindowControllerOperateCallBack = (_ controller: NSWindowController, _ headerFooter: KMHeaderFooterModel) -> ()
+typealias KMHeaderFooterWindowControllerOperateCallBack = (_ controller: NSWindowController, _ headerFooter: KMHeaderFooterObject) -> ()
 
 class KMHeaderFooterWindowController: KMBaseWindowController {
     @IBOutlet weak var headerFooterView: KMHeaderFooterView!
 
-    var headerFooterObj: KMHeaderFooterModel = KMHeaderFooterModel()
+    var headerFooterObj: KMHeaderFooterObject = KMHeaderFooterObject()
     var type: KMBatchModifyTemplateType = .Use
     var operateCallBack: KMHeaderFooterWindowControllerOperateCallBack?
     

+ 29 - 29
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/View/KMHeaderFooterView.swift

@@ -87,7 +87,7 @@ func convertDateFormat(_ oldString: String) -> String {
     return newString
 }
 
-typealias KMHeaderFooterViewDoneAction = ( _ model: KMHeaderFooterModel) -> ()
+typealias KMHeaderFooterViewDoneAction = ( _ model: KMHeaderFooterObject) -> ()
 typealias KMHeaderFooterViewCancelAction = (_ view: KMHeaderFooterView) -> Void
 
 class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate {
@@ -186,11 +186,11 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
             self.reloadData()
         }
     }
-    var headerFooterObj: KMHeaderFooterModel = KMHeaderFooterModel()
-    var originalHeaderFooterObj: KMHeaderFooterModel = KMHeaderFooterModel()
+    var headerFooterObj: KMHeaderFooterObject = KMHeaderFooterObject()
+    var originalHeaderFooterObj: KMHeaderFooterObject = KMHeaderFooterObject()
     var dateFormatArray: [Any] {
         get {
-            return KMHeaderFooterManager.defaultManager.dateFormatArray
+            return KMHeaderFooterManager.defaultManager().dateFormatArray
         }
     }
     
@@ -198,9 +198,9 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
     var isBates: Bool = false {
         didSet {
             if (self.isBates) {
-                headerFooterObj.id = KMHeaderFooterManager.defaultManager.fetchBatesAvailableName()
+                headerFooterObj.id = KMHeaderFooterManager.defaultManager().fetchBatesAvailableName()
             } else {
-                headerFooterObj.id = KMHeaderFooterManager.defaultManager.fetchHeaderFooterAvailableName()
+                headerFooterObj.id = KMHeaderFooterManager.defaultManager().fetchHeaderFooterAvailableName()
             }
             headerFooterObj.isBates = self.isBates
             self.reloadData()
@@ -216,12 +216,12 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
         NotificationCenter.default.removeObserver(self)
     }
     
-    convenience init?(baseFile filePath: String, headerFooter object: KMHeaderFooterModel, password: String, type: KMBatchModifyTemplateType) {
+    convenience init?(baseFile filePath: String, headerFooter object: KMHeaderFooterObject, password: String, type: KMBatchModifyTemplateType) {
         self.init()
         
         self.filePath = filePath
         self.password = password
-        self.headerFooterObj = object.copy() as! KMHeaderFooterModel
+        self.headerFooterObj = object.copy() as! KMHeaderFooterObject
         self.originalHeaderFooterObj = object
         self.initialID = object.id
 
@@ -746,10 +746,10 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
 
             if self.isBates {
                 if let bates = document?.bates() {
-                    bates.margin = NSEdgeInsets(top: max(self.headerFooterObj.topMargin - size.height, 0),
-                                                left: self.headerFooterObj.leftMargin,
-                                                bottom: max(self.headerFooterObj.bottomMargin - size.height, 0),
-                                                right: self.headerFooterObj.rightMargin)
+                    bates.margin = NSEdgeInsets(top: max(CGFloat(self.headerFooterObj.topMargin) - size.height, 0),
+                                                left: CGFloat(self.headerFooterObj.leftMargin),
+                                                bottom: max(CGFloat(self.headerFooterObj.bottomMargin) - size.height, 0),
+                                                right: CGFloat(self.headerFooterObj.rightMargin))
                     let pagesString = self.headerFooterObj.pageRangeString
                     if  pagesString.count != 0 {
                         bates.pageString = pagesString
@@ -777,10 +777,10 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
             } else {
                 print(document?.headerFooter())
                 if let headerFooter = document?.headerFooter() {
-                    headerFooter.margin = NSEdgeInsets(top: max(self.headerFooterObj.topMargin - size.height, 0),
-                                                       left: self.headerFooterObj.leftMargin,
-                                                       bottom: max(self.headerFooterObj.bottomMargin - size.height, 0),
-                                                       right: self.headerFooterObj.rightMargin)
+                    headerFooter.margin = NSEdgeInsets(top: max(CGFloat(self.headerFooterObj.topMargin) - size.height, 0),
+                                                       left: CGFloat(self.headerFooterObj.leftMargin),
+                                                       bottom: max(CGFloat(self.headerFooterObj.bottomMargin) - size.height, 0),
+                                                       right: CGFloat(self.headerFooterObj.rightMargin))
 
                     let pagesString = self.headerFooterObj.pageRangeString
                     if  pagesString.count != 0 {
@@ -1038,49 +1038,49 @@ extension KMHeaderFooterView {
 
     @IBAction func topMarginTextFiedEndEdit(_ sender: NSTextField) {
         topMarginStepper.integerValue = sender.integerValue
-        headerFooterObj.topMargin = CGFloat(sender.integerValue)
+        headerFooterObj.topMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func topMarginStepperAction(_ sender: NSStepper) {
         topMargintextField.integerValue = sender.integerValue
-        headerFooterObj.topMargin = CGFloat(sender.integerValue)
+        headerFooterObj.topMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func bottomMarginTextFieldEndEdit(_ sender: NSTextField) {
         bottomMarginStepper.integerValue = sender.integerValue
-        headerFooterObj.bottomMargin = CGFloat(sender.integerValue)
+        headerFooterObj.bottomMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func bottomMarginStepperAction(_ sender: NSStepper) {
         bottomMarginTextField.integerValue = sender.integerValue
-        headerFooterObj.bottomMargin = CGFloat(sender.integerValue)
+        headerFooterObj.bottomMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func leftMarginTextFieldEndEdit(_ sender: NSTextField) {
         leftMarginStepper.integerValue = sender.integerValue
-        headerFooterObj.leftMargin = CGFloat(sender.integerValue)
+        headerFooterObj.leftMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func leftMarginStepperAction(_ sender: NSStepper) {
         leftMarginTextField.integerValue = sender.integerValue
-        headerFooterObj.leftMargin = CGFloat(sender.integerValue)
+        headerFooterObj.leftMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func rightMarginTextFieldEndEdit(_ sender: NSTextField) {
         rightMarginStepper.integerValue = sender.integerValue
-        headerFooterObj.rightMargin = CGFloat(sender.integerValue)
+        headerFooterObj.rightMargin = sender.integerValue
         self.updatePDFView()
     }
 
     @IBAction func rightMarginStepperAction(_ sender: NSStepper) {
         rightMarginTextField.integerValue = sender.integerValue
-        headerFooterObj.rightMargin = CGFloat(sender.integerValue)
+        headerFooterObj.rightMargin = sender.integerValue
         self.updatePDFView()
     }
 
@@ -1118,7 +1118,7 @@ extension KMHeaderFooterView {
             }
             
             headerFooterObj.id = templateNameTextField.stringValue
-            KMHeaderFooterManager.defaultManager.addTemplate(headerFooterObj)
+            KMHeaderFooterManager.defaultManager().addHeaderFooter(headerFooterObj)
         }
         
         if let operateCallBack = operateCallBack {
@@ -1182,7 +1182,7 @@ extension KMHeaderFooterView {
                 } else {
                     headerFooterObj.id = templateNameTextField.stringValue
                 }
-                KMHeaderFooterManager.defaultManager.addTemplate(headerFooterObj)
+                KMHeaderFooterManager.defaultManager().addHeaderFooter(headerFooterObj)
             }
             if let operateCallBack = operateCallBack {
                 operateCallBack(headerFooterObj)
@@ -1195,8 +1195,8 @@ extension KMHeaderFooterView {
                     headerFooterObj.id = templateNameTextField.stringValue
                 }
                 
-                originalHeaderFooterObj = headerFooterObj.copy() as! KMHeaderFooterModel
-                KMHeaderFooterManager.defaultManager.store()
+                originalHeaderFooterObj = headerFooterObj.copy() as! KMHeaderFooterObject
+                KMHeaderFooterManager.defaultManager().store()
             }
             if let operateCallBack = operateCallBack {
                 operateCallBack(originalHeaderFooterObj)
@@ -1225,7 +1225,7 @@ extension KMHeaderFooterView {
                         } else {
                             self.headerFooterObj.id = self.templateNameTextField.stringValue
                         }
-                        KMHeaderFooterManager.defaultManager.addTemplate(self.headerFooterObj)
+                        KMHeaderFooterManager.defaultManager().addHeaderFooter(self.headerFooterObj)
                         NotificationCenter.default.post(name: NSNotification.Name("KMBatchOperateHeaderFootersNotification"), object: self)
                     }
                 }

+ 38 - 38
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/VC/KMBatchOperateAddHeaderFooterViewController.swift

@@ -29,7 +29,7 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     
     @IBOutlet var lineView: NSView!
     var haveFiles = false
-    var currentObject: KMHeaderFooterModel?
+    var currentObject: KMHeaderFooterObject?
     
     override var interfaceStatus: KMBatchOperateInterfaceStatus?{
         set{
@@ -244,12 +244,12 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     }
     func deleteAll() {
         if self.isBates {
-            for waterMark in KMHeaderFooterManager.defaultManager.onlyBatesObjects() {
-                KMHeaderFooterManager.defaultManager.removeHeaderFooter(waterMark)
+            for waterMark in KMHeaderFooterManager.defaultManager().onlyBatesObjects {
+                KMHeaderFooterManager.defaultManager().removeHeaderFooter(waterMark)
             }
         } else {
-            for waterMark in KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects() {
-                KMHeaderFooterManager.defaultManager.removeHeaderFooter(waterMark)
+            for waterMark in KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects {
+                KMHeaderFooterManager.defaultManager().removeHeaderFooter(waterMark)
             }
         }
         loadData()
@@ -259,15 +259,15 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     func reloadTable() {
         self.tableView.noteNumberOfRowsChanged()
         var count = 0
-        var array: [KMHeaderFooterModel] = []
+        var array: [KMHeaderFooterObject] = []
         if self.isBates {
-            count = KMHeaderFooterManager.defaultManager.onlyBatesObjects().count
-            array = KMHeaderFooterManager.defaultManager.onlyBatesObjects()
+            count = KMHeaderFooterManager.defaultManager().onlyBatesObjects.count
+            array = KMHeaderFooterManager.defaultManager().onlyBatesObjects
         } else {
-            count = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects().count
-            array = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()
+            count = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects.count
+            array = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects
         }
-        if array.contains(self.currentObject ?? KMHeaderFooterModel()) {
+        if array.contains(self.currentObject ?? KMHeaderFooterObject()) {
             let row = array.firstIndex(of: self.currentObject!)!
             let indexSet = IndexSet(integer: row)
             self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
@@ -333,16 +333,16 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
         }
         if (self.onlyManagerTemplate) {
             if (sender.tag == 1) {
-                var headFooter: KMHeaderFooterModel?
+                var headFooter: KMHeaderFooterObject?
                 let row = self.tableView.selectedRow
                 if (row == -1) {
                     NSSound.beep()
                     return
                 } else {
                     if (self.isBates) {
-                        headFooter = KMHeaderFooterManager.defaultManager.onlyBatesObjects()[row]
+                        headFooter = KMHeaderFooterManager.defaultManager().onlyBatesObjects[row]
                     } else {
-                        headFooter = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()[row]
+                        headFooter = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects[row]
                     }
                 }
 
@@ -400,16 +400,16 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
                     NSSound.beep()
                     return;
                 }
-                var headFooter: KMHeaderFooterModel?
+                var headFooter: KMHeaderFooterObject?
                 let row = self.tableView.selectedRow
                 if (row == -1 || self.files?.count ?? 0 < 1) {
                     NSSound.beep()
                     return;
                 } else {
                     if (self.isBates) {
-                        headFooter = KMHeaderFooterManager.defaultManager.onlyBatesObjects()[row]
+                        headFooter = KMHeaderFooterManager.defaultManager().onlyBatesObjects[row]
                     } else {
-                        headFooter = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()[row]
+                        headFooter = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects[row]
                     }
                 }
                 
@@ -448,15 +448,15 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
                 for fileURL in openPanel.urls {
                     self.choosePath = fileURL.path
                     if self.isBates {
-                        self.beginAddBates(obj as! KMHeaderFooterModel)
+                        self.beginAddBates(obj as! KMHeaderFooterObject)
                     } else {
-                        self.beginAddHeaderFooter(obj as! KMHeaderFooterModel)
+                        self.beginAddHeaderFooter(obj as! KMHeaderFooterObject)
                     }
                 }
             }
         }
     }
-    func beginAddBates(_ bates: KMHeaderFooterModel) {
+    func beginAddBates(_ bates: KMHeaderFooterObject) {
         hiddenWindowCloseButtonIfNeeded()
         successFilePathURLArray?.removeAll()
         for i in 0..<(files?.count ?? 0) {
@@ -475,7 +475,7 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
             interfaceStatus = .Processing
         }
     }
-    func beginAddHeaderFooter(_ headerFooter: KMHeaderFooterModel) {
+    func beginAddHeaderFooter(_ headerFooter: KMHeaderFooterObject) {
         hiddenWindowCloseButtonIfNeeded()
         successFilePathURLArray?.removeAll()
         for i in 0..<(files?.count ?? 0) {
@@ -494,7 +494,7 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
             interfaceStatus = .Processing
         }
     }
-    func modify(obj: KMHeaderFooterModel) {
+    func modify(obj: KMHeaderFooterObject) {
 //        let windowController = self.view.window?.windowController
 //        var filePath: String? = nil
 //        var password: String? = nil
@@ -541,8 +541,8 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
         self.km_beginSheet(windowC: windowController)
         
     }
-    func delete(obj: KMHeaderFooterModel) {
-        KMHeaderFooterManager.defaultManager.removeHeaderFooter(obj)
+    func delete(obj: KMHeaderFooterObject) {
+        KMHeaderFooterManager.defaultManager().removeHeaderFooter(obj)
         loadData()
         reloadTable()
         postNotification()
@@ -550,23 +550,23 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
         let action = menuItem.action
         if action == #selector(buttonItemClick_CleanAll(_:)) {
-            if (self.isBates && KMHeaderFooterManager.defaultManager.onlyBatesObjects().count < 1) || (!self.isBates && KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects().count < 1){
+            if (self.isBates && KMHeaderFooterManager.defaultManager().onlyBatesObjects.count < 1) || (!self.isBates && KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects.count < 1){
                 return false
             }
             return true
         }
         return true
     }
-    func headerFooterInterfaceSelectHeaderFooter(headerFooter: KMHeaderFooterModel) {
+    func headerFooterInterfaceSelectHeaderFooter(headerFooter: KMHeaderFooterObject) {
         self.tableView.reloadData()
-        if let index = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects().firstIndex(of: headerFooter) {
+        if let index = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects.firstIndex(of: headerFooter) {
             let indexSet = IndexSet(integer: index)
             self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
         }
     }
-    func batesInterfaceSelectBates(headerFooter: KMHeaderFooterModel) {
+    func batesInterfaceSelectBates(headerFooter: KMHeaderFooterObject) {
         self.tableView.reloadData()
-        if let index = KMHeaderFooterManager.defaultManager.onlyBatesObjects().firstIndex(of: headerFooter) {
+        if let index = KMHeaderFooterManager.defaultManager().onlyBatesObjects.firstIndex(of: headerFooter) {
             let indexSet = IndexSet(integer: index)
             self.tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
         }
@@ -575,19 +575,19 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     func numberOfRows(in tableView: NSTableView) -> Int {
         var count = 0
         if self.isBates {
-            count = KMHeaderFooterManager.defaultManager.onlyBatesObjects().count
+            count = KMHeaderFooterManager.defaultManager().onlyBatesObjects.count
         } else {
-            count = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects().count
+            count = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects.count
         }
         self.blankView.isHidden = count != 0
         return count
     }
     func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
-        var obj: KMHeaderFooterModel? = nil
+        var obj: KMHeaderFooterObject? = nil
         if self.isBates {
-            obj = KMHeaderFooterManager.defaultManager.onlyBatesObjects()[row]
+            obj = KMHeaderFooterManager.defaultManager().onlyBatesObjects[row]
         } else {
-            obj = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()[row]
+            obj = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects[row]
         }
         guard let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "mainCell"), owner: self) as? KMHeaderFooterTableCellView else {
             return nil
@@ -612,9 +612,9 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
     }
     func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { 
         if self.isBates {
-            return KMHeaderFooterManager.defaultManager.onlyBatesObjects()[row].cellHeight
+            return KMHeaderFooterManager.defaultManager().onlyBatesObjects[row].cellHeight
         } else {
-            return KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()[row].cellHeight
+            return KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects[row].cellHeight
         }
     }
     func tableView(_ tableView: NSTableView, shouldSelect tableColumn: NSTableColumn?) -> Bool {
@@ -628,7 +628,7 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
         updateActionButtonbackgroundColor()
         if row == -1 { return }
         if self.isBates {
-            let bates = KMHeaderFooterManager.defaultManager.onlyBatesObjects()[row]
+            let bates = KMHeaderFooterManager.defaultManager().onlyBatesObjects[row]
             self.currentObject = bates
             for i in 0..<(self.files?.count ?? 0) {
                 let file = self.files?[i]
@@ -644,7 +644,7 @@ class KMBatchOperateAddHeaderFooterViewController: KMBatchOperateBaseViewControl
                 }
             }
         } else {
-            let headerFooter = KMHeaderFooterManager.defaultManager.onlyHeaderFooterObjects()[row]
+            let headerFooter = KMHeaderFooterManager.defaultManager().onlyHeaderFooterObjects[row]
             self.currentObject = headerFooter
             for i in 0..<(self.files?.count ?? 0) {
                 let file = self.files?[i]

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/View/KMHeaderFooterTableCellView.swift

@@ -78,7 +78,7 @@ class KMHeaderFooterTableCellView: NSTableCellView {
         var appendString = string
         return appendString
     }
-    func updateInterface(_ obj: KMHeaderFooterModel) { 
+    func updateInterface(_ obj: KMHeaderFooterObject) { 
         var arr = NSMutableArray()
         if obj.topLeftString.count > 0 {
             arr.add(appendBaseString(NSLocalizedString("Left Header Text", comment: ""), withString: appendBaseString(obj.topLeftString)))

+ 8 - 8
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/WindowComtroller/KMHeaderFooterManagerWindowController.swift

@@ -7,7 +7,7 @@
 
 import Cocoa
 
-typealias HeaderFooterOperateCallBack = (_ obj: KMHeaderFooterModel) -> ()
+typealias HeaderFooterOperateCallBack = (_ obj: KMHeaderFooterObject) -> ()
 
 class KMHeaderFooterManagerWindowController: NSWindowController{
     var operateCallBack: HeaderFooterOperateCallBack?
@@ -21,20 +21,20 @@ class KMHeaderFooterManagerWindowController: NSWindowController{
     var password: String = ""
     var type:KMBatchModifyTemplateType = .Add
     var pdfdocument: CPDFDocument?
-    lazy var headerFooterObj: KMHeaderFooterModel? = {
-        let obj = KMHeaderFooterModel()
+    lazy var headerFooterObj: KMHeaderFooterObject? = {
+        let obj = KMHeaderFooterObject()
         obj.isBates = self.isBates
         if self.isBates {
-            obj.id = KMHeaderFooterManager.defaultManager.fetchBatesAvailableName()
+            obj.id = KMHeaderFooterManager.defaultManager().fetchBatesAvailableName()
         }else {
-            obj.id = KMHeaderFooterManager.defaultManager.fetchHeaderFooterAvailableName()
+            obj.id = KMHeaderFooterManager.defaultManager().fetchHeaderFooterAvailableName()
         }
         initialID = obj.id
         return obj
     }()
-    var originalHeaderFooterObj: KMHeaderFooterModel?
+    var originalHeaderFooterObj: KMHeaderFooterObject?
     lazy var dateFormatArray: Array<Any> = {
-        let arr = KMHeaderFooterManager.defaultManager.dateFormatArray
+        let arr = KMHeaderFooterManager.defaultManager().dateFormatArray
         return arr
     }()
     var initialID: String?
@@ -121,7 +121,7 @@ class KMHeaderFooterManagerWindowController: NSWindowController{
         DistributedNotificationCenter.default().removeObserver(self)
     }
     
-    convenience init(baseFile:String, obj:KMHeaderFooterModel, password:String, type:KMBatchModifyTemplateType) {
+    convenience init(baseFile:String, obj:KMHeaderFooterObject, password:String, type:KMBatchModifyTemplateType) {
         self.init(windowNibName: "KMHeaderFooterManagerWindowController")
         self.filePath = baseFile
         self.password = password

+ 7 - 2
PDF Office/PDF Master/Class/PDFTools/Background/New/View/KMAddBackgroundView.swift

@@ -428,8 +428,13 @@ class KMAddBackgroundView: KMBaseXibView, NSComboBoxDelegate {
             tBackground.type = .color
         }
         if background.imagePath.count != 0 {
-            let image = NSImage(contentsOfFile: background.imagePath)!
-            tBackground.setImage(image)
+            if let data = background.image {
+                tBackground.setImage(data)
+            } else {
+                if let image = NSImage(contentsOfFile: background.imagePath) {
+                    tBackground.setImage(image)
+                }
+            }
             tBackground.type = .image
         }
 

+ 140 - 29
PDF Office/PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift

@@ -7,48 +7,73 @@
 
 import Cocoa
 
-class KMBackgroundManager: NSObject {
+class KMBackgroundManager: NSObject, NSCoding {
     let kBackgroundFolderPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("background")
     let kBackgroundPlistPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("background").stringByAppendingPathComponent("background.plist")
     
     var datas: Array<KMBackgroundModel> = []
     
+    var backgroundObjects: [KMBackgroundObject] = []
+    
     static let defaultManager = KMBackgroundManager()
     
     override init() {
         super.init()
-        if (FileManager.default.fileExists(atPath: kBackgroundPlistPath!)) {
-            let dataDict = NSDictionary(contentsOfFile: kBackgroundPlistPath!)
-            if (dataDict == nil) {
-                return
-            }
-            var deleteKeys: Array<String> = []
-            for keyIndex in 0 ..< (dataDict?.allKeys.count)! {
-                let key: String = dataDict?.allKeys[keyIndex] as! String
-                let backgroundDict: NSDictionary = dataDict?.object(forKey: key) as! NSDictionary
-                
-                let model = parseDictionary(dict: backgroundDict)
-                /// 赋值id
-                model.backgroundID = key
-                if (model.type == .file) {
-                    if (model.image == nil) {
-                        deleteKeys.append(key)
-                    } else {
-                        self.datas.append(model)
-                    }
-                } else {
+        
+        if let storedData = UserDefaults.standard.value(forKey: "kBackgroundInfoSaveKey") as? Data {
+            NSKeyedUnarchiver.setClass(KMBackgroundObject.self, forClassName: "KMBackgroundObject")
+            NSKeyedUnarchiver.setClass(KMBackgroundManager.self, forClassName: "KMBackgroundManager")
+            if let man = NSKeyedUnarchiver.unarchiveObject(with: storedData) as? KMBackgroundManager {
+                for object in man.backgroundObjects {
+                    let model = self.parseObject(object: object)
                     self.datas.append(model)
+                    self.backgroundObjects.append(object)
                 }
             }
-            
-            if (deleteKeys.count > 0) {
-                let newDict: NSMutableDictionary = NSMutableDictionary(dictionary: dataDict!)
-                for key in deleteKeys {
-                    newDict.removeObject(forKey: key)
-                }
-                newDict.write(toFile: kBackgroundPlistPath!, atomically: true)
-            }
         }
+        
+//        if (FileManager.default.fileExists(atPath: kBackgroundPlistPath!)) {
+//            let dataDict = NSDictionary(contentsOfFile: kBackgroundPlistPath!)
+//            if (dataDict == nil) {
+//                return
+//            }
+//            var deleteKeys: Array<String> = []
+//            for keyIndex in 0 ..< (dataDict?.allKeys.count)! {
+//                let key: String = dataDict?.allKeys[keyIndex] as! String
+//                let backgroundDict: NSDictionary = dataDict?.object(forKey: key) as! NSDictionary
+//
+//                let model = parseDictionary(dict: backgroundDict)
+//                /// 赋值id
+//                model.backgroundID = key
+//                if (model.type == .file) {
+//                    if (model.image == nil) {
+//                        deleteKeys.append(key)
+//                    } else {
+//                        self.datas.append(model)
+//                    }
+//                } else {
+//                    self.datas.append(model)
+//                }
+//            }
+//
+//            if (deleteKeys.count > 0) {
+//                let newDict: NSMutableDictionary = NSMutableDictionary(dictionary: dataDict!)
+//                for key in deleteKeys {
+//                    newDict.removeObject(forKey: key)
+//                }
+//                newDict.write(toFile: kBackgroundPlistPath!, atomically: true)
+//            }
+//        }
+    }
+    
+    required init?(coder: NSCoder) {
+        if let data = coder.decodeObject(forKey: "backgroundObjects") {
+            self.backgroundObjects = data as? [KMBackgroundObject] ?? []
+        }
+    }
+    
+    func encode(with coder: NSCoder) {
+        coder.encode(self.backgroundObjects, forKey: "backgroundObjects")
     }
     
     func addTemplate(model: KMBackgroundModel) -> Bool {
@@ -95,6 +120,9 @@ class KMBackgroundManager: NSObject {
             }
         }
         
+        let obj = self.parseModeForObject(model)
+        self._addBackground(obj)
+        
         return result
     }
     
@@ -129,6 +157,10 @@ class KMBackgroundManager: NSObject {
                 self.datas.removeObject(model)
             }
         }
+        
+        let obj = self.parseModeForObject(model)
+        self._removeBackground(obj)
+        
         return result
     }
     
@@ -152,6 +184,8 @@ class KMBackgroundManager: NSObject {
             self.datas.removeAll()
         }
         
+        self._clearStored()
+        
         return result
     }
     
@@ -185,6 +219,8 @@ class KMBackgroundManager: NSObject {
             }
         }
         
+        self._clearStored()
+        
         return result
     }
     
@@ -218,6 +254,8 @@ class KMBackgroundManager: NSObject {
             }
         }
         
+        self._clearStored()
+        
         return result
     }
     
@@ -367,6 +405,79 @@ class KMBackgroundManager: NSObject {
         return model
     }
     
+    private func parseObject(object: KMBackgroundObject) -> KMBackgroundModel {
+        let model = KMBackgroundModel()
+        
+        model.type = object.type
+        if (model.type == .file) {
+            model.image = object.image
+            model.imagePath = object.imagePath ?? ""
+        } else {
+            model.color = object.color
+        }
+        
+        model.scale = object.scale
+        model.rotation = object.rotation.cgFloat
+        model.opacity = object.opacity
+        model.verticalMode = object.verticalMode
+        model.verticalSpace = object.verticalSpace.cgFloat
+        model.horizontalMode = object.horizontalMode
+        model.horizontalSpace = object.horizontalSpace.cgFloat
+        model.pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: object.pageRangeType.rawValue) ?? .all
+        model.pagesString = object.pagesString
+        model.backgroundID = object.backgroundID ?? "background0"
+        
+        return model
+    }
+    
+    private func parseModeForObject(_ mode: KMBackgroundModel) -> KMBackgroundObject {
+        let obj = KMBackgroundObject()
+        
+        obj.type = mode.type
+        if (obj.type == .file) {
+            obj.image = mode.image
+            obj.imagePath = mode.imagePath
+        } else {
+            obj.color = mode.color ?? .red
+        }
+        
+        obj.scale = mode.scale
+        obj.rotation = Int(mode.rotation)
+        obj.opacity = mode.opacity
+        obj.verticalMode = mode.verticalMode
+        obj.verticalSpace = Int(mode.verticalSpace)
+        obj.horizontalMode = mode.horizontalMode
+        obj.horizontalSpace = Int(mode.horizontalSpace)
+        obj.pageRangeType = KMBatchOperatePageChoice.init(rawValue: mode.pageRangeType.rawValue) ?? .All
+        obj.pagesString = mode.pagesString
+        obj.backgroundID = mode.backgroundID
+        
+        return obj
+    }
+    
+    private func _addBackground(_ obj: KMBackgroundObject) {
+        self.backgroundObjects.insert(obj, at: 0)
+        self._store()
+    }
+    
+    private func _removeBackground(_ obj: KMBackgroundObject) {
+        self.backgroundObjects.removeObject(obj)
+        self._store()
+    }
+    
+    private func _store() {
+        let encodedObject = NSKeyedArchiver.archivedData(withRootObject: self)
+        let defaults = UserDefaults.standard
+        defaults.set(encodedObject, forKey: "kBackgroundInfoSaveKey")
+        defaults.synchronize()
+    }
+    
+    private func _clearStored() {
+        let defaults = UserDefaults.standard
+        defaults.set(nil, forKey: "kBackgroundInfoSaveKey")
+        defaults.synchronize()
+    }
+    
     private func tagString() -> String {
         var result: String = ""
         

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPreviewController.swift

@@ -151,7 +151,7 @@ class KMBatesPreviewController: KMWatermarkAdjectivePreViewBaseController {
             style.lineBreakMode = .byCharWrapping
             let size: NSSize = "text".boundingRect(with: NSSize(width: 1000, height: 1000), options: NSString.DrawingOptions(rawValue: 3), attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.paragraphStyle : style]).size
             
-            property?.margin = NSEdgeInsetsMake(max(model.topMargin-size.height, 0), model.leftMargin, max(model.bottomMargin-size.height, 0), model.rightMargin)
+            property?.margin = NSEdgeInsetsMake(max(CGFloat(model.topMargin)-size.height, 0), CGFloat(model.leftMargin), max(CGFloat(model.bottomMargin)-size.height, 0), CGFloat(model.rightMargin))
             
             let strings = [model.topLeftString, model.topCenterString, model.topRightString, model.bottomLeftString, model.bottomCenterString, model.bottomRightString]
             var count: Int = 0

+ 7 - 7
PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyInfoController.swift

@@ -110,19 +110,19 @@ class KMBatesPropertyInfoController: NSViewController {
         marginView.frame = self.marginBox.contentView!.bounds
         marginView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
         self.marginBox.contentView?.addSubview(marginView)
-        marginView.itemClick = { [weak self] (index: Int, value: Any) in
+        marginView.itemClick = { [unowned self] (index: Int, value: Any) in
             if (index == 1) { /// top
-                self!.model.topMargin = value as! Double
+                self.model.topMargin = value as! Int
             } else if (index == 2) { /// bottom
-                self!.model.bottomMargin = value as! Double
+                self.model.bottomMargin = value as! Int
             } else if (index == 3) { /// left
-                self!.model.leftMargin = value as! Double
+                self.model.leftMargin = value as! Int
             } else if (index == 4) { /// right
-                self!.model.rightMargin = value as! Double
+                self.model.rightMargin = value as! Int
             }
             
-            if (self!.delegate != nil) {
-                self!.delegate.propertyInfoDidChange(model: self!.model)
+            if (self.delegate != nil) {
+                self.delegate.propertyInfoDidChange(model: self.model)
             }
         }
         

+ 4 - 0
PDF Office/PDF Master/Class/PDFTools/Bates/Model/KMBatesModel.swift

@@ -19,6 +19,10 @@ import Cocoa
         self.name = "Bates Number"
     }
     
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
     override func copy() -> Any {
         let model = KMBatesModel()
         model.name = self.name

+ 4 - 4
PDF Office/PDF Master/Class/PDFTools/Bates/Tools/KMBatesManager.swift

@@ -231,10 +231,10 @@ class KMBatesManager: NSObject {
         model.textColor = .color(red: dict["red"] as! CGFloat, green: dict["green"] as! CGFloat, blue: dict["blue"] as! CGFloat, alpha: dict["alpha"] as! CGFloat)
 
         /// 页边距
-        model.leftMargin = dict["leftMargin"] as! CGFloat
-        model.rightMargin = dict["rightMargin"] as! CGFloat
-        model.bottomMargin = dict["bottomMargin"] as! CGFloat
-        model.topMargin = dict["topMargin"] as! CGFloat
+        model.leftMargin = dict["leftMargin"] as! Int
+        model.rightMargin = dict["rightMargin"] as! Int
+        model.bottomMargin = dict["bottomMargin"] as! Int
+        model.topMargin = dict["topMargin"] as! Int
         
         /// 内容
         model.topLeftString = dict["topLeftString"] as! String

+ 97 - 5
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Base/KMHeaderFooterAdjectiveModel.swift

@@ -7,11 +7,11 @@
 
 import Cocoa
 
-@objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel {
-    var leftMargin: CGFloat = 30.0
-    var rightMargin: CGFloat = 30.0
-    var bottomMargin: CGFloat = 30.0
-    var topMargin: CGFloat = 30.0
+@objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding {
+    var leftMargin: Int = 30
+    var rightMargin: Int = 30
+    var bottomMargin: Int = 30
+    var topMargin: Int = 30
     var topLeftString: String = ""
     var topCenterString: String = ""
     var topRightString: String = ""
@@ -69,4 +69,96 @@ import Cocoa
         self.textFont = .font(name: "Helvetica", size: 10)
         self.textColor = .color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
     }
+    
+    required init?(coder: NSCoder) {
+        super.init()
+        pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "type"))!
+        leftMargin = coder.decodeInteger(forKey: "leftMargin")
+        rightMargin = coder.decodeInteger(forKey: "rightMargin")
+        bottomMargin = coder.decodeInteger(forKey: "bottomMargin")
+        topMargin = coder.decodeInteger(forKey: "topMargin")
+        topLeftString = coder.decodeObject(forKey: "topLeftString") as? String ?? ""
+        topCenterString = coder.decodeObject(forKey: "topCenterString") as? String ?? ""
+        topRightString = coder.decodeObject(forKey: "topRightString") as? String ?? ""
+        bottomLeftString = coder.decodeObject(forKey: "bottomLeftString") as? String ?? ""
+        bottomCenterString = coder.decodeObject(forKey: "bottomCenterString") as? String ?? ""
+        bottomRightString = coder.decodeObject(forKey: "bottomRightString") as? String ?? ""
+        startString = coder.decodeObject(forKey: "startString") as? String ?? ""
+        fontSize = coder.decodeFloat(forKey: "fontSize")
+        tempTextColor = coder.decodeObject(forKey: "textColor") as? NSColor ?? NSColor.black
+        id = coder.decodeObject(forKey: "headerFooterID") as? String ?? ""
+        pageCount = coder.decodeInteger(forKey: "pageChoice")
+        pageRangeString = coder.decodeObject(forKey: "pagesString") as? String ?? ""
+//        hasHeader = coder.decodeBool(forKey: "hasHeader")
+//        hasFooter = coder.decodeBool(forKey: "hasFooter")
+//        cellHeight = coder.decodeFloat(forKey: "cellHeight")
+//        dateFormatString = coder.decodeObject(forKey: "dateFormatString") as? String ?? "m/d"
+//        pageFormatString = coder.decodeObject(forKey: "pageFormatString") as? String ?? "1"
+//        isBates = coder.decodeBool(forKey: "isBates")
+//        batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as? String ?? ""
+//        batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as? String ?? ""
+//        batesDigits = coder.decodeInteger(forKey: "batesDigits")
+    }
+
+    func encode(with coder: NSCoder) {
+        coder.encode(pageRangeType.rawValue, forKey: "type")
+        coder.encode(leftMargin, forKey: "leftMargin")
+        coder.encode(rightMargin, forKey: "rightMargin")
+        coder.encode(bottomMargin, forKey: "bottomMargin")
+        coder.encode(topMargin, forKey: "topMargin")
+        coder.encode(topLeftString, forKey: "topLeftString")
+        coder.encode(topCenterString, forKey: "topCenterString")
+        coder.encode(topRightString, forKey: "topRightString")
+        coder.encode(bottomLeftString, forKey: "bottomLeftString")
+        coder.encode(bottomCenterString, forKey: "bottomCenterString")
+        coder.encode(bottomRightString, forKey: "bottomRightString")
+        coder.encode(startString, forKey: "startString")
+        coder.encode(fontSize, forKey: "fontSize")
+        coder.encode(tempTextColor, forKey: "textColor")
+//        coder.encode(hasHeader, forKey: "hasHeader")
+//        coder.encode(hasFooter, forKey: "hasFooter")
+//        coder.encode(cellHeight, forKey: "cellHeight")
+        coder.encode(id, forKey: "headerFooterID")
+        coder.encode(pageCount, forKey: "pageChoice")
+        coder.encode(pageRangeString, forKey: "pagesString")
+        
+//        coder.encode(dateFormatString, forKey: "dateFormatString")
+//        coder.encode(pageFormatString, forKey: "pageFormatString")
+//        coder.encode(isBates, forKey: "isBates")
+//        coder.encode(batesPrefixString, forKey: "batesPrefixString")
+//        coder.encode(batesSuffixString, forKey: "batesSuffixString")
+//        coder.encode(batesDigits, forKey: "batesDigits")
+    }
+
+//    func copy(with zone: NSZone? = nil) -> Any {
+//        let obj = KMHeaderFooterObject()
+//        obj.pageRangeType = pageRangeType
+//        obj.leftMargin = leftMargin
+//        obj.rightMargin = rightMargin
+//        obj.bottomMargin = bottomMargin
+//        obj.topMargin = topMargin
+//        obj.topLeftString = topLeftString
+//        obj.topCenterString = topCenterString
+//        obj.topRightString = topRightString
+//        obj.bottomLeftString = bottomLeftString
+//        obj.bottomCenterString = bottomCenterString
+//        obj.bottomRightString = bottomRightString
+//        obj.startString = startString
+//        obj.fontSize = fontSize
+//        obj.textColor = textColor
+////        obj.hasHeader = hasHeader
+////        obj.hasFooter = hasFooter
+////        obj.cellHeight = cellHeight
+//        obj.id = id
+//        obj.pageCount = pageCount
+//        obj.pageRangeString = pageRangeString
+//        
+//        obj.dateFormatString = dateFormatString
+//        obj.pageFormatString = pageFormatString
+//        obj.isBates = isBates
+//        obj.batesPrefixString = batesPrefixString
+//        obj.batesSuffixString = batesSuffixString
+//        obj.batesDigits = batesDigits
+//        return obj
+//    }
 }

+ 4 - 4
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMCreateHeaderFooterController.swift

@@ -7,7 +7,7 @@
 
 import Cocoa
 
-typealias KMCreateHeaderFooterModelDidChange = (_ model: KMHeaderFooterModel) -> ()
+typealias KMCreateHeaderFooterModelDidChange = (_ model: KMHeaderFooterObject) -> ()
 class KMCreateHeaderFooterController: KMWatermarkAdjectivePropertyBaseController {
     
     /// 是否是编辑类型
@@ -21,7 +21,7 @@ class KMCreateHeaderFooterController: KMWatermarkAdjectivePropertyBaseController
         super.viewWillAppear()
         
         let controller: KMHeaderFooterPropertyInfoController = childViewController[0] as! KMHeaderFooterPropertyInfoController
-        controller.model = self.model as! KMHeaderFooterModel
+        controller.model = self.model as! KMHeaderFooterObject
     }
 
     override func viewDidLoad() {
@@ -57,7 +57,7 @@ class KMCreateHeaderFooterController: KMWatermarkAdjectivePropertyBaseController
             return
         }
         
-        (childViewController[0] as! KMHeaderFooterPropertyInfoController).model = self.flagModel?.copy() as! KMHeaderFooterModel
+        (childViewController[0] as! KMHeaderFooterPropertyInfoController).model = self.flagModel?.copy() as! KMHeaderFooterObject
     }
 }
 
@@ -69,6 +69,6 @@ extension KMCreateHeaderFooterController: KMWatermarkAdjectivePropertyDelegate {
             return
         }
         
-        callback(model as! KMHeaderFooterModel)
+        callback(model as! KMHeaderFooterObject)
     }
 }

+ 5 - 5
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPreviewController.swift

@@ -40,7 +40,7 @@ class KMHeaderFooterPreviewController: KMWatermarkAdjectivePreViewBaseController
         controller.view.autoresizingMask = [.width, .height]
         self.right_gotoViewController(viewController: controller)
         controller.modelDidChange = { [weak self] model in
-            if (model == nil || (model as! KMHeaderFooterModel).hasVaild == false) {
+            if (model == nil || (model as! KMHeaderFooterObject).hasVaild == false) {
                 self!.topBarView.isCanApply(can: false)
                 self!.model = nil
             } else {
@@ -99,7 +99,7 @@ class KMHeaderFooterPreviewController: KMWatermarkAdjectivePreViewBaseController
             return
         }
         self.beginLoading()
-        self.addHeaderFooter(model: self.model! as! KMHeaderFooterModel, toPath: self.preView.document.documentURL.path, completion: {
+        self.addHeaderFooter(model: self.model! as! KMHeaderFooterObject, toPath: self.preView.document.documentURL.path, completion: {
             result in
             DispatchQueue.main.async {
                 self.preView.layoutDocumentView()
@@ -120,7 +120,7 @@ class KMHeaderFooterPreviewController: KMWatermarkAdjectivePreViewBaseController
         })
     }
     
-    private func addHeaderFooter(model: KMHeaderFooterModel, toPath: String, completion: @escaping (_ result: Bool) -> ()) {
+    private func addHeaderFooter(model: KMHeaderFooterObject, toPath: String, completion: @escaping (_ result: Bool) -> ()) {
         DispatchQueue.global().async {
             let document: CPDFDocument = self.preView.document
             var property = document.headerFooter()
@@ -142,7 +142,7 @@ class KMHeaderFooterPreviewController: KMWatermarkAdjectivePreViewBaseController
             style.lineBreakMode = .byCharWrapping
             let size: NSSize = "text".boundingRect(with: NSSize(width: 1000, height: 1000), options: NSString.DrawingOptions(rawValue: 3), attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.paragraphStyle : style]).size
             
-            property?.margin = NSEdgeInsetsMake(max(model.topMargin-size.height, 0), model.leftMargin, max(model.bottomMargin-size.height, 0), model.rightMargin)
+            property?.margin = NSEdgeInsetsMake(max(CGFloat(model.topMargin)-size.height, 0), CGFloat(model.leftMargin), max(CGFloat(model.bottomMargin)-size.height, 0), CGFloat(model.rightMargin))
             
             let strings = KMHeaderFooterPreviewController.parseModel(model: model, pageCount: Int(self.preView.document.pageCount))
             var count: Int = 0
@@ -239,7 +239,7 @@ class KMHeaderFooterPreviewController: KMWatermarkAdjectivePreViewBaseController
         }
     }
     
-    static func parseModel(model: KMHeaderFooterModel, pageCount: Int) -> [String] {
+    static func parseModel(model: KMHeaderFooterObject, pageCount: Int) -> [String] {
         var topLeftString: String = ""
         if (!model.topLeftString.isEmpty) {
             var string = KMWatermarkAdjectiveTools.parsePageFormat(formatString: model.topLeftString, startPage: model.startString, pageCount: "\(pageCount)")

+ 10 - 11
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyController.swift

@@ -7,8 +7,8 @@
 
 import Cocoa
 
-typealias KMHeaderFooterPropertyTemplateDidSelected = (_ model: KMHeaderFooterModel,_ isSelected: Bool)->()
-typealias KMHeaderFooterPropertyTemplateMenuItemClick = (_ itemIndex: Int,  _ model: KMHeaderFooterModel)->()
+typealias KMHeaderFooterPropertyTemplateDidSelected = (_ model: KMHeaderFooterObject,_ isSelected: Bool)->()
+typealias KMHeaderFooterPropertyTemplateMenuItemClick = (_ itemIndex: Int,  _ model: KMHeaderFooterObject)->()
 
 /// 页眉页脚 属性控制器
 class KMHeaderFooterPropertyController: KMWatermarkAdjectivePropertyBaseController {
@@ -41,11 +41,11 @@ class KMHeaderFooterPropertyController: KMWatermarkAdjectivePropertyBaseControll
     
     func reloadDatas () {
         let controller: KMHeaderFooterListController = childViewController[0] as! KMHeaderFooterListController
-        controller.initDatas(datas: KMHeaderFooterManager.defaultManager.datas)
+        controller.initDatas(datas: KMHeaderFooterManager.defaultManager().headFooterObjects)
     }
     
-    func deleteTemplateModel(_ templateModel: KMHeaderFooterModel) -> Bool {
-        return KMHeaderFooterManager.defaultManager.deleteTemplate(templateModel)
+    func deleteTemplateModel(_ templateModel: KMHeaderFooterObject) -> Bool {
+        return KMHeaderFooterManager.defaultManager().removeHeaderFooter(templateModel)
     }
     
     func deleteTemplateModel(in controller: KMHeaderFooterListController, index: Int) {
@@ -53,24 +53,23 @@ class KMHeaderFooterPropertyController: KMWatermarkAdjectivePropertyBaseControll
             return
         }
         
-        let templateModel: KMHeaderFooterModel = controller.datas[index] as! KMHeaderFooterModel
+        let templateModel: KMHeaderFooterObject = controller.datas[index] as! KMHeaderFooterObject
         if (deleteTemplateModel(templateModel)) { /// 删除成功,刷新数据
             reloadDatas()
         }
     }
     
     func deleteAllTemplateModel(in controller: KMHeaderFooterListController) {
-        if (KMHeaderFooterManager.defaultManager.deleteAllTemplate()) {
-            reloadDatas()
-        }
+        KMHeaderFooterManager.defaultManager().removeAllHeaderFooter()
+        reloadDatas()
     }
     
-    func findTemplateModel(in controller: KMHeaderFooterListController, index: Int) -> KMHeaderFooterModel? {
+    func findTemplateModel(in controller: KMHeaderFooterListController, index: Int) -> KMHeaderFooterObject? {
         if (index >= controller.datas.count) {
             return nil
         }
         
-        return (controller.datas[index] as! KMHeaderFooterModel)
+        return (controller.datas[index] as! KMHeaderFooterObject)
     }
 }
 

+ 6 - 6
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyInfoController.swift

@@ -33,8 +33,8 @@ class KMHeaderFooterPropertyInfoController: NSViewController {
         super.init(nibName: "KMHeaderFooterPropertyInfoController", bundle: nil)
     }
     
-    private var myModel: KMHeaderFooterModel!
-    var model: KMHeaderFooterModel {
+    private var myModel: KMHeaderFooterObject!
+    var model: KMHeaderFooterObject {
         get {
             return myModel
         }
@@ -121,13 +121,13 @@ class KMHeaderFooterPropertyInfoController: NSViewController {
         self.marginBox.contentView?.addSubview(marginView)
         marginView.itemClick = { [weak self] (index: Int, value: Any) in
             if (index == 1) { /// top
-                self!.model.topMargin = value as! Double
+                self!.model.topMargin = value as! Int
             } else if (index == 2) { /// bottom
-                self!.model.bottomMargin = value as! Double
+                self!.model.bottomMargin = value as! Int
             } else if (index == 3) { /// left
-                self!.model.leftMargin = value as! Double
+                self!.model.leftMargin = value as! Int
             } else if (index == 4) { /// right
-                self!.model.rightMargin = value as! Double
+                self!.model.rightMargin = value as! Int
             }
             
             if (self!.delegate != nil) {

+ 11 - 13
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Controller/KMHeaderFooterPropertyMainController.swift

@@ -46,7 +46,7 @@ class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainCont
     
     override func gotoCreateController() {
         let controller = KMCreateHeaderFooterController()
-        let model: KMHeaderFooterModel = KMHeaderFooterModel()
+        let model: KMHeaderFooterObject = KMHeaderFooterObject()
         model.pageCount = self.pageCount
         controller.model = model
         
@@ -60,7 +60,7 @@ class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainCont
             /// 保存到模板
             let createController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
             if (createController.model != nil) {
-                let model: KMHeaderFooterModel = createController.model as! KMHeaderFooterModel
+                let model: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
                 if (!model.hasVaild) {
                     let alert = NSAlert()
                     alert.alertStyle = .warning
@@ -69,17 +69,15 @@ class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainCont
                     return
                 }
                 
-                let result = KMHeaderFooterManager.defaultManager.addTemplate(createController.model as! KMHeaderFooterModel)
-                if (result) {
-                    guard let callback = self!.modelDidChange else {
-                        return
-                    }
-
-                    self?.model = model
-                    callback(self!.model)
-                    
-                    self!.gotoHomeController(model.id)
+                KMHeaderFooterManager.defaultManager().addHeaderFooter(createController.model as! KMHeaderFooterObject)
+                guard let callback = self!.modelDidChange else {
+                    return
                 }
+
+                self?.model = model
+                callback(self!.model)
+                
+                self!.gotoHomeController(model.id)
             }
         }
         
@@ -108,7 +106,7 @@ class KMHeaderFooterPropertyMainController: KMWatermarkAdjectivePropertyMainCont
             let editController: KMCreateHeaderFooterController = self!.currentController as! KMCreateHeaderFooterController
             if (editController.isEdited) {
                 /// 更新模板
-                let result = KMHeaderFooterManager.defaultManager.updateTemplate(editController.model as! KMHeaderFooterModel)
+                let result = KMHeaderFooterManager.defaultManager().store()
 //                if (result) {
                     
                 self!.gotoHomeController("")

+ 52 - 22
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Model/KMHeaderFooterModel.swift

@@ -1,5 +1,5 @@
 //
-//  KMHeaderFooterModel.swift
+//  KMHeaderFooterObject.swift
 //  PDF Reader Pro
 //
 //  Created by tangchao on 2022/12/27.
@@ -7,7 +7,8 @@
 
 import Cocoa
 
-class KMHeaderFooterModel: KMHeaderFooterAdjectiveModel {
+class KMHeaderFooterObject: KMHeaderFooterAdjectiveModel, NSCopying {
+    
     
     var dateFormatString: String = KMWatermarkAdjectiveTools.getDateFormats().first!
     var pageFormatString: String = KMWatermarkAdjectiveTools.getPageFormats().first!
@@ -22,28 +23,57 @@ class KMHeaderFooterModel: KMHeaderFooterAdjectiveModel {
         self.name = ""
     }
     
-    override func copy() -> Any {
-        let model = KMHeaderFooterModel()
-        model.name = self.name
-        
-        model.leftMargin = self.leftMargin
-        model.rightMargin = self.rightMargin
-        model.bottomMargin = self.bottomMargin
-        model.topMargin = self.topMargin
-        
-        model.topLeftString = self.topLeftString
-        model.topCenterString = self.topCenterString
-        model.topRightString = self.topRightString
-        
-        model.bottomLeftString = self.bottomLeftString
-        model.bottomCenterString = self.bottomCenterString
-        model.bottomRightString = self.bottomRightString
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
         
-        model.startString = self.startString
+        dateFormatString = coder.decodeObject(forKey: "dateFormatString") as? String ?? "m/d"
+        pageFormatString = coder.decodeObject(forKey: "pageFormatString") as? String ?? "1"
+        isBates = coder.decodeBool(forKey: "isBates")
+        batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as? String ?? ""
+        batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as? String ?? ""
+        batesDigits = coder.decodeInteger(forKey: "batesDigits")
+    }
+    
+    override func encode(with coder: NSCoder) {
+        super.encode(with: coder)
         
-        model.dateFormatString = self.dateFormatString
-        model.pageFormatString = self.pageFormatString
+        coder.encode(dateFormatString, forKey: "dateFormatString")
+        coder.encode(pageFormatString, forKey: "pageFormatString")
+        coder.encode(isBates, forKey: "isBates")
+        coder.encode(batesPrefixString, forKey: "batesPrefixString")
+        coder.encode(batesSuffixString, forKey: "batesSuffixString")
+        coder.encode(batesDigits, forKey: "batesDigits")
+    }
+    
+    func copy(with zone: NSZone? = nil) -> Any {
+        let obj = KMHeaderFooterObject()
+        obj.pageRangeType = pageRangeType
+        obj.leftMargin = leftMargin
+        obj.rightMargin = rightMargin
+        obj.bottomMargin = bottomMargin
+        obj.topMargin = topMargin
+        obj.topLeftString = topLeftString
+        obj.topCenterString = topCenterString
+        obj.topRightString = topRightString
+        obj.bottomLeftString = bottomLeftString
+        obj.bottomCenterString = bottomCenterString
+        obj.bottomRightString = bottomRightString
+        obj.startString = startString
+        obj.fontSize = fontSize
+        obj.textColor = textColor
+//        obj.hasHeader = hasHeader
+//        obj.hasFooter = hasFooter
+//        obj.cellHeight = cellHeight
+        obj.id = id
+        obj.pageCount = pageCount
+        obj.pageRangeString = pageRangeString
         
-        return model
+        obj.dateFormatString = dateFormatString
+        obj.pageFormatString = pageFormatString
+        obj.isBates = isBates
+        obj.batesPrefixString = batesPrefixString
+        obj.batesSuffixString = batesSuffixString
+        obj.batesDigits = batesDigits
+        return obj
     }
 }

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMDataVersionManager.swift

@@ -19,7 +19,7 @@ class KMDataVersionManager: NSObject{
         return false
     }
     
-    class func refrshBatesData(bates: KMHeaderFooterModel?) -> KMHeaderFooterModel? {
+    class func refrshBatesData(bates: KMHeaderFooterObject?) -> KMHeaderFooterObject? {
         if bates == nil {
             return nil
         }
@@ -37,7 +37,7 @@ class KMDataVersionManager: NSObject{
         bates!.bottomRightString = KMDataVersionManager.newBateString(oldString: bates!.bottomRightString, bates: bates!, match: str)
         return bates
     }
-    class func newBateString(oldString: String, bates: KMHeaderFooterModel, match: String) -> String {
+    class func newBateString(oldString: String, bates: KMHeaderFooterObject, match: String) -> String {
         let regex = try! NSRegularExpression(pattern: match, options: []) 
         let results = regex.matches(in: oldString, options: [], range: NSRange(location: 0, length: oldString.count))
         var newString = oldString

Різницю між файлами не показано, бо вона завелика
+ 747 - 369
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMHeaderFooterManager.swift


+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/View/KMHeaderFooterDateInfoView.swift

@@ -36,7 +36,7 @@ class KMHeaderFooterDateInfoView: KMHeaderFooterAdjectiveInfoBaseView {
         set {
             super.model = newValue
             
-            let myModel: KMHeaderFooterModel = newValue as! KMHeaderFooterModel
+            let myModel: KMHeaderFooterObject = newValue as! KMHeaderFooterObject
             if (myModel.dateFormatString.isEmpty) {
                 self.comboBox.stringValue = KMWatermarkAdjectiveTools.getDateFormats().first!
             } else {

+ 4 - 4
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/View/KMHeaderFooterMarginInfoView.swift

@@ -117,10 +117,10 @@ class KMHeaderFooterMarginInfoView: KMHeaderFooterAdjectiveInfoBaseView {
         set {
             super.model = newValue
             
-            self.topStepper.value = newValue.topMargin
-            self.bottomStepper.value = newValue.bottomMargin
-            self.leftStepper.value = newValue.leftMargin
-            self.rightStepper.value = newValue.rightMargin
+            self.topStepper.value = Double(newValue.topMargin)
+            self.bottomStepper.value = Double(newValue.bottomMargin)
+            self.leftStepper.value = Double(newValue.leftMargin)
+            self.rightStepper.value = Double(newValue.rightMargin)
         }
     }
     

+ 7 - 7
PDF Office/PDF Master/Class/PDFTools/PageEdit/Base/KMPageEditSettingBaseModel.swift

@@ -8,21 +8,21 @@
 import Cocoa
 
 class KMPageEditSettingBaseModel: NSObject {
-    var documentURL: URL!
+    var documentURL: URL?
     var password: String = ""
     
-    var fileName: String!
-    var pathExtension: String!
+    var fileName: String?
+    var pathExtension: String?
     var outputFileNameDeletePathExtension: String!
     var outputFileName: String {
         get {
-            if (fileName == nil || fileName.isEmpty) {
+            guard let data = self.fileName, data.isEmpty == false else {
                 return ""
             }
             
             var result: String = ""
-            let pathExtension = fileName.components(separatedBy: ".").last
-            let files = fileName.split(separator: ".")
+            let pathExtension = data.components(separatedBy: ".").last
+            let files = data.split(separator: ".")
             for i in 0 ..< files.count-1 {
                 let file: String = String(files[i])
                 result.append(file)
@@ -31,7 +31,7 @@ class KMPageEditSettingBaseModel: NSObject {
                 }
             }
             
-            return fileName
+            return data
         }
     }
     

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -651,8 +651,8 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
             model.pageCount = Int(pagecnt)
         }
         
-        model.fileName = model.documentURL.lastPathComponent
-        model.pathExtension = model.fileName.components(separatedBy: ".").last
+        model.fileName = model.documentURL?.lastPathComponent ?? ""
+        model.pathExtension = model.fileName?.components(separatedBy: ".").last
         
         if (self.isEmptySelection() == false) {
             model.type = 2

+ 0 - 370
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController_dmg.swift

@@ -1,370 +0,0 @@
-//
-//  KMPDFEditViewController_dmg.swift
-//  PDF Reader Pro DMG
-//
-//  Created by tangchao on 2023/8/8.
-//
-
-import Cocoa
-
-// 页面编辑控制器 [dmg]
-/*
- 登录策略 与 free 不同
- */
-class KMPDFEditViewController_dmg: KMPDFEditViewController {
-    // MARK: menu 菜单事件
-    
-    @objc override func item_insertCustomPage(sender: NSMenuItem?) {
-        Task { @MainActor in
-            let windowController = KMPageEditInsertCustomPageWindowController()
-            if (self.thumbnailView.selectionIndexPaths.count > 0) {
-                if (self.getPasteIndex() != NSNotFound) {
-                    if let page = self.thumbnailView.document?.page(at: UInt(self.getPasteIndex())) {
-                        let width = page.bounds.size.width * 210 / 595
-                        let height = page.bounds.size.height * 297 / 842
-                        windowController.selectedPageSize = NSSize(width: width, height: height)
-                    }
-                }
-            }
-            
-            self.km_beginSheet(windowC: windowController)
-            windowController.itemClick = { [weak self] index in
-                if (index == 1) { /// 取消
-                    self?.km_endSheet()
-                    return
-                }
-                
-                if IAPProductsManager.default().isAvailableAllFunction() == false {
-                    KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                    return
-                }
-                
-                /// 插入
-                guard let windowC = self?.kmCurrentWindowC as? KMPageEditInsertCustomPageWindowController else {
-                    self?.km_endSheet()
-                    return
-                }
-                guard let _insertIndex = self?.getInsertIndex() else {
-                    self?.km_endSheet()
-                    return
-                }
-                
-                /// 样式
-                //            let type = windowC.typeIndex
-                // mm 单位的大小
-                let pageSize = windowC.pageSize
-                let direction = windowC.direction
-                var _pageSize = KMPageEditTools.sizeUnitToBoundSize(unit: .mm, pageSize: pageSize)
-                
-                if (direction == 0) { // 纵向
-                    if (_pageSize.width > _pageSize.height) { // 需要交换
-                        let tmp = _pageSize.width
-                        _pageSize.width = _pageSize.height
-                        _pageSize.height = tmp
-                    } else {
-                        // no things.
-                    }
-                } else { // 横向
-                    if (_pageSize.width > _pageSize.height) {
-                        // no things.
-                    } else { // 需要交换
-                        let tmp = _pageSize.width
-                        _pageSize.width = _pageSize.height
-                        _pageSize.height = tmp
-                    }
-                }
-                
-                /// 插入位置
-                //            if (type == 1) { /// 空白页
-                let document = CPDFDocument()
-                document?.insertPage(_pageSize, at: 0)
-                if let page: CPDFPage = (document?.page(at: 0)) {
-                    self?.insertPages(pages: [page], at: IndexSet(integer: _insertIndex+1))
-                }
-                //            } else {
-                //                let document = CPDFDocument()
-                //                var imageName = "plaid"
-                //                if (type == 2) {
-                //                    imageName = "horizontal_line"
-                //                } else if (type == 3) {
-                //                    imageName = "five_line_score"
-                //                }
-                //                let imagePath = Bundle.main.pathForImageResource(imageName)
-                //                document?.insertPage(pageSize, withImage: imagePath, at: 0)
-                //                let page: CPDFPage = (document?.page(at: 0))!
-                //                if (direction == 0) { /// 纵向
-                //                    page.rotation = 90
-                //                }
-                //
-                //                self?.insertPagesForDescSort(pages: [page], indexs: IndexSet(integer: _insertIndex+1))
-                //            }
-                self?.km_endSheet()
-            }
-        }
-    }
-
-    override func splitAction() {
-        self.trackEvent(type: .split)
-        
-        Task { @MainActor in
-            self.toolBar.unSelectItem(for: KMToolbarPageEditSplitItemIdentifier)
-            
-            self.showSplitWindow { [unowned self] splitWindowC, model in
-                if IAPProductsManager.default().isAvailableAllFunction() == false {
-                    KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                    return
-                }
-                
-                /// 拆分
-                self.splitMethod(windowC: splitWindowC, model: model)
-            }
-        }
-    }
-    
-    override func replaceAction() {
-        self.km_open_file_multi {  [unowned self] index, params in
-            if (self.fetchProgressBlockParamsIsPasswordFile(params: params)) { // 加密文档进度回调
-                return
-            }
-            
-            var _fileUrl = self.fetchProgressBlockParamsForFileUrl(params: params)
-            if let exn = _fileUrl?.pathExtension, KMTools.isPDFType(exn) {
-                if (_fileUrl!.path.isPDFValid() == false) {
-                    let alert = NSAlert()
-                    alert.alertStyle = .critical
-                    alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
-                    alert.runModal()
-                }
-            }
-        } completionBlock: { [unowned self] documents in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-            
-            self.replacePages(of: self.thumbnailView.selectionIndexPaths, with: documents)
-        }
-    }
-    
-    override func replacePages(of targetIndexpaths: Set<IndexPath>, with documents: [CPDFDocument]) {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-            
-            super.replacePages(of: targetIndexpaths, with: documents)
-        }
-    }
-    
-    override func extractActionIndexpaths(indexpaths: Set<IndexPath>) {
-        self.showExtractWindow_success(indexpaths: indexpaths) { [unowned self] oneDocumentPerPage, extractAfterDelete in
-            self.extractPages(indexpaths: indexpaths, oneDocumentPerPage: oneDocumentPerPage, limit: !self.canPayFunction) { [unowned self] result, params in
-                if (result == .failure || result == .cancel) {
-                    return
-                }
-                
-                if (extractAfterDelete) {
-                    self.deleteIndexPaths(indexpaths: indexpaths)
-                }
-            }
-        }
-    }
-    
-    override func showExtractWindow(indexpaths: Set<IndexPath>, callback: @escaping KMResultBlock) {
-        let windowC = KMPageEditExtractWindowController(nil)
-        if let data = self.thumbnailView.document?.pageCount, data == indexpaths.count {
-            windowC.canDeleteAll = false
-        } else {
-            windowC.canDeleteAll = true
-        }
-        self.km_beginSheet(windowC: windowC)
-        
-        windowC.itemClick = { [weak self] index, _ in
-            if (index == 1) { /// 取消
-                self?.km_endSheet()
-                callback(.cancel)
-                return
-            }
-            guard let _windowC = self?.kmCurrentWindowC as? KMPageEditExtractWindowController  else {
-                self?.km_endSheet()
-                callback(nil)
-                return
-            }
-            
-            /// 提取设置项
-            let settingView = _windowC.settingView as! KMPageEditExtractSettingView
-            let oneDocumentPerPage = settingView.independentPerPageValue
-            let extractAfterDelete = settingView.extractAfterDeletePageValue
-            
-            Task { @MainActor in
-                if IAPProductsManager.default().isAvailableAllFunction() == false {
-                    KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                    return
-                }
-                
-                self?.km_endSheet()
-                callback(.ok, oneDocumentPerPage, extractAfterDelete)
-            }
-        }
-    }
-    
-    override func reverseAction() {
-        self.trackEvent(type: .reverse)
-        
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            self.toolBar.unSelectItem(for: KMToolbarPageEditReverseItemIdentifier)
-            self.reverseMenuAction(sender: nil)
-        }
-    }
-    
-    override func leftRotateIndexpaths(indexpaths: Set<IndexPath>) {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.leftRotateIndexpaths(indexpaths: indexpaths)
-        }
-    }
-    
-    override func rightRotateIndexpaths(indexpaths: Set<IndexPath>) {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.rightRotateIndexpaths(indexpaths: indexpaths)
-        }
-    }
-    
-    override func insertBlankPage(size: NSSize, at index: Int, position: KMInsertPosition = .after) {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.insertBlankPage(size: size, at: index, position: position)
-        }
-    }
-    
-    override func insertFileAction() {
-        self.km_open_file_multi { [unowned self] index, params in
-            if (self.fetchProgressBlockParamsIsPasswordFile(params: params)) { // 加密文档进度回调
-                return
-            }
-            
-            var _fileUrl = self.fetchProgressBlockParamsForFileUrl(params: params)
-            if let exn = _fileUrl?.pathExtension, KMTools.isPDFType(exn) {
-                if (_fileUrl!.path.isPDFValid() == false) {
-                    let alert = NSAlert()
-                    alert.alertStyle = .critical
-                    alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
-                    alert.runModal()
-                }
-            }
-        } completionBlock: { [unowned self] documents in
-            var insertIndex = self.getInsertIndex()
-            var pages: Array<CPDFPage> = []
-            var indexs = IndexSet()
-            for document in documents {
-                for i in 0 ..< document.pageCount {
-                    guard let page = document.page(at: i) else {
-                        continue
-                    }
-                    
-                    pages.append(page)
-                    insertIndex += 1
-                    indexs.insert(insertIndex)
-                }
-            }
-            
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-            
-            self.insertPages(pages: pages, at: indexs)
-        }
-    }
-    
-    override func deleteIndexPaths(indexpaths: Set<IndexPath>) {
-        if (!self.indexpathsIsValid(indexpaths: indexpaths)) {
-            KMPrint("indexpaths invalid. indexpaths: \(indexpaths)")
-            return
-        }
-        
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.deleteIndexPaths(indexpaths: indexpaths)
-        }
-    }
-    
-    override func cutAction() {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.cutAction()
-        }
-    }
-    
-    override func copyAction() {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.copyAction()
-        }
-    }
-    
-    override func pasteAction() {
-        Task { @MainActor in
-            if IAPProductsManager.default().isAvailableAllFunction() == false {
-                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                return
-            }
-
-            super.pasteAction()
-        }
-    }
-}
-
-extension KMPDFEditViewController_dmg {
-    override func thumbnailView(thumbanView: KMThumbnailView, shouldAcceptDrop draggingInfo: NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> Bool {
-        if IAPProductsManager.default().isAvailableAllFunction() == false {
-            KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-            return false
-        }
-        
-        return true
-    }
-    
-    override func thumbnailView(thumbanView: KMThumbnailView, shouldPasteboardWriterForItemAt indexPath: IndexPath) -> Bool {
-        if IAPProductsManager.default().isAvailableAllFunction() == false {
-            KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-            return false
-        }
-//        if (!self.canPayFunction) {
-//            return false
-//        }
-        
-        return true
-    }
-}

+ 1 - 4
PDF Office/PDF Master/Class/PDFTools/PageEdit/Model/KMPageEditSplitSettingModel.swift

@@ -67,9 +67,6 @@ class KMPageEditSplitSettingModel: KMPageEditSettingBaseModel {
                 
                 var avgNumberPage = (pageCount / fileCount)
                 let pageOffset = pageCount % fileCount
-//                if (pageCount % fileCount != 0) {
-//                    avgNumberPage += 1
-//                }
                 var files: Array<IndexSet> = []
                 for i in 0 ..< fileCount {
                     var indexs: IndexSet = []
@@ -179,7 +176,7 @@ class KMPageEditSplitSettingModel: KMPageEditSettingBaseModel {
             self.outputFileNameDeletePathExtension = result
             
             result.append(".")
-            result.append(self.pathExtension)
+            result.append(self.pathExtension ?? "pdf")
             
             return result
         }

+ 3 - 1
PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPDFEditToolbar.swift

@@ -261,7 +261,9 @@ class KMPDFEditToolbar: NSView {
         popover.animates = true
         popover.behavior = .semitransient
         popover.setValue(true, forKey: "shouldHideAnchor")
-        popover.show(relativeTo: CGRect(x: sender!.bounds.origin.x, y: 10, width: sender!.bounds.size.width, height: sender!.bounds.size.height), of: sender!, preferredEdge: .maxY)
+        if let data = sender {
+            popover.show(relativeTo: CGRect(x: sender?.bounds.origin.x ?? 0, y: 10, width: sender?.bounds.size.width ?? 0, height: sender?.bounds.size.height ?? 0), of: data, preferredEdge: .maxY)
+        }
         vc.downCallback = { [weak self] downEntered, count in
             self?.popover?.close()
             self?.popover = nil

+ 5 - 5
PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPageEditInsertTypeItemView.swift

@@ -16,7 +16,7 @@ private class KMPageEditInsertTypeSubItemView: NSView {
     var button = NSButton()
     
     var itemID: Int = 0
-    var itemClick: KMPageEditInsertTypeSubItemViewItemClick!
+    var itemClick: KMPageEditInsertTypeSubItemViewItemClick?
     
     override var isFlipped: Bool {
         return true
@@ -133,7 +133,7 @@ class KMPageEditInsertTypeItemView: KMPageEditBaseItemView {
             }
             
             /// 默认选中第一个
-            self.selectItem(self.itemViews.first!.itemID)
+            self.selectItem(self.itemViews.first?.itemID ?? 0)
             
             self.layoutSubtreeIfNeeded()
         }
@@ -153,10 +153,10 @@ class KMPageEditInsertTypeItemView: KMPageEditBaseItemView {
         let itemY: CGFloat = 8
         var preItemView: KMPageEditInsertTypeSubItemView?
         for itemView in self.itemViews {
-            if (preItemView == nil) {
-                itemView.frame = NSMakeRect(margin, itemY, itemSize.width, itemSize.height)
+            if let data = preItemView {
+                itemView.frame = NSMakeRect((data.frame.maxX)+space, itemY, itemSize.width, itemSize.height)
             } else {
-                itemView.frame = NSMakeRect((preItemView?.frame.maxX)!+space, itemY, itemSize.width, itemSize.height)
+                itemView.frame = NSMakeRect(margin, itemY, itemSize.width, itemSize.height)
             }
             
             preItemView = itemView

+ 2 - 0
PDF Office/PDF Master/Class/PDFTools/Watermark/Base/KMWatermarkAdjectiveBaseModel.swift

@@ -22,7 +22,9 @@ enum KMWatermarkAdjectiveText {
 
 @objcMembers class KMWatermarkAdjectiveBaseModel: NSObject {
     var textFont: KMWatermarkAdjectiveText!
+    var fontSize: Float = 12.0
     var textColor: KMWatermarkAdjectiveText!
+    var tempTextColor: NSColor = NSColor.black
     
     var id: String = ""
     

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/Watermark/OCPart/KMWatermarkPDFView_OC.m

@@ -15,7 +15,7 @@
 @property (nonatomic, strong) KMWatermarkModel *watermark;
 @property (nonatomic, strong) KMBackgroundModel *background;
 @property (nonatomic, strong) KMBatesModel *bates;
-@property (nonatomic, strong) KMHeaderFooterModel *headerFooter;
+@property (nonatomic, strong) KMHeaderFooterObject *headerFooter;
 
 @end
 
@@ -29,7 +29,7 @@
         self.watermark = model;
     } else if ([model isKindOfClass:[KMBackgroundModel class]]) {
         self.background = model;
-    } else if ([model isKindOfClass:[KMHeaderFooterModel class]]) {
+    } else if ([model isKindOfClass:[KMHeaderFooterObject class]]) {
         self.headerFooter = model;
     } else {
         self.bates = nil;

+ 10 - 10
PDF Office/PDF Master/Class/PDFTools/Watermark/Tools/KMWatermarkAdjectiveTools.swift

@@ -151,8 +151,8 @@ case bates = 4
     class func apply(_ model: AnyObject, _ pdfView: CPDFView, _ toPath: String, completion: @escaping (_ result: Bool) -> ()) {
         if (model.isKind(of: KMBatesModel.self)) {
             KMWatermarkAdjectiveTools.applyBates(model as! KMBatesModel, pdfView, toPath, completion: completion)
-        } else if (model.isKind(of: KMHeaderFooterModel.self)) {
-            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterModel, pdfView, toPath, completion: completion)
+        } else if (model.isKind(of: KMHeaderFooterObject.self)) {
+            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterObject, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMBackgroundModel.self)) {
             KMWatermarkAdjectiveTools.applyBackground(model as! KMBackgroundModel, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMWatermarkModel.self)) {
@@ -235,7 +235,7 @@ case bates = 4
             style.lineBreakMode = .byCharWrapping
             let size: NSSize = "text".boundingRect(with: NSSize(width: 1000, height: 1000), options: NSString.DrawingOptions(rawValue: 3), attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.paragraphStyle : style]).size
             
-            property?.margin = NSEdgeInsetsMake(max(model.topMargin-size.height, 0), model.leftMargin, max(model.bottomMargin-size.height, 0), model.rightMargin)
+            property?.margin = NSEdgeInsetsMake(max(CGFloat(model.topMargin)-size.height, 0), CGFloat(model.leftMargin), max(CGFloat(model.bottomMargin)-size.height, 0), CGFloat(model.rightMargin))
             
             let strings = [model.topLeftString, model.topCenterString, model.topRightString, model.bottomLeftString, model.bottomCenterString, model.bottomRightString]
             var count: Int = 0
@@ -293,7 +293,7 @@ case bates = 4
         }
     }
     
-    private class func applyHeaderFooter(_ model: KMHeaderFooterModel, _ pdfView: CPDFView, _ toPath: String, completion: @escaping (_ result: Bool) -> ()) {
+    private class func applyHeaderFooter(_ model: KMHeaderFooterObject, _ pdfView: CPDFView, _ toPath: String, completion: @escaping (_ result: Bool) -> ()) {
         DispatchQueue.global().async {
             let document: CPDFDocument = pdfView.document
             var property = document.headerFooter()
@@ -315,7 +315,7 @@ case bates = 4
             style.lineBreakMode = .byCharWrapping
             let size: NSSize = "text".boundingRect(with: NSSize(width: 1000, height: 1000), options: NSString.DrawingOptions(rawValue: 3), attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.paragraphStyle : style]).size
             
-            property?.margin = NSEdgeInsetsMake(max(model.topMargin-size.height, 0), model.leftMargin, max(model.bottomMargin-size.height, 0), model.rightMargin)
+            property?.margin = NSEdgeInsetsMake(max(CGFloat(model.topMargin)-size.height, 0), CGFloat(model.leftMargin), max(CGFloat(model.bottomMargin)-size.height, 0), CGFloat(model.rightMargin))
             
             let strings = KMWatermarkAdjectiveTools.parseModel(model: model, pdfView.document.pageCount)
             var count: Int = 0
@@ -527,8 +527,8 @@ case bates = 4
     class func add(_ model: AnyObject, _ pdfView: CPDFView, completion: @escaping (_ result: Bool) -> ()) {
         if (model.isKind(of: KMBatesModel.self)) {
 //            KMWatermarkAdjectiveTools.applyBates(model as! KMBatesModel, pdfView, toPath, completion: completion)
-        } else if (model.isKind(of: KMHeaderFooterModel.self)) {
-//            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterModel, pdfView, toPath, completion: completion)
+        } else if (model.isKind(of: KMHeaderFooterObject.self)) {
+//            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterObject, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMBackgroundModel.self)) {
 //            KMWatermarkAdjectiveTools.applyBackground(model as! KMBackgroundModel, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMWatermarkModel.self)) {
@@ -624,8 +624,8 @@ case bates = 4
     class func update(_ model: AnyObject, _ pdfView: CPDFView, completion: @escaping (_ result: Bool) -> ()) {
         if (model.isKind(of: KMBatesModel.self)) {
 //            KMWatermarkAdjectiveTools.applyBates(model as! KMBatesModel, pdfView, toPath, completion: completion)
-        } else if (model.isKind(of: KMHeaderFooterModel.self)) {
-//            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterModel, pdfView, toPath, completion: completion)
+        } else if (model.isKind(of: KMHeaderFooterObject.self)) {
+//            KMWatermarkAdjectiveTools.applyHeaderFooter(model as! KMHeaderFooterObject, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMBackgroundModel.self)) {
 //            KMWatermarkAdjectiveTools.applyBackground(model as! KMBackgroundModel, pdfView, toPath, completion: completion)
         } else if (model.isKind(of: KMWatermarkModel.self)) {
@@ -724,7 +724,7 @@ case bates = 4
         }
     }
     
-    private class func parseModel(model: KMHeaderFooterModel, _ pageCount: UInt) -> [String] {
+    private class func parseModel(model: KMHeaderFooterObject, _ pageCount: UInt) -> [String] {
         var topLeftString: String = ""
         if (!model.topLeftString.isEmpty) {
             var string = KMWatermarkAdjectiveTools.parsePageFormat(formatString: model.topLeftString, startPage: model.startString, pageCount: "\(pageCount)")

+ 20 - 20
PDF Office/PDF Master/Class/PDFTools/Watermark/View/KMWatermarkPDFView.swift

@@ -13,7 +13,7 @@ class KMWatermarkPDFView: CPDFView {
     
     var watermark: KMWatermarkModel?
     var background: KMBackgroundModel?
-    var headerFooter: KMHeaderFooterModel?
+    var headerFooter: KMHeaderFooterObject?
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
@@ -426,8 +426,8 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        var posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
-        tString.draw(in: CGRect(x: headerFooter.leftMargin + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
+        var posY = min(pageBounds.size.height - CGFloat((headerFooter.topMargin)), pageBounds.size.height - size.height)
+        tString.draw(in: CGRect(x: Double(headerFooter.leftMargin) + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
     
 
         let topCenterString = headerFooter.topCenterString
@@ -437,7 +437,7 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
+        posY = min(pageBounds.size.height - CGFloat((headerFooter.topMargin)), pageBounds.size.height - size.height)
         tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2 + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
         
 
@@ -448,8 +448,8 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        posY = min(pageBounds.size.height - (headerFooter.topMargin), pageBounds.size.height - size.height)
-        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width + xMargin,
+        posY = min(pageBounds.size.height - CGFloat((headerFooter.topMargin)), pageBounds.size.height - size.height)
+        tString.draw(in: CGRect(x: pageBounds.size.width - CGFloat((headerFooter.rightMargin)) - size.width + xMargin,
                                 y: posY + yMargin,
                                 width: size.width,
                                 height: size.height),
@@ -463,8 +463,8 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        posY = max((headerFooter.bottomMargin) - size.height, 0)
-        tString.draw(in: CGRect(x: headerFooter.leftMargin + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
+        posY = max(CGFloat((headerFooter.bottomMargin)) - size.height, 0)
+        tString.draw(in: CGRect(x: Double(headerFooter.leftMargin) + xMargin, y: posY + yMargin, width: size.width, height: size.height), withAttributes: attributes)
         
 
         let bottomCenterString = headerFooter.bottomCenterString
@@ -474,7 +474,7 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        posY = max((headerFooter.bottomMargin) - size.height, 0)
+        posY = max(CGFloat((headerFooter.bottomMargin)) - size.height, 0)
         tString.draw(in: CGRect(x: pageBounds.size.width/2 - size.width/2 + xMargin,
                                 y: posY + yMargin,
                                 width: size.width,
@@ -489,8 +489,8 @@ class KMWatermarkPDFView: CPDFView {
                                    options: [.usesLineFragmentOrigin, .usesFontLeading],
                                    attributes: attributes).size
 
-        posY = max((headerFooter.bottomMargin) - size.height, 0)
-        tString.draw(in: CGRect(x: pageBounds.size.width - (headerFooter.rightMargin) - size.width + xMargin,
+        posY = max(CGFloat((headerFooter.bottomMargin)) - size.height, 0)
+        tString.draw(in: CGRect(x: pageBounds.size.width - CGFloat((headerFooter.rightMargin)) - size.width + xMargin,
                                 y: posY + yMargin,
                                 width: size.width,
                                 height: size.height),
@@ -500,17 +500,17 @@ class KMWatermarkPDFView: CPDFView {
         context.setStrokeColor(NSColor(red: 51.0/255.0, green: 186.0/255.0, blue: 234.0/255.0, alpha: 1.0).cgColor)
         context.setLineWidth(1.0)
 
-        context.move(to: CGPoint(x: xMargin, y: headerFooter.bottomMargin + bottomOffset))
-        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: headerFooter.bottomMargin + bottomOffset))
+        context.move(to: CGPoint(x: xMargin, y: CGFloat(headerFooter.bottomMargin) + bottomOffset))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: CGFloat(headerFooter.bottomMargin) + bottomOffset))
 
-        context.move(to: CGPoint(x: xMargin + headerFooter.leftMargin, y: 0))
-        context.addLine(to: CGPoint(x: xMargin + headerFooter.leftMargin, y: pageBounds.size.height))
+        context.move(to: CGPoint(x: Int(xMargin) + headerFooter.leftMargin, y: 0))
+        context.addLine(to: CGPoint(x: xMargin + Double(headerFooter.leftMargin), y: pageBounds.size.height))
 
-        context.move(to: CGPoint(x: xMargin + pageBounds.size.width - (headerFooter.rightMargin), y: 0))
-        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width - (headerFooter.rightMargin), y: pageBounds.size.height))
+        context.move(to: CGPoint(x: Int(xMargin + pageBounds.size.width) - (headerFooter.rightMargin), y: 0))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width - Double((headerFooter.rightMargin)), y: pageBounds.size.height))
 
-        context.move(to: CGPoint(x: xMargin, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
-        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: pageBounds.size.height - (headerFooter.topMargin) - topOffset))
+        context.move(to: CGPoint(x: xMargin, y: pageBounds.size.height - CGFloat((headerFooter.topMargin)) - topOffset))
+        context.addLine(to: CGPoint(x: xMargin + pageBounds.size.width, y: pageBounds.size.height - CGFloat((headerFooter.topMargin)) - topOffset))
 
         let arr: [CGFloat] = [8, 1]
         context.setLineDash(phase: 0, lengths: arr)
@@ -582,7 +582,7 @@ class KMWatermarkPDFView: CPDFView {
     static func convertDateFormat(_ oldString: String) -> String {
         var newString = oldString
         
-        for dateFormat in KMHeaderFooterManager.defaultManager.dateFormatArray {
+        for dateFormat in KMHeaderFooterManager.defaultManager().dateFormatArray {
             if newString.contains(dateFormat) {
                 let formatString = dateFormat.replacingOccurrences(of: "m", with: "M")
                 let replace = "<<\(dateFormat)>>"

+ 0 - 51
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/Base/KMPDFThumbViewBaseController.swift

@@ -336,57 +336,6 @@ class KMPDFThumbViewBaseController: KMBaseViewController {
     
     // 提取 指定的item
     public func extractActionIndexpaths(indexpaths: Set<IndexPath>) {
-//        Task { @MainActor in
-//            if await (KMLightMemberManager.manager.canPayFunction() == false) {
-//                let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!, type: .extract) { isSubscribeSuccess, isWaterMarkExport, isClose in
-//                    if (isClose) {
-//                        return
-//                    }
-//                    if (isSubscribeSuccess) {
-//                        self.showExtractWindow_success(indexpaths: indexpaths) { [unowned self] oneDocumentPerPage, extractAfterDelete in
-//                            self._extractPages(indexpaths: indexpaths, oneDocumentPerPage: oneDocumentPerPage) { [unowned self] result, params in
-//                                if (result == .failure || result == .cancel) {
-//                                    return
-//                                }
-//
-//                                if (extractAfterDelete) {
-//                                    self.deleteIndexPaths(indexpaths: indexpaths)
-//                                }
-//                            }
-//                        }
-//                        return
-//                    }
-//                    if (isWaterMarkExport) {
-//                        self.showExtractWindow_success(indexpaths: indexpaths) { [unowned self] oneDocumentPerPage, extractAfterDelete in
-//                            self._extractPages(indexpaths: indexpaths, oneDocumentPerPage: oneDocumentPerPage, limit: true) { [unowned self] result, params in
-//                                if (result == .failure || result == .cancel) {
-//                                    return
-//                                }
-//
-//                                if (extractAfterDelete) {
-//                                    self.deleteIndexPaths(indexpaths: indexpaths)
-//                                }
-//                            }
-//                        }
-//                        return
-//                    }
-//
-//                }
-//                return
-//            }
-//
-//            self.showExtractWindow_success(indexpaths: indexpaths) { [unowned self] oneDocumentPerPage, extractAfterDelete in
-//                self._extractPages(indexpaths: indexpaths, oneDocumentPerPage: oneDocumentPerPage) { [unowned self] result, params in
-//                    if (result == .failure || result == .cancel) {
-//                        return
-//                    }
-//
-//                    if (extractAfterDelete) {
-//                        self.deleteIndexPaths(indexpaths: indexpaths)
-//                    }
-//                }
-//            }
-//        }
 //        let pageIndexs = self.indexpathsToIndexs(indexpaths: indexpaths)
 //        var fileName = self.thumbnailView.document?.documentURL.deletingPathExtension().lastPathComponent
 //        fileName?.append(KMPageRangeTools.newParseSelectedIndexs(selectedIndex: pageIndexs.sorted()))

+ 29 - 21
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailView.swift

@@ -66,10 +66,12 @@ extension KMPDFThumbnailView {
             return size_
         }
         
-        let page = self.document?.page(at: UInt(indexPath.item))
-        let height = KMPDFThumbnailItem.sizeToFit(size: self.thumbnailSzie, page: page!, isShow: self.isShowPageSize)
+        var height: CGFloat = 0
+        if let page = self.document?.page(at: UInt(indexPath.item)) {
+            height = KMPDFThumbnailItem.sizeToFit(size: self.thumbnailSzie, page: page, isShow: self.isShowPageSize)
+        }
         
-        return NSMakeSize(collectionView.frame.size.width - 20, CGFloat(height))
+        return NSMakeSize(collectionView.frame.size.width - 20, height)
     }
     
     override func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
@@ -107,14 +109,14 @@ extension KMPDFThumbnailView {
         cellView.hoverCallBack = { [unowned self] view, mouseEntered in
             if let _ = self.collectionView.item(at: hoverIndex)?.view {
                 let tempCell = self.collectionView.item(at: hoverIndex) as? KMPDFThumbnailItem
-                tempCell!.hover = false
+                tempCell?.hover = false
             }
             
             if mouseEntered {
                 hoverIndex = indexPath.item
                 if let _ = self.collectionView.item(at: hoverIndex)?.view {
                     let tempCell = self.collectionView.item(at: hoverIndex) as? KMPDFThumbnailItem
-                    tempCell!.hover = true
+                    tempCell?.hover = true
                 }
             } else {
                 hoverIndex = -1
@@ -153,7 +155,7 @@ extension KMPDFThumbnailView {
             
             if let data = self.dragTempFilePath {
                 if (self.limit) {
-                    let _ = KMTools.saveWatermarkDocument(document: document!, to: URL(fileURLWithPath: data))
+//                    let _ = KMTools.saveWatermarkDocument(document: document!, to: URL(fileURLWithPath: data))
                 } else {
                     document?.write(to: URL(fileURLWithPath: data))
                 }
@@ -208,16 +210,18 @@ extension KMPDFThumbnailView {
         
         let pboard = draggingInfo.draggingPasteboard
         if (pboard.availableType(from: [self.localForDraggedTypes]) != nil) {
-            let dragIndexPath = self.dragedIndexPaths.first
-            if (dragIndexPath == nil) {
+            guard let dragIndexPath = self.dragedIndexPaths.first else {
+                return false
+            }
+            guard let document = self.document else {
                 return false
             }
-            let dragIndex = dragIndexPath!.item
+            let dragIndex = dragIndexPath.item
             let toIndex = max(0, indexPath.item)
-            if dragIndex < 0 || dragIndex > self.document!.pageCount {
+            if dragIndex < 0 || dragIndex > document.pageCount {
                 return false
             }
-            if (toIndex >= self.document!.pageCount) {
+            if (toIndex >= document.pageCount) {
                 return false
             }
 
@@ -282,12 +286,14 @@ extension KMPDFThumbnailView {
         // 创建数据提供者
         let fileExtension = "pdf"
         if #available(macOS 11.0, *) {
-            let typeIdentifier = UTType(filenameExtension: fileExtension)
-            provider = KMFilePromiseProvider(fileType: typeIdentifier!.identifier, delegate: self)
+            if let typeIdentifier = UTType(filenameExtension: fileExtension) {
+                provider = KMFilePromiseProvider(fileType: typeIdentifier.identifier, delegate: self)
+            }
         } else {
-            let typeIdentifier =
-                  UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as CFString, nil)
-            provider = KMFilePromiseProvider(fileType: typeIdentifier!.takeRetainedValue() as String, delegate: self)
+            if let typeIdentifier =
+                UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as CFString, nil) {
+                provider = KMFilePromiseProvider(fileType: typeIdentifier.takeRetainedValue() as String, delegate: self)
+            }
         }
         
         // 记录拖拽索引
@@ -295,11 +301,11 @@ extension KMPDFThumbnailView {
         do {
             if let _url = self.document?.documentURL {
                 let data = try NSKeyedArchiver.archivedData(withRootObject: indexPath, requiringSecureCoding: false)
-                provider!.userInfo = [KMFilePromiseProvider.UserInfoKeys.urlKey: _url,
+                provider?.userInfo = [KMFilePromiseProvider.UserInfoKeys.urlKey: _url,
                                       KMFilePromiseProvider.UserInfoKeys.indexPathKey: data]
             } else {
                 let data = try NSKeyedArchiver.archivedData(withRootObject: indexPath, requiringSecureCoding: false)
-                provider!.userInfo = [KMFilePromiseProvider.UserInfoKeys.indexPathKey: data]
+                provider?.userInfo = [KMFilePromiseProvider.UserInfoKeys.indexPathKey: data]
             }
         } catch {
             fatalError("failed to archive indexPath to pasteboard")
@@ -350,7 +356,7 @@ extension KMPDFThumbnailView {
 extension KMPDFThumbnailView {
     var dragTempFloderPath: String? {
         get {
-            return NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("KMPDFThumbnailView_Drag_Temp")
+            return NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier ?? "").stringByAppendingPathComponent("KMPDFThumbnailView_Drag_Temp")
         }
     }
     var dragTempFilePath: String? {
@@ -400,8 +406,10 @@ extension KMPDFThumbnailView: NSFilePromiseProviderDelegate {
             completionHandler(nil)
         } catch let error {
             OperationQueue.main.addOperation {
-                self.presentError(error, modalFor: self.window!,
-                                  delegate: nil, didPresent: nil, contextInfo: nil)
+                if let win = self.window {
+                    self.presentError(error, modalFor: win,
+                                      delegate: nil, didPresent: nil, contextInfo: nil)
+                }
             }
             completionHandler(error)
         }

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

@@ -1022,26 +1022,26 @@ let KMColorPickerViewHeight: CGFloat = 64
         hiddenSubviews()
 
         textColorPickerView.annotationTypeString = NSLocalizedString("Anchored Note", comment: "Description for export")
-        commentButton.title = NSLocalizedString("Comment", tableName: "NoteWindow", comment: "")
-        commentButton.toolTip = NSLocalizedString("Comment", tableName: "NoteWindow", comment: "")
+        commentButton.title = NSLocalizedString("Comment", comment: "")
+        commentButton.toolTip = NSLocalizedString("Comment", comment: "")
         commentButton.setTitleColor(KMAppearance.Layout.h0Color())
-        paragraphButton.title = NSLocalizedString("Paragraph", tableName: "NoteWindow", comment: "")
-        paragraphButton.toolTip = NSLocalizedString("Paragraph", tableName: "NoteWindow", comment: "")
+        paragraphButton.title = NSLocalizedString("Paragraph", comment: "")
+        paragraphButton.toolTip = NSLocalizedString("Paragraph", comment: "")
         paragraphButton.setTitleColor(KMAppearance.Layout.h0Color())
-        insertButton.title = NSLocalizedString("Insert", tableName: "NoteWindow", comment: "")
-        insertButton.toolTip = NSLocalizedString("Insert", tableName: "NoteWindow", comment: "")
+        insertButton.title = NSLocalizedString("Insert", comment: "")
+        insertButton.toolTip = NSLocalizedString("Insert", comment: "")
         insertButton.setTitleColor(KMAppearance.Layout.h0Color())
-        addParagraphButton.title = NSLocalizedString("New Paragraph", tableName: "NoteWindow", comment: "")
-        addParagraphButton.toolTip = NSLocalizedString("New Paragraph", tableName: "NoteWindow", comment: "")
+        addParagraphButton.title = NSLocalizedString("New Paragraph", comment: "")
+        addParagraphButton.toolTip = NSLocalizedString("New Paragraph", comment: "")
         addParagraphButton.setTitleColor(KMAppearance.Layout.h0Color())
-        keyButton.title = NSLocalizedString("Key", tableName: "NoteWindow", comment: "")
-        keyButton.toolTip = NSLocalizedString("Key", tableName: "NoteWindow", comment: "")
+        keyButton.title = NSLocalizedString("Key", comment: "")
+        keyButton.toolTip = NSLocalizedString("Key", comment: "")
         keyButton.setTitleColor(KMAppearance.Layout.h0Color())
-        noteButton.title = NSLocalizedString("Note", tableName: "NoteWindow", comment: "")
-        noteButton.toolTip = NSLocalizedString("Note", tableName: "NoteWindow", comment: "")
+        noteButton.title = NSLocalizedString("Note", comment: "")
+        noteButton.toolTip = NSLocalizedString("Note", comment: "")
         noteButton.setTitleColor(KMAppearance.Layout.h0Color())
-        helpButton.title = NSLocalizedString("Help", tableName: "NoteWindow", comment: "")
-        helpButton.toolTip = NSLocalizedString("Help", tableName: "NoteWindow", comment: "")
+        helpButton.title = NSLocalizedString("Help", comment: "")
+        helpButton.toolTip = NSLocalizedString("Help", comment: "")
         helpButton.setTitleColor(KMAppearance.Layout.h0Color())
 
         let languages = NSLocale.preferredLanguages

+ 75 - 67
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -62,7 +62,7 @@ class KMToolbarController: NSViewController {
     var mainToolBarView: KMToolbarViewController?
     var childToolBarView: KMToolbarViewController?
     var _toolbarType : KMToolbarViewType = KMToolbarViewType.None
-    var mainViewController: KMMainViewController?
+    weak var mainViewController: KMMainViewController?
     open weak var delegate: KMToolbarControllerDelegate?
     var toolbarItems : [NSToolbarItem.Identifier : Any] = [:]
     var listView : CPDFListView?
@@ -116,7 +116,9 @@ class KMToolbarController: NSViewController {
         mainToolBarView?.view.layer?.backgroundColor = NSColor.km_init(hex: "#F7F8FA").cgColor
         mainToolBarBox.contentView = mainToolBarView?.view
         mainToolBarView?.delegate = self
-        mainToolBarView?.pdfView = self.listView!
+        if let data = self.listView {
+            mainToolBarView?.pdfView = data
+        }
         
         childToolBarView = KMToolbarViewController.init()
         childToolBarView?.view.wantsLayer = true
@@ -125,7 +127,9 @@ class KMToolbarController: NSViewController {
         childToolBarView?.view.frame = childToolBarBox.frame
         childToolBarView?.delegate = self
         childToolBarView?.view.autoresizingMask = [.width, .height]
-        childToolBarView?.pdfView = self.listView!
+        if let data = self.listView {
+            childToolBarView?.pdfView = data
+        }
         
         toolbarType = .None
         mainToolBarView?.toolbarType = .Main
@@ -243,14 +247,14 @@ class KMToolbarController: NSViewController {
         }
         
         var item: KMToolbarItemView?
-        for (key, value) in self.mainToolBarView!.toolbarItems {
+        for (key, value) in self.mainToolBarView?.toolbarItems ?? [:] {
             if (key == identifier) {
-                item = (value as! KMToolbarItemView)
+                item = (value as? KMToolbarItemView)
                 break
             }
         }
         // 主工具栏 item
-        if (item != nil) {
+        if let data = item {
             if (identifier == KMDocumentAnnotationToolbarItemIdentifier ||
                 identifier == KMDocumentPageToolbarItemIdentifier ||
                 identifier == KMDocumentConversonToolbarItemIdentifier ||
@@ -258,15 +262,15 @@ class KMToolbarController: NSViewController {
                 identifier == KMDocumentFormToolbarItemIdentifier ||
                 identifier == KMDocumentFillSginToolbarItemIdentifier ||
                 identifier == KMDocumentToolToolbarItemIdentifier) {
-                self.mainToolBarView?.leftControllButtonAction(item: item!.clickButton)
+                self.mainToolBarView?.leftControllButtonAction(item: data.clickButton)
             } else if (identifier == KMRightControlToolbarItemIdentifier) {
-                self.mainToolBarView?.itemAction(item!)
+                self.mainToolBarView?.itemAction(data)
             } else if (identifier == KMLeftControlToolbarItemIdentifier) {
-                self.mainToolBarView?.itemAction(item!)
+                self.mainToolBarView?.itemAction(data)
             } else if identifier == KMDocumentRedactToolbarItemIdentifier {
-                self.mainToolBarView?.itemAction(item!)
+                self.mainToolBarView?.itemAction(data)
             } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
-                self.mainToolBarView?.itemAction(item!)
+                self.mainToolBarView?.itemAction(data)
             }
             
             return
@@ -276,10 +280,10 @@ class KMToolbarController: NSViewController {
     private func trySelectChildItem(_ identifier: String) -> Bool {
         // 子工具栏 item [当前主工具栏已开启]
         var item: KMToolbarItemView?
-        if (self.childToolBarView?.toolbarItems != nil && self.childToolBarView!.toolbarItems.count > 0) {
-            for (key, value) in self.childToolBarView!.toolbarItems {
+        if let items = self.childToolBarView?.toolbarItems, items.count > 0 {
+            for (key, value) in items {
                 if (key == identifier) {
-                    item = (value as! KMToolbarItemView)
+                    item = (value as? KMToolbarItemView)
                     break
                 }
             }
@@ -295,26 +299,26 @@ class KMToolbarController: NSViewController {
     private func selectChildItem(_ identifier: String) {
         // 子工具栏 item [当前主工具栏已开启]
         var item: KMToolbarItemView?
-        if (self.childToolBarView?.toolbarItems != nil && self.childToolBarView!.toolbarItems.count > 0) {
-            for (key, value) in self.childToolBarView!.toolbarItems {
+        if let items = self.childToolBarView?.toolbarItems, items.count > 0 {
+            for (key, value) in items {
                 if (key == identifier) {
-                    item = (value as! KMToolbarItemView)
+                    item = (value as? KMToolbarItemView)
                     break
                 }
             }
             // 子工具栏[找到]
-            if (item != nil) {
+            if let data = item {
                 if (identifier == KMToolbarMoveToolModeItemIdentifier ||
                     identifier == KMToolbarMagnifyToolModeItemIdentifier ||
                     identifier == KMToolbarSelectToolModeItemIdentifier ||
                     identifier == KMToolbarZoomToSelectionItemIdentifier) {
-                    self.childToolBarView?.leftControllButtonAction(item: item!.clickButton)
+                    self.childToolBarView?.leftControllButtonAction(item: data.clickButton)
                 } else if identifier == KMToolbarViewSettingIdentifier ||
                             identifier == KMAnnotationImageToolbarItemIdentifier ||
                             identifier == KMAnnotationTableToolbarItemIdentifier {
-                    self.childToolBarView?.itemAction(item!)
+                    self.childToolBarView?.itemAction(data)
                 } else {
-                    self.childToolBarView?.changeAnnotationMode(item: item!.clickButton)
+                    self.childToolBarView?.changeAnnotationMode(item: data.clickButton)
                 }
             }
         }
@@ -327,9 +331,9 @@ class KMToolbarController: NSViewController {
         
         var item: KMToolbarItemView?
         if (isMainToolItem(identifier)) {
-            for (key, value) in self.mainToolBarView!.toolbarItems {
+            for (key, value) in self.mainToolBarView?.toolbarItems ?? [:] {
                 if (key == identifier) {
-                    item = (value as! KMToolbarItemView)
+                    item = (value as? KMToolbarItemView)
                     break
                 }
             }
@@ -344,9 +348,9 @@ class KMToolbarController: NSViewController {
         }
             
         var item: KMToolbarItemView?
-        for (key, value) in self.childToolBarView!.toolbarItems {
+        for (key, value) in self.childToolBarView?.toolbarItems ?? [:] {
             if (key == identifier) {
-                item = (value as! KMToolbarItemView)
+                item = (value as? KMToolbarItemView)
                 break
             }
         }
@@ -354,8 +358,10 @@ class KMToolbarController: NSViewController {
     }
     
     func exitPageEdit() -> Void {
-        resetToolbarViewController(mainToolBarView!)
-        exitPageEditToolbarViewController(mainToolBarView!)
+        if let data = self.mainToolBarView {
+            resetToolbarViewController(data)
+            exitPageEditToolbarViewController(data)
+        }
     }
     
     func exitTextEdit() -> Void {
@@ -370,8 +376,8 @@ class KMToolbarController: NSViewController {
         self.toolbarType = .None
         
         let topBarView = KMWatermarkAdjectiveTopBarView()
-        topBarView.frame = (self.mainToolBarView?.toolbar.bounds)!
-        self.mainToolBarView?.toolbar.addSubview(topBarView)
+        topBarView.frame = (self.mainToolBarView?.toolbar?.bounds) ?? .zero
+        self.mainToolBarView?.toolbar?.addSubview(topBarView)
         topBarView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
         topBarView.wantsLayer = true
         topBarView.layer?.backgroundColor = NSColor.white.cgColor
@@ -392,24 +398,21 @@ class KMToolbarController: NSViewController {
         
         topBarView.initItemData(itemArrays: itemModels)
         
-        topBarView.cancelClick = {
-            [unowned self] in
-            self.delegate?.clickChildTool!(type: type, index: 1)
+        topBarView.cancelClick = { [unowned self] in
+            self.delegate?.clickChildTool?(type: type, index: 1)
         }
         
-        topBarView.applyClick = {
-            [unowned self] in
-            self.delegate?.clickChildTool!(type: type, index: 2)
+        topBarView.applyClick = { [unowned self] in
+            self.delegate?.clickChildTool?(type: type, index: 2)
         }
         
-        topBarView.itemClick = {
-            [unowned self] (section: Int, item: Int) -> () in
-            self.delegate?.clickChildTool!(type: type, index: 3+item)
+        topBarView.itemClick = { [unowned self] section,item in
+            self.delegate?.clickChildTool?(type: type, index: 3+item)
         }
     }
     
     func exitWatermarkAdjective() {
-        let topBarView = self.mainToolBarView?.toolbar.subviews.last
+        let topBarView = self.mainToolBarView?.toolbar?.subviews.last
         if (topBarView == nil || topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self) == false) {
             return
         }
@@ -418,7 +421,7 @@ class KMToolbarController: NSViewController {
     }
     
     func fetchTopBarView() -> NSView? {
-        let topBarView = self.mainToolBarView?.toolbar.subviews.last
+        let topBarView = self.mainToolBarView?.toolbar?.subviews.last
         if (topBarView == nil) {
             return nil
         }
@@ -437,22 +440,22 @@ class KMToolbarController: NSViewController {
         self.toolbarType = .None
         
         let topBarView = KMRedactTopToolBar()
-        topBarView.frame = (self.mainToolBarView?.toolbar.bounds)!
-        self.mainToolBarView?.toolbar.addSubview(topBarView)
-        topBarView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
+        topBarView.frame = (self.mainToolBarView?.toolbar?.bounds) ?? .zero
+        self.mainToolBarView?.toolbar?.addSubview(topBarView)
+        topBarView.autoresizingMask = [.width, .height]
         topBarView.wantsLayer = true
         topBarView.layer?.backgroundColor = NSColor.white.cgColor
         
         topBarView.selectItem(0)
-        self.delegate?.clickChildTool!(type: .redact, index: 4)
+        self.delegate?.clickChildTool?(type: .redact, index: 4)
         
         topBarView.itemClick = { [weak self] index in
-            self!.delegate?.clickChildTool!(type: .redact, index: index)
+            self?.delegate?.clickChildTool?(type: .redact, index: index)
         }
     }
     
     func exitRedact() {
-        let topBarView = self.mainToolBarView?.toolbar.subviews.last
+        let topBarView = self.mainToolBarView?.toolbar?.subviews.last
         if (topBarView == nil || topBarView?.isKind(of: KMRedactTopToolBar.self) == false) {
             return
         }
@@ -490,17 +493,17 @@ class KMToolbarController: NSViewController {
     
     @objc func cropItemAction(sender: NSMenuItem) {
         if (sender.tag == 0) { /// 裁剪当前页面
-            self.delegate?.clickChildTool!(type: .crop, index: 1)
+            self.delegate?.clickChildTool?(type: .crop, index: 1)
             return
         }
         
         if (sender.tag == 1) { /// 裁剪所有页面
-            self.delegate?.clickChildTool!(type: .crop, index: 2)
+            self.delegate?.clickChildTool?(type: .crop, index: 2)
             return
         }
         
         /// 自定义裁剪区域
-        self.delegate?.clickChildTool!(type: .crop, index: 3)
+        self.delegate?.clickChildTool?(type: .crop, index: 3)
     }
     
     @objc func secureItemAction(sender: NSMenuItem) {
@@ -522,34 +525,39 @@ class KMToolbarController: NSViewController {
 //MARK: Find Search
 extension KMToolbarController {
     func showFindBar() {
-        print("showFindBar")
         var height: Float = self.fetchHeight(type: _toolbarType)
         self.delegate?.toolbarController?(self, heightOffsetChange: height)
         
         self.findSearchView.findField.becomeFirstResponder()
         self.findSearchView.doneAction = { [unowned self] view in
-            print("doneAction")
             self.exitFindBar()
         }
         
-        self.findSearchView.searchAction = { view, searchString, forward in
-            print("searchAction")
-            self.toolbarViewController(self.mainToolBarView!, searchAction: searchString, forward: forward)
+        self.findSearchView.searchAction = { [weak self] view, searchString, forward in
+            if let data = self?.mainToolBarView {
+                self?.toolbarViewController(data, searchAction: searchString, forward: forward)
+            }
             return true
         }
         
         self.findSearchView.showAllAction = { [unowned self] view, searchString, forward in
-            self.toolbarViewController(self.mainToolBarView!, searchAllAction: searchString, forward: forward)
-            print("showAllAction: \(searchString)")
+            if let data = self.mainToolBarView {
+                self.toolbarViewController(data, searchAllAction: searchString, forward: forward)
+            }
         }
     }
     
     func showFindString(forward: Bool) {
-        self.toolbarViewController(self.mainToolBarView!, searchAction: self.findSearchView.findString ?? "", forward: forward)
+        if let data = self.mainToolBarView {
+            self.toolbarViewController(data, searchAction: self.findSearchView.findString ?? "", forward: forward)
+        }
+        
     }
     
     func showAllAction() {
-        self.toolbarViewController(self.mainToolBarView!, searchAllAction: self.findSearchView.findString ?? "", forward: true)
+        if let data = self.mainToolBarView {
+            self.toolbarViewController(data, searchAllAction: self.findSearchView.findString ?? "", forward: true)
+        }
     }
     
     func exitFindBar() {
@@ -606,14 +614,14 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
             //文字编辑 图片编辑 选中按钮逻辑(只能同时选中其中一个)
             if type == .addText || type == .addImage {
                 let boxItem = item.clickObject as? KMToolbarItemView
-                if boxItem != nil {
-                    if self.lastChildItemBox != boxItem {
+                if let data = boxItem {
+                    if self.lastChildItemBox != data {
                         self.lastChildItemBox.isSelected = false
-                        boxItem!.isSelected = true
+                        data.isSelected = true
                     } else {
-                        boxItem!.isSelected = !boxItem!.isSelected
+                        data.isSelected = !data.isSelected
                     }
-                    self.lastChildItemBox = boxItem!
+                    self.lastChildItemBox = data
                 }
             }
             
@@ -720,9 +728,9 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
                 
                 if downEntered {
                     if (count == titles.first) {
-                        self!.delegate?.clickChildTool?(type: .crop, index: 1)
+                        self?.delegate?.clickChildTool?(type: .crop, index: 1)
                     } else {
-                        self!.delegate?.clickChildTool?(type: .crop, index: 2)
+                        self?.delegate?.clickChildTool?(type: .crop, index: 2)
                     }
                 }
             }
@@ -751,9 +759,9 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
             vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
                 if downEntered {
                     if (count == titles.first) {
-                        self!.delegate?.clickChildTool?(type: .secure, index: 1)
+                        self?.delegate?.clickChildTool?(type: .secure, index: 1)
                     } else {
-                        self!.delegate?.clickChildTool?(type: .secure, index: 2)
+                        self?.delegate?.clickChildTool?(type: .secure, index: 2)
                     }
                 }
             }

+ 19 - 17
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarItemView.swift

@@ -17,7 +17,7 @@ class KMToolbarClickButton: NSButton {
 }
 
 extension NSControl.ImagePosition {
-    static let imageExpandLeft: NSControl.ImagePosition = .init(rawValue: 100)!
+    static let imageExpandLeft: NSControl.ImagePosition = .init(rawValue: 100) ?? .imageLeft
 }
 
 private let KMPopOverClosedByWindowNotificationName = "KMPopOverClosedByWindowNotification"
@@ -49,10 +49,12 @@ extension KMToolbarItemView {
             if self.itemIdentifier != KMToolbarDividerItemIdentifier {
                 if (isSelected) {
                     if(self.image != nil && self.alternateImage != nil) {
-                        if (self.selectedImage != nil) {
-                            self.imageViewBtn.image = self.selectedImage!
+                        if let data = self.selectedImage {
+                            self.imageViewBtn.image = data
                         } else {
-                            self.imageViewBtn.image = self.alternateImage!
+                            if let data = self.alternateImage {
+                                self.imageViewBtn.image = data
+                            }
                         }
                     }
                     if (self.nameBtn.superview != nil) {
@@ -65,8 +67,8 @@ extension KMToolbarItemView {
                     if (self.needExpandAction) {
                         self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
                     }
-                    if (self.image != nil) {
-                        self.imageViewBtn.image = self.image!
+                    if let data = self.image {
+                        self.imageViewBtn.image = data
                     }
                     if (self.nameBtn.superview != nil) {
                         self.nameBtn.setTitleColor(color: Self.fetchTextNormalColor())
@@ -82,8 +84,8 @@ extension KMToolbarItemView {
             self.nameBtn.isEnabled = !self.unEnabled
             self.imageViewBtn.isEnabled = !self.unEnabled
             self.needExpandButton.isEnabled = !self.unEnabled
-            if self.customizeView != nil {
-                self.subviewsdEnable(view: self.customizeView!, isEnable: !self.unEnabled)
+            if let data = self.customizeView {
+                self.subviewsdEnable(view: data, isEnable: !self.unEnabled)
             }
         }
     }
@@ -168,7 +170,7 @@ extension KMToolbarItemView {
             if self.promptIdentifier_ != newValue {
                 self.promptIdentifier_ = newValue
                 
-                if let data = KMDataManager.ud_object(forKey: newValue!) as? Bool {
+                if let data = KMDataManager.ud_object(forKey: newValue ?? "") as? Bool {
                     self.isShowPrompt = !data
                 } else {
                     self.isShowPrompt = true
@@ -774,24 +776,24 @@ extension KMToolbarItemView: KMCustomButtonPopMenuViewControllerDelegate, KMCust
 
 extension KMToolbarItemView {
     func subviewsdEnable(view: NSView, isEnable: Bool) {
-        if ((view as? NSButton) != nil) {
-            (view as! NSButton).isEnabled = isEnable
+        if let data = view as? NSButton {
+            data.isEnabled = isEnable
         }
         
-        if ((view as? NSTextField) != nil) {
-            (view as! NSTextField).isEnabled = isEnable
+        if let data = (view as? NSTextField) {
+            data.isEnabled = isEnable
         }
         
         for subview in view.subviews {
             if subview.subviews.count != 0 {
                 self.subviewsdEnable(view: subview, isEnable: isEnable)
             }
-            if ((subview as? NSButton) != nil) {
-                (subview as! NSButton).isEnabled = isEnable
+            if let data = subview as? NSButton {
+                data.isEnabled = isEnable
             }
             
-            if ((subview as? NSTextField) != nil) {
-                (subview as! NSTextField).isEnabled = isEnable
+            if let data = (subview as? NSTextField) {
+                data.isEnabled = isEnable
             }
         }
     }

+ 15 - 21
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarView.swift

@@ -176,9 +176,6 @@ private let KMToolbarItemSpace = 8.0
         var iWidth: CGFloat = 0
         for i in 0 ..< (itemIdentifiers.count-self._invisibleItems.count) {
             let itemIdentifier = itemIdentifiers[i]
-//            if (![itemIdentifier isKindOfClass:[NSString class]]) {
-//                return;
-//            }
             var item: KMToolbarItemView?
             if itemIdentifier == KMToolbarDividerItemIdentifier {
                 item = KMToolbarItemView(itemIdentifier: itemIdentifier, postition: .imageOnly, withPopMenu: nil)
@@ -190,11 +187,11 @@ private let KMToolbarItemSpace = 8.0
             } else if let data = self.delegate?.toolbar?(self, itemFor: itemIdentifier) {
                 item = data
             }
-            if (item == nil) {
+            guard let data = item else {
                 continue
             }
 
-            self.contentView.addSubview(item!)
+            self.contentView.addSubview(data)
 //            if (lastItem != nil) {
 //                if (i == itemIdentifiers.count - 1) {
 //                    item?.mas_makeConstraints({ make in
@@ -223,8 +220,8 @@ private let KMToolbarItemSpace = 8.0
 //                    })
 //                }
 //            }
-            items.append(item!)
-            iWidth += item!.itemWidth
+            items.append(data)
+            iWidth += data.itemWidth
             if lastItem != nil {
                 // + 前一个的间距
                 iWidth += Self.kHSpace
@@ -271,9 +268,6 @@ private let KMToolbarItemSpace = 8.0
         var iWidth: CGFloat = 0
         for i in 0 ..< itemIdentifiers.count {
             let itemIdentifier = itemIdentifiers[i]
-//            if (![itemIdentifier isKindOfClass:[NSString class]]) {
-//                return;
-//            }
             var item: KMToolbarItemView?
             if itemIdentifier == KMToolbarDividerItemIdentifier {
                 item = KMToolbarItemView(itemIdentifier: itemIdentifier, postition: .imageOnly, withPopMenu: nil)
@@ -285,11 +279,11 @@ private let KMToolbarItemSpace = 8.0
             } else if let data = self.delegate?.toolbar?(self, itemFor: itemIdentifier) {
                 item = data
             }
-            if (item == nil) {
+            guard let data = item else {
                 continue
             }
 
-            self.contentView.addSubview(item!)
+            self.contentView.addSubview(data)
 //            if (lastItem != nil) {
 //                if (i == itemIdentifiers.count - 1) {
 //                    item?.mas_makeConstraints({ make in
@@ -331,9 +325,9 @@ private let KMToolbarItemSpace = 8.0
 //                    })
 //                }
 //            }
-            items.append(item!)
+            items.append(data)
 
-            iWidth += item!.itemWidth
+            iWidth += data.itemWidth
             if lastItem != nil {
                 // + 前一个的间距
                 iWidth += Self.kHSpace
@@ -342,7 +336,7 @@ private let KMToolbarItemSpace = 8.0
             lastItem = item
 //            posX += item!.frame.size.width
         }
-        self._items = items;
+        self._items = items
         self._centerWidth = iWidth
         
         self.addSubview(self.moreButton)
@@ -382,11 +376,11 @@ private let KMToolbarItemSpace = 8.0
                 } else if let data = self.delegate?.toolbar?(self, itemFor: itemIdentifier) {
                     item = data
                 }
-                if (item == nil) {
+                guard let data = item else {
                     continue
                 }
                 
-                self.leftView.addSubview(item!)
+                self.leftView.addSubview(data)
 //                if (lastItem != nil) {
 //                    if (i == itemIdentifiers.count - 1) {
 //                        item?.mas_makeConstraints({ make in
@@ -419,7 +413,7 @@ private let KMToolbarItemSpace = 8.0
 //                        })
 //                    }
 //                }
-                iWidth += item!.itemWidth
+                iWidth += data.itemWidth
                 if lastItem != nil {
                     // + 前一个的间距
                     iWidth += Self.kHSpace
@@ -469,11 +463,11 @@ private let KMToolbarItemSpace = 8.0
                     item = data
                 }
                 
-                if (item == nil) {
+                guard let data = item else {
                     continue
                 }
                 
-                self.rightView.addSubview(item!)
+                self.rightView.addSubview(data)
 //                if (lastItem != nil) {
 //                    if (i == itemIdentifiers.count - 1) {
 //                        item?.mas_makeConstraints({ make in
@@ -505,7 +499,7 @@ private let KMToolbarItemSpace = 8.0
 //                        })
 //                    }
 //                }
-                iWidth += item!.itemWidth
+                iWidth += data.itemWidth
                 if lastItem != nil {
                     // + 前一个的间距
                     iWidth += Self.kHSpace

+ 51 - 50
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -118,7 +118,7 @@ import Cocoa
 
 class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
 
-    var toolbar : KMToolbarView!
+    var toolbar : KMToolbarView?
     var toolbarType : KMToolbarViewType = KMToolbarViewType.None
     var toolbarItems : [String : Any] = [:]
     @IBOutlet weak  var mainWindowController : MainWindowController!
@@ -146,10 +146,10 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
         super.loadView()
         
         self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
-        self.toolbar.frame = self.view.bounds
-        self.toolbar.autoresizingMask = [.width,.height]
-        self.toolbar.delegate = self
-        self.view.addSubview(self.toolbar)
+        self.toolbar?.frame = self.view.bounds
+        self.toolbar?.autoresizingMask = [.width,.height]
+        self.toolbar?.delegate = self
+        self.view.addSubview(self.toolbar!)
         
         self.view.addSubview(self.bottomLine)
         self.bottomLine.frame = NSMakeRect(0, 0, NSWidth(self.view.bounds), 1)
@@ -161,23 +161,23 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
     func updateType(newType:KMToolbarViewType) {
         if newType != toolbarType {
             toolbarType = newType
-            if self.toolbar != nil && self.toolbar.superview != nil {
-                self.toolbar.removeFromSuperview()
+            if self.toolbar != nil && self.toolbar?.superview != nil {
+                self.toolbar?.removeFromSuperview()
             }
             self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
-            self.toolbar.frame = self.view.bounds
-            self.toolbar.autoresizingMask = [.width,.height]
-            self.toolbar.delegate = self
-            self.view.addSubview(self.toolbar)
+            self.toolbar?.frame = self.view.bounds
+            self.toolbar?.autoresizingMask = [.width,.height]
+            self.toolbar?.delegate = self
+            self.view.addSubview(self.toolbar!)
         }
     }
     
     func reloadateToolbar() -> Void {
-        toolbar.reloadData()
+        self.toolbar?.reloadData()
     }
     
     func resetToolbar() -> Void {
-        for item in toolbar.items {
+        for item in self.toolbar?.items ?? [] {
             item.isSelected = false
         }
     }
@@ -216,13 +216,14 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
                 return
             }
         }
-        let itemView = item.clickObject as! KMToolbarItemView
-        if itemView.itemIdentifier == KMDocumentRedactToolbarItemIdentifier {
-            self.delegate?.toolbarViewController?(self, clickMode: .redact, toolbar: itemView, [])
-        } else {
-            self.delegate?.toolbarViewController?(self, itemDidClick: item.clickObject as! KMToolbarItemView)
+        if let itemView = item.clickObject as? KMToolbarItemView {
+            if itemView.itemIdentifier == KMDocumentRedactToolbarItemIdentifier {
+                self.delegate?.toolbarViewController?(self, clickMode: .redact, toolbar: itemView, [])
+            } else {
+                self.delegate?.toolbarViewController?(self, itemDidClick: itemView)
+            }
+            self._itemSetPromptFlag(item: itemView)
         }
-        self._itemSetPromptFlag(item: item.clickObject as? KMToolbarItemView)
     }
     
     @objc private func _menuItemAction(_ item: NSMenuItem) {
@@ -245,12 +246,11 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
     }
     
     @IBAction func showPDFLayoutMode(sender: KMToolbarClickButton) {
-        let item = sender.clickObject as? KMToolbarItemView
-        if (item != nil) {
-            item?.isSelected = !item!.isSelected
+        if let item = sender.clickObject as? KMToolbarItemView {
+            item.isSelected = !item.isSelected
+            self.delegate?.showPDFLayoutModeAction?(show: true)
+            self._itemSetPromptFlag(item: item)
         }
-        self.delegate?.showPDFLayoutModeAction?(show: true)
-        self._itemSetPromptFlag(item: item)
     }
     
     @objc func cropMenuAction(item: KMToolbarItemView) {
@@ -359,25 +359,26 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
     }
     
     @objc func conversionMenuItemAction(sender: KMToolbarClickButton) {
-        let item: KMToolbarItemView = sender.clickObject as! KMToolbarItemView
-        var type: KMToolbarType = .word
-        if (item.btnTag == KMToolbarType.excel.rawValue) {
-            type = .excel
-        } else if (item.btnTag == KMToolbarType.ppt.rawValue) {
-            type = .ppt
-        } else if (item.btnTag == KMToolbarType.rtf.rawValue) {
-            type = .rtf
-        } else if (item.btnTag == KMToolbarType.csv.rawValue) {
-            type = .csv
-        } else if (item.btnTag == KMToolbarType.html.rawValue) {
-            type = .html
-        } else if (item.btnTag == KMToolbarType.conversion_text.rawValue) {
-            type = .conversion_text
-        } else if (item.btnTag == KMToolbarType.conversion_image.rawValue) {
-            type = .conversion_image
+        if let item: KMToolbarItemView = sender.clickObject as? KMToolbarItemView {
+            var type: KMToolbarType = .word
+            if (item.btnTag == KMToolbarType.excel.rawValue) {
+                type = .excel
+            } else if (item.btnTag == KMToolbarType.ppt.rawValue) {
+                type = .ppt
+            } else if (item.btnTag == KMToolbarType.rtf.rawValue) {
+                type = .rtf
+            } else if (item.btnTag == KMToolbarType.csv.rawValue) {
+                type = .csv
+            } else if (item.btnTag == KMToolbarType.html.rawValue) {
+                type = .html
+            } else if (item.btnTag == KMToolbarType.conversion_text.rawValue) {
+                type = .conversion_text
+            } else if (item.btnTag == KMToolbarType.conversion_image.rawValue) {
+                type = .conversion_image
+            }
+            self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
+            self._itemSetPromptFlag(item: item)
         }
-        self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
-        self._itemSetPromptFlag(item: item)
     }
     
     @objc private func _pdfToImageAction(sender: NSMenuItem) {
@@ -542,7 +543,7 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
     override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
         super.interfaceThemeDidChanged(appearance)
         
-        self.toolbar.appearance = .init(named: appearance)
+        self.toolbar?.appearance = .init(named: appearance)
     }
 }
 
@@ -711,7 +712,7 @@ extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidatio
             if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) && (pId != KMDocumentAnnotationToolbarItemIdentifier || data.itemIdentifier! == KMToolbarAnnotationSettingItemIdentifier) {
                 create = true
             } else {
-                if let toolbarId = self.toolbar.toolbarIdentifier {
+                if let toolbarId = self.toolbar?.toolbarIdentifier {
                     let itemIdentifiers = (UserDefaults.standard.object(forKey: toolbarId) as? [String]) ?? []
                     if itemIdentifiers.contains(identifier) && annotationToolIdentifiers.contains(identifier) == false {
                         create = true
@@ -874,7 +875,7 @@ extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidatio
             UserDefaults.standard.set(pdfView.annotationType.rawValue, forKey: KMToolBarToolPDFShapeStyle)
             UserDefaults.standard.synchronize()
         }
-        for item in self.toolbar.items {
+        for item in self.toolbar?.items ?? [] {
             if self.toolbarType == .Annatiton || self.toolbarType == .Move || self.toolbarType == .Magnify ||
                 self.toolbarType == .Select || self.toolbarType == .SelectZoom {
                 item.isSelected = false
@@ -1263,7 +1264,7 @@ extension KMToolbarViewController {
             item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(shareButtonAction)
             
-            let menuItem = NSMenuItem.init(title: item!.titleName ?? "", action: nil, target: self)
+            let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: nil, target: self)
             let menu = NSMenu()
             menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
             menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
@@ -1964,12 +1965,12 @@ extension KMToolbarViewController {
             item?.target = self
             item?.btnTag = KMToolbarType.bates.rawValue
 //            item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
-            item?.titleName = NSLocalizedString("Bates Number", comment: "")
+            item?.titleName = NSLocalizedString("Bates Numbers", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
 //            item?.btnAction = #selector(batesMenuAction)
             
-            let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(batesMenuAction), target: self)
+            let menuItem = NSMenuItem.init(title: "Bates Numbers", action: #selector(batesMenuAction), target: self)
             let subMenu = NSMenu()
             subMenu.addItem(title: NSLocalizedString("Add Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 1)
             subMenu.addItem(title: NSLocalizedString("Remove Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 2)
@@ -2019,12 +2020,12 @@ extension KMToolbarViewController {
             item?.target = self
             item?.btnTag = KMToolbarType.background.rawValue
 //            item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
-            item?.titleName = NSLocalizedString("Backgroud", comment: "")
+            item?.titleName = NSLocalizedString("Background", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
 //            item?.btnAction = #selector(backgroundMenuAction)
             
-            let menuItem = NSMenuItem.init(title: "Backgroud", action: #selector(backgroundMenuAction), target: self)
+            let menuItem = NSMenuItem.init(title: "Background", action: #selector(backgroundMenuAction), target: self)
             let subMenu = NSMenu()
             subMenu.addItem(title: NSLocalizedString("Add Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 1)
             subMenu.addItem(title: NSLocalizedString("Remove Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 2)

+ 2 - 6
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -518,8 +518,8 @@ let LOCKED_KEY  = "locked"
                     } else {
                         (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: false)
                     }
-                } else if ((model?.isKind(of: KMHeaderFooterModel.self))!) {
-                    if ((model as! KMHeaderFooterModel).hasVaild) {
+                } else if ((model?.isKind(of: KMHeaderFooterObject.self))!) {
+                    if ((model as! KMHeaderFooterObject).hasVaild) {
                         (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: true)
                     } else {
                         (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: false)
@@ -1051,11 +1051,7 @@ let LOCKED_KEY  = "locked"
             }
         }
         
-//        #if VERSION_DMG
-//        let controller = KMPDFEditViewController_dmg(self.listView.document)
-//        #else
         let controller = KMPDFEditViewController(self.listView.document)
-//        #endif
         
         controller.selectedPages = tPages
         controller.listView = self.listView

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

@@ -49,9 +49,14 @@
 
 * 签名 KMSignatureAnnotationViewController
 
+* 水印
 * 水印模板 KMBatchOperateAddWatermarkViewController
 * 水印模板编辑 KMWatermarkWindowController
 
+* 背景
+* 背景模板 KMBatchOperateAddWatermarkViewController
+* 背景模板编辑 KMBackgroundWindowController
+
 ## What's New
 * KMFunctionGuideWindowController
 

+ 8 - 12
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -3781,6 +3781,9 @@
 		BB8115FF2992682F0008F536 /* KMSecureLimitAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8115FE2992682F0008F536 /* KMSecureLimitAlertView.swift */; };
 		BB8116002992682F0008F536 /* KMSecureLimitAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8115FE2992682F0008F536 /* KMSecureLimitAlertView.swift */; };
 		BB8116012992682F0008F536 /* KMSecureLimitAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8115FE2992682F0008F536 /* KMSecureLimitAlertView.swift */; };
+		BB83B8EC2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB83B8EB2BA8415900EFF584 /* KMPageEditExtractWindowController.swift */; };
+		BB83B8ED2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB83B8EB2BA8415900EFF584 /* KMPageEditExtractWindowController.swift */; };
+		BB83B8EE2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB83B8EB2BA8415900EFF584 /* KMPageEditExtractWindowController.swift */; };
 		BB853C632AF87425009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB853C622AF87425009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift */; };
 		BB853C642AF87428009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB853C622AF87425009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift */; };
 		BB853C652AF8742A009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB853C622AF87425009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift */; };
@@ -4201,7 +4204,6 @@
 		BBA5429C29F13A140041BAD0 /* KMMemorandumPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA5429B29F13A140041BAD0 /* KMMemorandumPattern.swift */; };
 		BBA5429D29F13A140041BAD0 /* KMMemorandumPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA5429B29F13A140041BAD0 /* KMMemorandumPattern.swift */; };
 		BBA5429E29F13A140041BAD0 /* KMMemorandumPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA5429B29F13A140041BAD0 /* KMMemorandumPattern.swift */; };
-		BBA5B64A2A823E0200748A83 /* KMPDFEditViewController_dmg.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA5B6492A823E0200748A83 /* KMPDFEditViewController_dmg.swift */; };
 		BBA762D229D2D98D00844513 /* KMCommonDefine.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA762D129D2D98D00844513 /* KMCommonDefine.swift */; };
 		BBA762D329D2D98D00844513 /* KMCommonDefine.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA762D129D2D98D00844513 /* KMCommonDefine.swift */; };
 		BBA762D429D2D98D00844513 /* KMCommonDefine.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBA762D129D2D98D00844513 /* KMCommonDefine.swift */; };
@@ -4628,9 +4630,6 @@
 		BBD1F77F296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBD1F77B296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib */; };
 		BBD1F780296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBD1F77B296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib */; };
 		BBD1F781296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBD1F77B296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib */; };
-		BBD1F783296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F782296F9DB500343885 /* KMPageEditExtractWindowController.swift */; };
-		BBD1F784296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F782296F9DB500343885 /* KMPageEditExtractWindowController.swift */; };
-		BBD1F785296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F782296F9DB500343885 /* KMPageEditExtractWindowController.swift */; };
 		BBD1F787296FAC7C00343885 /* KMPageEditSettingBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F786296FAC7C00343885 /* KMPageEditSettingBaseView.swift */; };
 		BBD1F788296FAC7C00343885 /* KMPageEditSettingBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F786296FAC7C00343885 /* KMPageEditSettingBaseView.swift */; };
 		BBD1F789296FAC7C00343885 /* KMPageEditSettingBaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD1F786296FAC7C00343885 /* KMPageEditSettingBaseView.swift */; };
@@ -6683,6 +6682,7 @@
 		BB7FF5062A60E84400901C2D /* KMEnumExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMEnumExtensions.swift; sourceTree = "<group>"; };
 		BB8115FA29924A5F0008F536 /* KMSecureEncryptCheckCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptCheckCellView.swift; sourceTree = "<group>"; };
 		BB8115FE2992682F0008F536 /* KMSecureLimitAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureLimitAlertView.swift; sourceTree = "<group>"; };
+		BB83B8EB2BA8415900EFF584 /* KMPageEditExtractWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMPageEditExtractWindowController.swift; sourceTree = "<group>"; };
 		BB853C622AF87425009C20C1 /* KMBatchOperateRemoveWatermarkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchOperateRemoveWatermarkViewController.swift; sourceTree = "<group>"; };
 		BB853C662AF87502009C20C1 /* KMBatchOperateRemoveWatermarkViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMBatchOperateRemoveWatermarkViewController.xib; sourceTree = "<group>"; };
 		BB853C6A2AF8782A009C20C1 /* KMRemoveWatermarkOperationQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRemoveWatermarkOperationQueue.swift; sourceTree = "<group>"; };
@@ -6853,7 +6853,6 @@
 		BBA2109329ACC10F00E6B346 /* signlist_add.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = signlist_add.pdf; sourceTree = "<group>"; };
 		BBA388122AEF9A42004FE93F /* NSWindow+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSWindow+KMExtension.swift"; sourceTree = "<group>"; };
 		BBA5429B29F13A140041BAD0 /* KMMemorandumPattern.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMMemorandumPattern.swift; sourceTree = "<group>"; };
-		BBA5B6492A823E0200748A83 /* KMPDFEditViewController_dmg.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFEditViewController_dmg.swift; sourceTree = "<group>"; };
 		BBA762D129D2D98D00844513 /* KMCommonDefine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCommonDefine.swift; sourceTree = "<group>"; };
 		BBA8B66D2B9027D500CB07B0 /* SKFileUpdateChecker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKFileUpdateChecker.m; sourceTree = "<group>"; };
 		BBA8B66E2B9027D600CB07B0 /* SKFileUpdateChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKFileUpdateChecker.h; sourceTree = "<group>"; };
@@ -7019,7 +7018,6 @@
 		BBCE57172A72723600508EFC /* NSResponder+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSResponder+KMExtension.swift"; sourceTree = "<group>"; };
 		BBD1F77A296F9BE000343885 /* KMPageEditSettingBaseWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageEditSettingBaseWindowController.swift; sourceTree = "<group>"; };
 		BBD1F77B296F9BE000343885 /* KMPageEditSettingBaseWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPageEditSettingBaseWindowController.xib; sourceTree = "<group>"; };
-		BBD1F782296F9DB500343885 /* KMPageEditExtractWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageEditExtractWindowController.swift; sourceTree = "<group>"; };
 		BBD1F786296FAC7C00343885 /* KMPageEditSettingBaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageEditSettingBaseView.swift; sourceTree = "<group>"; };
 		BBD1F78A296FACA300343885 /* KMPageEditExtractSettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageEditExtractSettingView.swift; sourceTree = "<group>"; };
 		BBD1F78E296FE6A500343885 /* KMPageEditSplitWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPageEditSplitWindowController.swift; sourceTree = "<group>"; };
@@ -11087,7 +11085,6 @@
 			isa = PBXGroup;
 			children = (
 				BB1EC7FC2967B26700EC0BC3 /* KMPDFEditViewController.swift */,
-				BBA5B6492A823E0200748A83 /* KMPDFEditViewController_dmg.swift */,
 				BB1EC7FD2967B26700EC0BC3 /* KMPDFEditViewController.xib */,
 			);
 			path = Controller;
@@ -11250,6 +11247,7 @@
 		BB2EDF49296E6373003BCF58 /* Window */ = {
 			isa = PBXGroup;
 			children = (
+				BB83B8EB2BA8415900EFF584 /* KMPageEditExtractWindowController.swift */,
 				BB1969D02B2833FE00922736 /* KMProgressWindowController.xib */,
 				BBF62C732B0347D0007B7E86 /* SplitWindowController.xib */,
 				BBF62C6B2B033B5A007B7E86 /* KMPDFEditExtractWindow.xib */,
@@ -11257,7 +11255,6 @@
 				BB10FAE82AFE03CC00F18D65 /* KMPDFEditPageRangeWindowController.xib */,
 				BB2EDF4A296E63E5003BCF58 /* KMPageEditInsertCustomPageWindowController.swift */,
 				BB2EDF4B296E63E5003BCF58 /* KMPageEditInsertCustomPageWindowController.xib */,
-				BBD1F782296F9DB500343885 /* KMPageEditExtractWindowController.swift */,
 				BBD1F78E296FE6A500343885 /* KMPageEditSplitWindowController.swift */,
 				BB10FAE42AFE039E00F18D65 /* KMPDFEditPageRangeWindowController.swift */,
 				BB03D68B2B01C782008C9976 /* KMPDFEditInsertBlankPageWindow.swift */,
@@ -15243,6 +15240,7 @@
 				BB003021298CEBED002DD1A0 /* KMPreferenceStepper.swift in Sources */,
 				9FB220D72B0F4ED400A5B208 /* KMAnnotationSelectLinkViewController.swift in Sources */,
 				9FDD0FA629533494000C4DAD /* KMJSONParser.swift in Sources */,
+				BB83B8EC2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */,
 				BBFE6E7F2930EBD400142C01 /* KMCompressWindowController.swift in Sources */,
 				AD1CA4302A0640F20070541F /* KMAnnotationScreenHeadView.swift in Sources */,
 				BB3A66A32B0783BD00575343 /* KMTocTableCellView.swift in Sources */,
@@ -15597,7 +15595,6 @@
 				BB2EDF6D296ECE17003BCF58 /* KMPageEditInsertDirectionItemView.swift in Sources */,
 				BB570ADF2B513A66005E7E4A /* KMLeftSideViewController+Snapshot.swift in Sources */,
 				BB30D4822B90249D00702541 /* KMStatusBar.m in Sources */,
-				BBD1F783296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */,
 				BB146FB1299DC0D100784A6A /* GTLRErrorObject.m in Sources */,
 				ADAFDA482AEA7F1300F084BC /* KMAdvertisementShowView.swift in Sources */,
 				BB03D6942B021124008C9976 /* NSSegmentedControl+KMExtension.swift in Sources */,
@@ -16553,6 +16550,7 @@
 				BB671A022AD2D2A0003D44D5 /* CPDFStampAnnotation+PDFListView.swift in Sources */,
 				BB8810D12B4F980E00AFA63E /* NSNULL+Filtration.m in Sources */,
 				AD58F4202B1DC29100299EE0 /* KMPrintViewModel.swift in Sources */,
+				BB83B8ED2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */,
 				BB65A0552AF8B90F003A27A0 /* KMDisplayPreferences.swift in Sources */,
 				BB74DA7C2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */,
 				BB0FE0382B734DD1001E0F88 /* AIConfigWindowController.swift in Sources */,
@@ -16787,7 +16785,6 @@
 				9F1FE4B229406E4700E952CA /* CTTabWindowController.m in Sources */,
 				BB2EDF6E296ECE17003BCF58 /* KMPageEditInsertDirectionItemView.swift in Sources */,
 				BB6013912AD3AFF000A76FB2 /* NSPopover+KMExtension.swift in Sources */,
-				BBD1F784296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */,
 				BB146FB2299DC0D100784A6A /* GTLRErrorObject.m in Sources */,
 				BB1BFF722AEA0AFE003EB179 /* KMBatchOperateLeftViewController.swift in Sources */,
 				BBB9B31A299A5D6D004F3235 /* KMCloudServer.m in Sources */,
@@ -17585,6 +17582,7 @@
 				AD055E832B88294F0035F824 /* SKBookmarkController.m in Sources */,
 				BBAC26A62AFE134300563A08 /* KMToolbarItemPopViewController.swift in Sources */,
 				BB93CDEB2AE7B6E100B29C57 /* KMToolbarView.swift in Sources */,
+				BB83B8EE2BA8415A00EFF584 /* KMPageEditExtractWindowController.swift in Sources */,
 				AD1D48232AFB6BBA007AC1F0 /* KMMergeView.swift in Sources */,
 				BB403BAC2B15CA6E00B3106D /* KMBatchConvertOperation.swift in Sources */,
 				BB1EC8002967B26700EC0BC3 /* KMPDFEditViewController.swift in Sources */,
@@ -17855,7 +17853,6 @@
 				BB2F9AB12AFCAE1F00F9DD93 /* KMProfileTitleCellView.swift in Sources */,
 				BB2F615A2966B69D001CB369 /* KMWatermarkPropertyHomeController.swift in Sources */,
 				89752E1F2942CB04003FF08E /* KMSearchMode.swift in Sources */,
-				BBD1F785296F9DB500343885 /* KMPageEditExtractWindowController.swift in Sources */,
 				BB147049299DC0D200784A6A /* OIDServiceConfiguration.m in Sources */,
 				ADE3C1C329A4C13700793B13 /* KMPrintAccessoryController_OC.m in Sources */,
 				BB5DF1EB2959C5CB0025CDA1 /* KMHeaderFooterPreviewController.swift in Sources */,
@@ -17989,7 +17986,6 @@
 				BB8F4541295A98960037EA22 /* KMHeaderFooterPropertyController.swift in Sources */,
 				BBFE6E6F2930D9C600142C01 /* KMMergeSettingWindowController.swift in Sources */,
 				AD7D5CCD2B95728C006562CD /* KMBookmarkOutlineTitleCellView.swift in Sources */,
-				BBA5B64A2A823E0200748A83 /* KMPDFEditViewController_dmg.swift in Sources */,
 				ADAFD9F52AE68A7400F084BC /* KMCreatPDFView.swift in Sources */,
 				BB74DA792AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */,
 				BB493F972B3E9805003E6175 /* KMBatchQuickActionManager.swift in Sources */,

+ 128 - 0
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -68,5 +68,133 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "7C1F3382-B4CF-4707-B8C8-21EA61B227D7"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "187"
+            endingLineNumber = "187"
+            landmarkName = "deleteAllTemplates()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "F7DD2FDE-9C75-4B1A-8FC1-34FB5E1A5BCF"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "168"
+            endingLineNumber = "168"
+            landmarkName = "deleteAllTemplates()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "A2AA2A43-A90A-48C1-A3CA-800C60ECCA83"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "193"
+            endingLineNumber = "193"
+            landmarkName = "deleteAllColorTemplates()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "36D5CBC8-3449-4928-B955-1B9A151F06D0"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Background/tool/KMBackgroundManager.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "228"
+            endingLineNumber = "228"
+            landmarkName = "deleteAllFileTemplates()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "2EF02E13-4AAA-4D8B-988C-ED1A4A323F95"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Background/Controller/KMBackgroundPropertyController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "79"
+            endingLineNumber = "79"
+            landmarkName = "deleteAllTemplateModel(in:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "F1534BAD-9AE9-4B9F-AA49-A2CC2C46C512"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/AddHeaderFooter/VC/KMBatchOperateAddHeaderFooterViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "201"
+            endingLineNumber = "201"
+            landmarkName = "buttonItemClick_CleanAll(_:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "6C49AA2A-33CD-43DD-8B45-B0BFEA1B641A"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Watermark/Controller/KMBatchOperateAddWatermarkViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "651"
+            endingLineNumber = "651"
+            landmarkName = "_buttonItemClick_CleanAll(_:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "B4C39154-973C-43C3-9AA6-2A5BD02235DF"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFTools/Watermark/Controller/KMBatchOperateAddWatermarkViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "749"
+            endingLineNumber = "749"
+            landmarkName = "_deleteAllWatermark()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

Різницю між файлами не показано, бо вона завелика
+ 776 - 321
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist