Browse Source

【编辑工具】数据兼容 - 页眉页脚,bates码颜色与字体兼容

lizhe 11 months ago
parent
commit
84ea50ff33
18 changed files with 283 additions and 1483 deletions
  1. 4 4
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPreviewController.swift
  2. 9 9
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyController.swift
  3. 5 4
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyHomeController.swift
  4. 12 12
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyInfoController.swift
  5. 4 4
      PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMCreateBatesController.swift
  6. 1 1
      PDF Office/PDF Master/Class/PDFTools/Bates/Model/KMBatesModel.swift
  7. 14 14
      PDF Office/PDF Master/Class/PDFTools/Bates/Tools/KMBatesManager.swift
  8. 3 3
      PDF Office/PDF Master/Class/PDFTools/Bates/View/KMBatesPrefixInfoView.swift
  9. 12 5
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Base/KMHeaderFooterAdjectiveModel.swift
  10. 1 1
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Model/KMHeaderFooterModel.swift
  11. 3 3
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMDataVersionManager.swift
  12. 4 671
      PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMHeaderFooterManager.swift
  13. 26 2
      PDF Office/PDF Master/Class/PDFTools/Watermark/Base/KMWatermarkAdjectiveBaseModel.swift
  14. 2 2
      PDF Office/PDF Master/Class/PDFTools/Watermark/OCPart/KMWatermarkPDFView_OC.m
  15. 7 7
      PDF Office/PDF Master/Class/PDFTools/Watermark/Tools/KMWatermarkAdjectiveTools.swift
  16. 2 2
      PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift
  17. 2 2
      PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift
  18. 172 737
      PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

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

@@ -41,7 +41,7 @@ class KMBatesPreviewController: KMWatermarkAdjectivePreViewBaseController {
         controller.view.autoresizingMask = [.width, .height]
         self.right_gotoViewController(viewController: controller)
         controller.modelDidChange = { [weak self] model in
-            if (model == nil || (model! as! KMBatesModel).hasVaild == false) {
+            if (model == nil || (model! as! KMHeaderFooterObject).hasVaild == false) {
                 self!.topBarView.isCanApply(can: false)
                 self?.model = nil
             } else {
@@ -99,7 +99,7 @@ class KMBatesPreviewController: KMWatermarkAdjectivePreViewBaseController {
             return
         }
         
-        if ((self.model as! KMBatesModel).hasVaild == false) {
+        if ((self.model as! KMHeaderFooterObject).hasVaild == false) {
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("Failure", comment: "")
@@ -108,7 +108,7 @@ class KMBatesPreviewController: KMWatermarkAdjectivePreViewBaseController {
         }
         
         self.beginLoading()
-        self.addBates(model: self.model! as! KMBatesModel, toPath: self.preView.document.documentURL.path, completion: {
+        self.addBates(model: self.model! as! KMHeaderFooterObject, toPath: self.preView.document.documentURL.path, completion: {
             result in
             DispatchQueue.main.async {
                 self.preView.layoutDocumentView()
@@ -129,7 +129,7 @@ class KMBatesPreviewController: KMWatermarkAdjectivePreViewBaseController {
         })
     }
     
-    private func addBates(model: KMBatesModel, toPath: String, completion: @escaping (_ result: Bool) -> ()) {
+    private func addBates(model: KMHeaderFooterObject, toPath: String, completion: @escaping (_ result: Bool) -> ()) {
         DispatchQueue.global().async {
             let document: CPDFDocument = self.applyDocument!
             var property = document.bates()

+ 9 - 9
PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyController.swift

@@ -7,8 +7,8 @@
 
 import Cocoa
 
-typealias KMBatesPropertyTemplateDidSelected = (_ model: KMBatesModel,_ isSelected: Bool)->()
-typealias KMBatesPropertyTemplateMenuItemClick = (_ itemIndex: Int,  _ model: KMBatesModel)->()
+typealias KMBatesPropertyTemplateDidSelected = (_ model: KMHeaderFooterObject,_ isSelected: Bool)->()
+typealias KMBatesPropertyTemplateMenuItemClick = (_ itemIndex: Int,  _ model: KMHeaderFooterObject)->()
 class KMBatesPropertyController: KMWatermarkAdjectivePropertyBaseController {
 
     var templateDidSelected: KMBatesPropertyTemplateDidSelected!
@@ -40,11 +40,11 @@ class KMBatesPropertyController: KMWatermarkAdjectivePropertyBaseController {
     
     func reloadDatas () {
         let controller: KMHeaderFooterListController = childViewController[0] as! KMHeaderFooterListController
-        controller.initDatas(datas: KMBatesManager.defaultManager.datas)
+        controller.initDatas(datas: KMHeaderFooterManager.defaultManager().headFooterObjects)
     }
     
-    func deleteTemplateModel(_ templateModel: KMBatesModel) -> Bool {
-        return KMBatesManager.defaultManager.deleteTemplate(templateModel)
+    func deleteTemplateModel(_ templateModel: KMHeaderFooterObject) -> Bool {
+        return KMHeaderFooterManager.defaultManager().addHeaderFooter(templateModel)
     }
     
     func deleteTemplateModel(in controller: KMHeaderFooterListController, index: Int) {
@@ -52,24 +52,24 @@ class KMBatesPropertyController: KMWatermarkAdjectivePropertyBaseController {
             return
         }
         
-        let templateModel: KMBatesModel = controller.datas[index] as! KMBatesModel
+        let templateModel: KMHeaderFooterObject = controller.datas[index] as! KMHeaderFooterObject
         if (deleteTemplateModel(templateModel)) { /// 删除成功,刷新数据
             reloadDatas()
         }
     }
     
     func deleteAllTemplateModel(in controller: KMHeaderFooterListController) {
-        if (KMBatesManager.defaultManager.deleteAllTemplate()) {
+        if (KMHeaderFooterManager.defaultManager().removeAllHeaderFooter()) {
             reloadDatas()
         }
     }
     
-    func findTemplateModel(in controller: KMHeaderFooterListController, index: Int) -> KMBatesModel? {
+    func findTemplateModel(in controller: KMHeaderFooterListController, index: Int) -> KMHeaderFooterObject? {
         if (index >= controller.datas.count) {
             return nil
         }
         
-        return (controller.datas[index] as! KMBatesModel)
+        return (controller.datas[index] as! KMHeaderFooterObject)
     }
     
 }

+ 5 - 4
PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMBatesPropertyHomeController.swift

@@ -46,7 +46,8 @@ class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController
     
     override func gotoCreateController() {
         let controller = KMCreateBatesController()
-        let model: KMBatesModel = KMBatesModel()
+        let model: KMHeaderFooterObject = KMHeaderFooterObject()
+        model.type = .bates
         model.pageCount = self.pageCount
         controller.model = model
         
@@ -60,7 +61,7 @@ class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController
             /// 保存到模板
             let createController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
             if (createController.model != nil) {
-                let model: KMBatesModel = createController.model as! KMBatesModel
+                let model: KMHeaderFooterObject = createController.model as! KMHeaderFooterObject
                 if (!model.hasVaild) {
                     let alert = NSAlert()
                     alert.alertStyle = .warning
@@ -68,7 +69,7 @@ class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController
                     alert.runModal()
                     return
                 }
-                let result = KMBatesManager.defaultManager.addTemplate(model)
+                let result = KMHeaderFooterManager.defaultManager().addHeaderFooter(model)
                 if (result) {
                     guard let callback = self!.modelDidChange else {
                         return
@@ -105,7 +106,7 @@ class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController
             let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
             if (editController.isEdited) {
                 /// 更新模板
-                let result = KMBatesManager.defaultManager.updateTemplate(editController.model as! KMBatesModel)
+                let result = KMHeaderFooterManager.defaultManager().store()
 //                if (result) {
                     
                 self!.gotoHomeController("")

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

@@ -35,8 +35,8 @@ class KMBatesPropertyInfoController: NSViewController {
         super.init(nibName: "KMBatesPropertyInfoController", bundle: nil)
     }
     
-    private var myModel: KMBatesModel!
-    var model: KMBatesModel {
+    private var myModel: KMHeaderFooterObject!
+    var model: KMHeaderFooterObject {
         get {
             return myModel
         }
@@ -47,7 +47,7 @@ class KMBatesPropertyInfoController: NSViewController {
             self.marginView.model = newValue
             self.preFixView.model = newValue
             
-            self.pageView.leftStepper.value = Double(newValue.digits)
+            self.pageView.leftStepper.value = Double(newValue.batesDigits)
             self.pageView.rightComboBox.removeAllItems()
             for i in 0 ..< newValue.pageCount {
                 self.pageView.rightComboBox.addItem(withObjectValue: i+1)
@@ -132,9 +132,9 @@ class KMBatesPropertyInfoController: NSViewController {
         self.preSufFixBox.contentView?.addSubview(preFixView)
         preFixView.itemClick = { [weak self] (index: Int, value: Any) in
             if (index == 1) {
-                self!.model.prefixString = value as! String
+                self!.model.batesPrefixString = value as! String
             } else if (index == 2) {
-                self!.model.suffixString = value as! String
+                self!.model.batesSuffixString = value as! String
             }
 
             if (self!.delegate != nil) {
@@ -148,7 +148,7 @@ class KMBatesPropertyInfoController: NSViewController {
         self.pageBox.contentView?.addSubview(pageView)
         pageView.itemClick = { [weak self] (index: Int, value: Any) in
             if (index == 1) { /// 位数
-                self!.model.digits = Int(value as! Double)
+                self!.model.batesDigits = Int(value as! Double)
             } else if (index == 2) { /// 起始页
                 self!.model.startString = "\(value as! Int+1)"
             }
@@ -165,17 +165,17 @@ class KMBatesPropertyInfoController: NSViewController {
         contentView.addAction = { [self]
             (index: Int, sender: NSButton) in
             
-            var string: String = "<<#\(self.model.digits)"
+            var string: String = "<<#\(self.model.batesDigits)"
             string.append("#\(self.model.startString)")
             
-            if (!self.model.prefixString.isEmpty) {
-                string.append("#\(self.model.prefixString)")
-            } else if (!self.model.suffixString.isEmpty) {
+            if (!self.model.batesPrefixString.isEmpty) {
+                string.append("#\(self.model.batesPrefixString)")
+            } else if (!self.model.batesSuffixString.isEmpty) {
                 string.append("#")
             }
             
-            if (!self.model.suffixString.isEmpty) {
-                string.append("#\(self.model.suffixString)")
+            if (!self.model.batesSuffixString.isEmpty) {
+                string.append("#\(self.model.batesSuffixString)")
             }
             string.append(">>")
             

+ 4 - 4
PDF Office/PDF Master/Class/PDFTools/Bates/Controller/KMCreateBatesController.swift

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

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

@@ -1,5 +1,5 @@
 //
-//  KMBatesModel.swift
+//  KMHeaderFooterObject.swift
 //  PDF Reader Pro
 //
 //  Created by tangchao on 2022/12/28.

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

@@ -13,7 +13,7 @@ class KMBatesManager: NSObject {
     
     static let defaultManager = KMBatesManager()
     
-    var datas: Array<KMBatesModel> = []
+    var datas: Array<KMHeaderFooterObject> = []
     
     override init() {
         super.init()
@@ -38,7 +38,7 @@ class KMBatesManager: NSObject {
         }
     }
     
-    func addTemplate(_ model: KMBatesModel) -> Bool {
+    func addTemplate(_ model: KMHeaderFooterObject) -> Bool {
         if (!FileManager.default.fileExists(atPath: kFolderPath!)) {
             let create: ()? = try?FileManager.default.createDirectory(atPath: kFolderPath!, withIntermediateDirectories: false)
             if (create == nil) {
@@ -78,7 +78,7 @@ class KMBatesManager: NSObject {
         return result
     }
     
-    func deleteTemplate(_ model: KMBatesModel) -> Bool {
+    func deleteTemplate(_ model: KMHeaderFooterObject) -> Bool {
         if (model.id.isEmpty) {
             return false
         }
@@ -130,7 +130,7 @@ class KMBatesManager: NSObject {
         return result
     }
     
-    func updateTemplate(_ model: KMBatesModel) -> Bool {
+    func updateTemplate(_ model: KMHeaderFooterObject) -> Bool {
         if (!FileManager.default.fileExists(atPath: kFolderPath!)) {
             let create = try?FileManager.default.createDirectory(atPath: kFolderPath!, withIntermediateDirectories: false)
             if (create == nil) {
@@ -145,7 +145,7 @@ class KMBatesManager: NSObject {
             }
         }
         
-        var flagModel: KMBatesModel!
+        var flagModel: KMHeaderFooterObject!
         for model_ in self.datas {
             if (model_.id == model.id) {
                 flagModel = model_
@@ -179,7 +179,7 @@ class KMBatesManager: NSObject {
     /**
         `Private Methods`
      */
-    private func parseModel(model: KMBatesModel) -> Dictionary<String, Any> {
+    private func parseModel(model: KMHeaderFooterObject) -> Dictionary<String, Any> {
         var dict: [String : Any] = [:]
         /// 字体相关
         switch model.textFont {
@@ -212,9 +212,9 @@ class KMBatesManager: NSObject {
         dict["bottomCenterString"] = model.bottomCenterString
         dict["bottomRightString"] = model.bottomRightString
         
-        dict["prefixString"] = model.prefixString
-        dict["suffixString"] = model.suffixString
-        dict["digits"] = model.digits
+        dict["prefixString"] = model.batesPrefixString
+        dict["suffixString"] = model.batesSuffixString
+        dict["digits"] = model.batesDigits
         dict["startString"] = model.startString
         
         dict["pageRangeType"] = model.pageRangeType
@@ -223,8 +223,8 @@ class KMBatesManager: NSObject {
         return dict
     }
     
-    private func parseDictionary(dict: NSDictionary) -> KMBatesModel {
-        let model = KMBatesModel()
+    private func parseDictionary(dict: NSDictionary) -> KMHeaderFooterObject {
+        let model = KMHeaderFooterObject()
         
         /// 字体相关
         model.textFont = .font(name: dict["fontName"] as! String, size: dict["fontSize"] as! CGFloat)
@@ -244,9 +244,9 @@ class KMBatesManager: NSObject {
         model.bottomCenterString = dict["bottomCenterString"] as! String
         model.bottomRightString = dict["bottomRightString"] as! String
         
-        model.prefixString = dict["prefixString"] as! String
-        model.suffixString = dict["suffixString"] as! String
-        model.digits = dict["digits"] as! Int
+        model.batesPrefixString = dict["prefixString"] as! String
+        model.batesSuffixString = dict["suffixString"] as! String
+        model.batesDigits = dict["digits"] as! Int
         model.startString = dict["startString"] as! String
         
         model.pageRangeType = KMWatermarkeModelPageRangeType(rawValue: dict["pageRangeType"] as! Int)!

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/Bates/View/KMBatesPrefixInfoView.swift

@@ -64,9 +64,9 @@ class KMBatesPrefixInfoView: KMHeaderFooterAdjectiveInfoBaseView {
         set {
             super.model = newValue
             
-            let myModel: KMBatesModel = newValue as! KMBatesModel
-            self.preFixTextField.stringValue = myModel.prefixString
-            self.sufFixTextField.stringValue = myModel.suffixString
+            let myModel: KMHeaderFooterObject = newValue as! KMHeaderFooterObject
+            self.preFixTextField.stringValue = myModel.batesPrefixString
+            self.sufFixTextField.stringValue = myModel.batesSuffixString
         }
     }
 }

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

@@ -7,7 +7,14 @@
 
 import Cocoa
 
+enum KMHeaderFooterObjectType: Int {
+    case headerFooter = 0
+    case bates
+}
+
 @objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding {
+    var type: KMHeaderFooterObjectType = .headerFooter
+    
     var leftMargin: Int = 30
     var rightMargin: Int = 30
     var bottomMargin: Int = 30
@@ -72,7 +79,8 @@ import Cocoa
     
     required init?(coder: NSCoder) {
         super.init()
-        pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "type"))!
+        type = KMHeaderFooterObjectType.init(rawValue: coder.decodeInteger(forKey: "type"))!
+        pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "pageChoice"))!
         leftMargin = coder.decodeInteger(forKey: "leftMargin")
         rightMargin = coder.decodeInteger(forKey: "rightMargin")
         bottomMargin = coder.decodeInteger(forKey: "bottomMargin")
@@ -87,7 +95,6 @@ import Cocoa
         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")
@@ -101,7 +108,8 @@ import Cocoa
     }
 
     func encode(with coder: NSCoder) {
-        coder.encode(pageRangeType.rawValue, forKey: "type")
+        coder.encode(type.rawValue, forKey: "type")
+        coder.encode(pageRangeType.rawValue, forKey: "pageChoice")
         coder.encode(leftMargin, forKey: "leftMargin")
         coder.encode(rightMargin, forKey: "rightMargin")
         coder.encode(bottomMargin, forKey: "bottomMargin")
@@ -114,12 +122,11 @@ import Cocoa
         coder.encode(bottomRightString, forKey: "bottomRightString")
         coder.encode(startString, forKey: "startString")
         coder.encode(fontSize, forKey: "fontSize")
-        coder.encode(tempTextColor, forKey: "textColor")
+        coder.encode(self.getTextColor(), 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")

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

@@ -9,7 +9,6 @@ import Cocoa
 
 class KMHeaderFooterObject: KMHeaderFooterAdjectiveModel, NSCopying {
     
-    
     var dateFormatString: String = KMWatermarkAdjectiveTools.getDateFormats().first!
     var pageFormatString: String = KMWatermarkAdjectiveTools.getPageFormats().first!
     var batesPrefixString: String = ""
@@ -47,6 +46,7 @@ class KMHeaderFooterObject: KMHeaderFooterAdjectiveModel, NSCopying {
     
     func copy(with zone: NSZone? = nil) -> Any {
         let obj = KMHeaderFooterObject()
+        obj.type = type
         obj.pageRangeType = pageRangeType
         obj.leftMargin = leftMargin
         obj.rightMargin = rightMargin

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

@@ -7,13 +7,13 @@
 
 import Foundation
 
-let KMBatesManagerVersion = "KMBatesManagerVersion"
+let KMHeaderFooterManagerVersion = "KMHeaderFooterManagerVersion"
 
 class KMDataVersionManager: NSObject{
     class func updateBatesData() -> Bool {
         var defaults = UserDefaults.standard
-        if  (defaults.object(forKey: KMBatesManagerVersion) != nil) {
-            defaults.setValue("1", forKey: KMBatesManagerVersion)
+        if  (defaults.object(forKey: KMHeaderFooterManagerVersion) != nil) {
+            defaults.setValue("1", forKey: KMHeaderFooterManagerVersion)
             return true
         }
         return false

+ 4 - 671
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMHeaderFooterManager.swift

@@ -1,578 +1,7 @@
-//
-//  KMHeaderFooterManager.swift
-//  PDF Reader Pro
-//
-//  Created by tangchao on 2022/12/27.
-//
-
-//import Cocoa
-//
-//let kHeaderFooterInfoSaveKey = "kHeaderFooterInfoSaveKey"
-
-//class KMHeaderFooterManager: NSObject, NSCoding{
-//    
-//    
-//    let kFolderPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("headerfooter")
-//    let kPlistPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("headerfooter").stringByAppendingPathComponent("headerfooter.plist")
-//    
-//    static let defaultManager = KMHeaderFooterManager()
-////    = {
-////        var manager = KMHeaderFooterManager()
-////        if let storedData = UserDefaults.standard.value(forKey: kHeaderFooterInfoSaveKey) as? Data {
-////            manager = NSKeyedUnarchiver.unarchiveObject(with: storedData) as! KMHeaderFooterManager
-////        } else {
-////            manager = KMHeaderFooterManager()
-//////            if manager.headFooterObjects == nil {
-//////                manager.headFooterObjects = []
-//////            }
-////        }
-////        return manager
-////    }()
-//    
-//    func encode(with coder: NSCoder) {
-////        coder.encode(self.headFooterObjects, forKey: "headFooterObjects")
-//    }
-//    
-//    required init?(coder: NSCoder) {
-////        self.headFooterObjects = coder.decodeObject(forKey: "headFooterObjects") as? [KMHeaderFooterObject]
-//    }
-//    
-//    var datas: Array<KMHeaderFooterObject> = []
-//    
-////    var headFooterObjects: [KMHeaderFooterObject]?
-//    
-//    lazy var dateFormatArray: Array = {
-//        let arr = [
-//            "m/d",
-//            "m/d/yy",
-//            "m/d/yyyy",
-//            "mm/dd/yy",
-//            "mm/dd/yyyy",
-//            "d/m/yy",
-//            "d/m/yyyy",
-//            "dd/mm/yy",
-//            "dd/mm/yyyy",
-//            "mm/yy",
-//            "mm/yyyy",
-//            "m.d.yy",
-//            "m.d.yyyy",
-//            "mm.dd.yy",
-//            "mm.dd.yyyy",
-//            "mm.yy",
-//            "mm.yyyy",
-//            "d.m.yy",
-//            "d.m.yyyy",
-//            "dd.mm.yy",
-//            "dd.mm.yyyy",
-//            "yy-mm-dd",
-//            "yyyy-mm-dd"
-//        ]
-//        return arr
-//    }()
-//    
-//    func onlyBatesObjects() -> [KMHeaderFooterObject] {
-//        var arr: [KMHeaderFooterObject] = Array<KMHeaderFooterObject>()
-//        for i in 0..<datas.count {
-//            let obj = self.datas[i]
-//            if KMDataVersionManager.updateBatesData() {
-//                KMDataVersionManager.refrshBatesData(bates: obj)
-//                store()
-//            }
-//            
-//            if obj.isBates {
-//                arr.append(obj)
-//            }
-//        }
-//        return arr
-//    }
-//    func onlyHeaderFooterObjects() -> [KMHeaderFooterObject]{
-//        var arr: [KMHeaderFooterObject] = Array<KMHeaderFooterObject>()
-//        for i in 0..<self.datas.count {
-//            let obj = self.datas[i]
-//            
-//            if !obj.isBates {
-//                arr.append(obj)
-//            }
-//        }
-//        return arr
-//    }
-//    override init() {
-//        super.init()
-//        if (FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            let dataDict = NSDictionary(contentsOfFile: kPlistPath!)
-//            if (dataDict == nil) {
-//                return
-//            }
-//            
-//            for keyIndex in 0 ..< (dataDict?.allKeys.count ?? 0) {
-//                let key: String = dataDict?.allKeys[keyIndex] as! String
-//                let backgroundDict: NSDictionary = dataDict?.object(forKey: key) as! NSDictionary
-//                
-//                let model = parseDictionary(dict: backgroundDict)
-//                /// 赋值id
-//                model.id = key
-//                self.datas.append(model)
-//            }
-//            
-//            /// 根据id进行排序(升序)
-//            self.datas.sort(){$0.id > $1.id}
-//        }
-//    }
-//    
-//    func store() { 
-//        let encodedObject = NSKeyedArchiver.archivedData(withRootObject: self)
-//        let defaults = UserDefaults.standard 
-//        defaults.set(encodedObject, forKey: kHeaderFooterInfoSaveKey)
-//        defaults.synchronize()
-//    }
-//    
-//    func fetchBatesAvailableName() -> String {
-//        var availableIndex = 0
-//        let nameArray = converArrType(arr: onlyBatesObjects(), keyString: "id")
-//        for i in 0..<nameArray.count {
-//            let string = nameArray[i]
-//            if string.hasPrefix("Bates") {
-//                let index = Int(string.substring(from: "Bates".endIndex))!
-//                if index >= availableIndex {
-//                    availableIndex = index + 1
-//                }
-//            }
-//        }
-//        return String(format: "Bates%ld", availableIndex)
-//    }
-//    
-//    func fetchHeaderFooterAvailableName() -> String {
-//        var availableIndex = 0
-//        let nameArray = converArrType(arr: onlyHeaderFooterObjects(), keyString: "id")
-//        for i in 0..<nameArray.count {
-//            let string = nameArray[i]
-//            if string.hasPrefix("HeaderFooter") {
-//                let index = Int(string.substring(from: "HeaderFooter".endIndex))!
-//                if index >= availableIndex {
-//                    availableIndex = index + 1
-//                }
-//            }
-//        }
-//        return  String(format: "HeaderFooter%ld", availableIndex)
-//    }
-//    
-//    func converArrType(arr: Array<KMHeaderFooterObject>, keyString: String) -> [String] {
-//        let newArr = NSMutableArray()
-//        for item in arr {
-//            newArr.add(item.id)
-//        }
-//        return newArr as! [String]
-//    }
-//    
-//    func addTemplate(_ model: KMHeaderFooterObject) -> Bool {
-//        if (!FileManager.default.fileExists(atPath: kFolderPath!)) {
-//            let create: ()? = try?FileManager.default.createDirectory(atPath: kFolderPath!, withIntermediateDirectories: false)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            let create = try?FileManager.default.createFile(atPath: kPlistPath!, contents: nil)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        let dict = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDict:NSMutableDictionary!
-//        if (dict != nil) {
-//            newDict = NSMutableDictionary(dictionary: dict!)
-//        } else {
-//            newDict = NSMutableDictionary()
-//        }
-//        
-//        let modelDict = self.parseModel(model: model)
-//        
-//        let tag = model.id
-//        newDict.addEntries(from: [tag : modelDict])
-//        model.id = tag
-//        let result = newDict.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            if (self.datas.count < 1) {
-//                self.datas.append(model)
-//            } else {
-//                self.datas.insert(model, at: 0)
-//            }
-//        }
-//        
-//        return result
-//    }
-//    
-//    func deleteTemplate(_ model: KMHeaderFooterObject) -> Bool {
-//        if (model.id.isEmpty) {
-//            return false
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            return false
-//        }
-//        
-//        let key: String = model.id
-//        
-//        let dictionary = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDictionary: NSMutableDictionary!
-//        if (dictionary != nil) {
-//            newDictionary = NSMutableDictionary(dictionary: dictionary!)
-//        } else {
-//            newDictionary = NSMutableDictionary()
-//        }
-//        newDictionary.removeObject(forKey: key)
-//        
-//        let result = newDictionary.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            if (self.datas.contains(model)) {
-//                self.datas.removeObject(model)
-//            }
-//        }
-//        return result
-//    }
-//    
-//    func deleteAllTemplate() -> Bool {
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            return false
-//        }
-//        
-//        let dictionary = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDictionary: NSMutableDictionary!
-//        if (dictionary != nil) {
-//            newDictionary = NSMutableDictionary(dictionary: dictionary!)
-//        } else {
-//            newDictionary = NSMutableDictionary()
-//        }
-//        
-//        newDictionary.removeAllObjects()
-//        
-//        let result = newDictionary.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            self.datas.removeAll()
-//        }
-//        
-//        return result
-//    }
-//    
-//    func updateTemplate(_ model: KMHeaderFooterObject) -> Bool {
-//        if (!FileManager.default.fileExists(atPath: kFolderPath!)) {
-//            let create = try?FileManager.default.createDirectory(atPath: kFolderPath!, withIntermediateDirectories: false)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            let create = try?FileManager.default.createFile(atPath: kPlistPath!, contents: nil)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        var flagModel: KMHeaderFooterObject!
-//        for model_ in self.datas {
-//            if (model_.id == model.id) {
-//                flagModel = model_
-//                break
-//            }
-//        }
-//        
-//        if (flagModel == nil) {
-//            return false
-//        }
-//        
-//        let dict = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDict:NSMutableDictionary!
-//        if (dict != nil) {
-//            newDict = NSMutableDictionary(dictionary: dict!)
-//        } else {
-//            newDict = NSMutableDictionary()
-//        }
-//        
-//        let modelDict = self.parseModel(model: model)
-//        newDict.setObject(modelDict, forKey: flagModel.id as NSCopying)
-//        let result = newDict.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            let index = self.datas.index(of: flagModel)
-//            self.datas[index!] = model
-//        }
-//        
-//        return result
-//    }
-//    func removeHeaderFooter(_ obj: KMHeaderFooterObject) {
-//        if (obj.id.count < 1) {
-//            return
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            return
-//        }
-//        
-//        let key: String = obj.id
-//        
-//        let dictionary = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDictionary: NSMutableDictionary!
-//        if (dictionary != nil) {
-//            newDictionary = NSMutableDictionary(dictionary: dictionary!)
-//        } else {
-//            newDictionary = NSMutableDictionary()
-//        }
-//        newDictionary.removeObject(forKey: key)
-//        
-//        let result = newDictionary.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            self.datas.removeObject(obj)
-//        }
-//    }
-//    
-//    /**
-//        `Private Methods`
-//     */
-//    private func parseModel(model: KMHeaderFooterObject) -> Dictionary<String, Any> {
-//        var dict: [String : Any] = [:]
-//        /// 字体相关
-//        switch model.textFont {
-//        case .font(name: var name, size: var size):
-//            dict["fontName"] = name
-//            dict["fontSize"] = size
-//        default: break
-//        }
-//        
-//        switch model.textColor {
-//        case .color(red: var red, green: var green, blue: var blue, alpha: var alpha):
-//            dict["red"] = red
-//            dict["green"] = green
-//            dict["blue"] = blue
-//            dict["alpha"] = alpha
-//        default: break
-//        }
-//      
-//        /// 页边距
-//        dict["leftMargin"] = model.leftMargin
-//        dict["rightMargin"] = model.rightMargin
-//        dict["bottomMargin"] = model.bottomMargin
-//        dict["topMargin"] = model.topMargin
-//        dict["isBates"] = model.isBates ? "1" : "0"
-//        
-//        /// 内容
-//        dict["topLeftString"] = model.topLeftString
-//        dict["topCenterString"] = model.topCenterString
-//        dict["topRightString"] = model.topRightString
-//        dict["bottomLeftString"] = model.bottomLeftString
-//        dict["bottomCenterString"] = model.bottomCenterString
-//        dict["bottomRightString"] = model.bottomRightString
-//        
-//        /// 日期
-//        dict["dateFormatString"] = model.dateFormatString
-//        
-//        /// 页面
-//        dict["pageRangeString"] = model.pageRangeString
-//        dict["startString"] = model.startString
-//        
-//        /// 页面范围
-//        dict["pageRangeType"] = model.pageRangeType.rawValue
-//        dict["pageRangeString"] = model.pageRangeString
-//        
-//        return dict
-//    }
-//    
-//    private func parseDictionary(dict: NSDictionary) -> KMHeaderFooterObject {
-//        let model = KMHeaderFooterObject()
-//        
-//        /// 字体相关
-//        model.textFont = .font(name: dict["fontName"] as! String, size: dict["fontSize"] as! CGFloat)
-//        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.topLeftString = dict["topLeftString"] as! String
-//        model.topCenterString = dict["topCenterString"] as! String
-//        model.topRightString = dict["topRightString"] as! String
-//        model.bottomLeftString = dict["bottomLeftString"] as! String
-//        model.bottomCenterString = dict["bottomCenterString"] as! String
-//        model.bottomRightString = dict["bottomRightString"] as! String
-//        model.isBates = false
-//        if (dict["isBates"] != nil) {
-//            model.isBates = (dict["isBates"] as! String == "1")
-//        }
-//        
-//        /// 日期
-//        model.dateFormatString = dict["dateFormatString"] as! String
-//        
-//        /// 页面
-//        model.pageRangeString = dict["pageRangeString"] as! String
-//        model.startString = dict["startString"] as! String
-//        
-//        /// 页面范围
-//        model.pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: dict["pageRangeType"] as! Int)!
-//        model.pageRangeString = dict["pageRangeString"] as! String
-//        
-//        return model
-//    }
-//    
-//    private func tagString() -> String {
-//        var result: String = ""
-//        
-//        let dateFormatter = DateFormatter()
-//        dateFormatter.dateFormat = "yyMMddHHmmss"
-//        result.append(dateFormatter.string(from: Date()))
-//        result = result.appendingFormat("%04d", arc4random()%10000)
-//        
-//        return result
-//    }
-//}
-
-
 import Foundation
 
 private let kHeaderFooterInfoSaveKey = "kHeaderFooterInfoSaveKey"
 
-//class KMHeaderFooterObject: NSObject, NSCoding, NSCopying {
-//    var type: Int = 0
-//    var leftMargin: Int = 0
-//    var rightMargin: Int = 0
-//    var bottomMargin: Int = 0
-//    var topMargin: Int = 0
-//    var topLeftString: String = ""
-//    var topCenterString: String = ""
-//    var topRightString: String = ""
-//    var bottomLeftString: String = ""
-//    var bottomCenterString: String = ""
-//    var bottomRightString: String = ""
-//    var startString: String = ""
-//    var fontSize: Float = 16
-//    var textColor: NSColor = NSColor.black
-//    var pagesString: String = ""
-//    var isBates: Bool = false
-//    var batesPrefixString: String = ""
-//    var batesSuffixString: String = ""
-//    var batesDigits: Int = 0
-//    var hasHeader: Bool = false
-//    var hasFooter: Bool = false
-////    var cellHeight: Float = 0
-//    var headerFooterID: String = ""
-//    var pageChoice: Int = 0
-//    var dateFormatString: String = "m/d"
-//    var pageFormatString: String = "1"
-//
-//    override init() {
-//        super.init()
-//    }
-//
-//    required init?(coder: NSCoder) {
-//        type = 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")
-//        textColor = coder.decodeObject(forKey: "textColor") as? NSColor ?? NSColor.black
-//        pagesString = coder.decodeObject(forKey: "pagesString") as? String ?? ""
-//        isBates = coder.decodeBool(forKey: "isBates")
-//        batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as? String ?? ""
-//        batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as? String ?? ""
-//        batesDigits = coder.decodeInteger(forKey: "batesDigits")
-//        hasHeader = coder.decodeBool(forKey: "hasHeader")
-//        hasFooter = coder.decodeBool(forKey: "hasFooter")
-//        cellHeight = coder.decodeFloat(forKey: "cellHeight")
-//        headerFooterID = coder.decodeObject(forKey: "headerFooterID") as? String ?? ""
-//        pageChoice = coder.decodeInteger(forKey: "pageChoice")
-//        dateFormatString = coder.decodeObject(forKey: "dateFormatString") as? String ?? "m/d"
-//        pageFormatString = coder.decodeObject(forKey: "pageFormatString") as? String ?? "1"
-//    }
-//
-//    func encode(with coder: NSCoder) {
-//        coder.encode(type, 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(textColor, forKey: "textColor")
-//        coder.encode(pagesString, forKey: "pagesString")
-//        coder.encode(isBates, forKey: "isBates")
-//        coder.encode(batesPrefixString, forKey: "batesPrefixString")
-//        coder.encode(batesSuffixString, forKey: "batesSuffixString")
-//        coder.encode(batesDigits, forKey: "batesDigits")
-//        coder.encode(hasHeader, forKey: "hasHeader")
-//        coder.encode(hasFooter, forKey: "hasFooter")
-//        coder.encode(cellHeight, forKey: "cellHeight")
-//        coder.encode(headerFooterID, forKey: "headerFooterID")
-//        coder.encode(pageChoice, forKey: "pageChoice")
-//        coder.encode(dateFormatString, forKey: "dateFormatString")
-//        coder.encode(pageFormatString, forKey: "pageFormatString")
-//    }
-//
-//    func copy(with zone: NSZone? = nil) -> Any {
-//        let obj = KMHeaderFooterObject()
-//        obj.type = type
-//        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.pagesString = pagesString
-//        obj.isBates = isBates
-//        obj.batesPrefixString = batesPrefixString
-//        obj.batesSuffixString = batesSuffixString
-//        obj.batesDigits = batesDigits
-//        obj.hasHeader = hasHeader
-//        obj.hasFooter = hasFooter
-//        obj.cellHeight = cellHeight
-//        obj.headerFooterID = headerFooterID
-//        obj.pageChoice = pageChoice
-//        obj.dateFormatString = dateFormatString
-//        obj.pageFormatString = pageFormatString
-//        return obj
-//    }
-//
-//    var cellHeight: Float {
-//        get {
-//            var baseHeight: Float = 33 + 24
-//            if !topLeftString.isEmpty { baseHeight += 20 }
-//            if !topCenterString.isEmpty { baseHeight += 20 }
-//            if !topRightString.isEmpty { baseHeight += 20 }
-//            if !bottomLeftString.isEmpty { baseHeight += 20 }
-//            if !bottomCenterString.isEmpty { baseHeight += 20 }
-//            if !bottomRightString.isEmpty { baseHeight += 20 }
-//            baseHeight -= 4
-//            return baseHeight
-//        }
-//        set {
-//            
-//        }
-//    }
-//}
-
 class KMHeaderFooterManager: NSObject, NSCoding {
     var headFooterObjects: [KMHeaderFooterObject] = []
 
@@ -654,14 +83,16 @@ class KMHeaderFooterManager: NSObject, NSCoding {
         return true
     }
     
-    func removeAllHeaderFooter() {
+    func removeAllHeaderFooter() -> Bool {
         headFooterObjects.removeAll()
         store()
+        return true
     }
 
-    func addHeaderFooter(_ obj: KMHeaderFooterObject) {
+    func addHeaderFooter(_ obj: KMHeaderFooterObject) -> Bool {
         headFooterObjects.insert(obj, at: 0)
         store()
+        return true
     }
 
     func store() {
@@ -706,103 +137,5 @@ class KMHeaderFooterManager: NSObject, NSCoding {
         }
         return "Bates\(availableIndex)"
     }
-    
-//    func deleteTemplate(_ model: KMHeaderFooterObject) -> Bool {
-//        if (model.id.isEmpty) {
-//            return false
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            return false
-//        }
-//        
-//        let key: String = model.id
-//        
-//        let dictionary = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDictionary: NSMutableDictionary!
-//        if (dictionary != nil) {
-//            newDictionary = NSMutableDictionary(dictionary: dictionary!)
-//        } else {
-//            newDictionary = NSMutableDictionary()
-//        }
-//        newDictionary.removeObject(forKey: key)
-//        
-//        let result = newDictionary.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            if (self.headFooterObjects.contains(model)) {
-//                self.headFooterObjects.removeObject(model)
-//            }
-//        }
-//        return result
-//    }
-    
-//    func deleteAllTemplate() -> Bool {
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            return false
-//        }
-//        
-//        let dictionary = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDictionary: NSMutableDictionary!
-//        if (dictionary != nil) {
-//            newDictionary = NSMutableDictionary(dictionary: dictionary!)
-//        } else {
-//            newDictionary = NSMutableDictionary()
-//        }
-//        
-//        newDictionary.removeAllObjects()
-//        
-//        let result = newDictionary.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            self.headFooterObjects.removeAll()
-//        }
-//        
-//        return result
-//    }
-    
-//    func updateTemplate(_ model: KMHeaderFooterObject) -> Bool {
-//        if (!FileManager.default.fileExists(atPath: kFolderPath!)) {
-//            let create = try?FileManager.default.createDirectory(atPath: kFolderPath!, withIntermediateDirectories: false)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        if (!FileManager.default.fileExists(atPath: kPlistPath!)) {
-//            let create = try?FileManager.default.createFile(atPath: kPlistPath!, contents: nil)
-//            if (create == nil) {
-//                return false
-//            }
-//        }
-//        
-//        var flagModel: KMHeaderFooterObject!
-//        for model_ in self.headFooterObjects {
-//            if (model_.id == model.id) {
-//                flagModel = model_
-//                break
-//            }
-//        }
-//        
-//        if (flagModel == nil) {
-//            return false
-//        }
-//        
-//        let dict = NSDictionary(contentsOfFile: kPlistPath!)
-//        var newDict:NSMutableDictionary!
-//        if (dict != nil) {
-//            newDict = NSMutableDictionary(dictionary: dict!)
-//        } else {
-//            newDict = NSMutableDictionary()
-//        }
-//        
-//        let modelDict = self.parseModel(model: model)
-//        newDict.setObject(modelDict, forKey: flagModel.id as NSCopying)
-//        let result = newDict.write(toFile: kPlistPath!, atomically: true)
-//        if (result) {
-//            let index = self.headFooterObjects.index(of: flagModel)
-//            self.headFooterObjects[index!] = model
-//        }
-//        
-//        return result
-//    }
 }
 

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

@@ -22,9 +22,33 @@ enum KMWatermarkAdjectiveText {
 
 @objcMembers class KMWatermarkAdjectiveBaseModel: NSObject {
     var textFont: KMWatermarkAdjectiveText!
-    var fontSize: Float = 12.0
+    var fontSize: Float = 12.0 {
+        didSet {
+            textFont = KMWatermarkAdjectiveText.font(name: "Helvetica", size: CGFloat(fontSize))
+        }
+    }
     var textColor: KMWatermarkAdjectiveText!
-    var tempTextColor: NSColor = NSColor.black
+    var tempTextColor: NSColor = NSColor.black {
+        didSet {
+//            var red: CGFloat = 0.0
+//            var greed: CGFloat = 0.0
+//            var blue: CGFloat = 0.0
+//            NSColor * oldStrokeColor = [config.oldStrokeColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+//            [oldStrokeColor getRed:&red green:&green blue:&blue alpha:NULL];
+//            oldStrokeColor = [NSColor colorWithRed:red green:green blue:blue alpha:config.oldStrokeOpacity];
+            
+            var red: CGFloat = 0
+            var green: CGFloat = 0
+            var blue: CGFloat = 0
+            var alpha: CGFloat = 0
+
+            let oldStrokeColor = tempTextColor.usingColorSpace(NSColorSpace.deviceRGB)
+            oldStrokeColor?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
+//            let newStrokeColor = NSColor(red: red, green: green, blue: blue, alpha: alpha)
+            
+            textColor = KMWatermarkAdjectiveText.color(red: red, green: green, blue: blue, alpha: alpha)
+        }
+    }
     
     var id: String = ""
     

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

@@ -14,7 +14,7 @@
 
 @property (nonatomic, strong) KMWatermarkModel *watermark;
 @property (nonatomic, strong) KMBackgroundModel *background;
-@property (nonatomic, strong) KMBatesModel *bates;
+@property (nonatomic, strong) KMHeaderFooterObject *bates;
 @property (nonatomic, strong) KMHeaderFooterObject *headerFooter;
 
 @end
@@ -23,7 +23,7 @@
 
 - (void)setModel:(id)model {
     _model = model;
-    if ([model isKindOfClass:[KMBatesModel class]]) {
+    if ([model isKindOfClass:[KMHeaderFooterObject class]]) {
         self.bates = model;
     } else if ([model isKindOfClass:[KMWatermarkModel class]]) {
         self.watermark = model;

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

@@ -149,8 +149,8 @@ case bates = 4
     
     // MARK: Apply
     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)
+        if (model.isKind(of: KMHeaderFooterObject.self)) {
+            KMWatermarkAdjectiveTools.applyBates(model as! KMHeaderFooterObject, 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)) {
@@ -213,7 +213,7 @@ case bates = 4
         }
     }
     
-    private class func applyBates(_ model: KMBatesModel, _ pdfView: CPDFView, _ toPath: String, completion: @escaping (_ result: Bool) -> ()) {
+    private class func applyBates(_ model: KMHeaderFooterObject, _ pdfView: CPDFView, _ toPath: String, completion: @escaping (_ result: Bool) -> ()) {
         DispatchQueue.global().async {
             let document: CPDFDocument = pdfView.document
             var property = document.bates()
@@ -525,8 +525,8 @@ case bates = 4
     
     // MARK: Add
     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)
+        if (model.isKind(of: KMHeaderFooterObject.self)) {
+//            KMWatermarkAdjectiveTools.applyBates(model as! KMHeaderFooterObject, 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)) {
@@ -622,8 +622,8 @@ case bates = 4
     
     // MARK: Update
     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)
+        if (model.isKind(of: KMHeaderFooterObject.self)) {
+//            KMWatermarkAdjectiveTools.applyBates(model as! KMHeaderFooterObject, 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)) {

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

@@ -4033,7 +4033,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 } else if (index == 2) { /// 应用
                     let model = self.rightSideViewController.model
                     if (type == .bates || type == .headerAndFooter) {
-                        if (model == nil || (model?.isKind(of: KMBatesModel.self) == false)) {
+                        if (model == nil || (model?.isKind(of: KMHeaderFooterObject.self) == false)) {
                             let alert = NSAlert()
                             alert.alertStyle = .critical
                             alert.messageText = "没有找到模型"
@@ -4041,7 +4041,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                             return
                         }
                         
-                        if ((model as! KMBatesModel).hasVaild == false) {
+                        if ((model as! KMHeaderFooterObject).hasVaild == false) {
                             let alert = NSAlert()
                             alert.alertStyle = .critical
                             alert.messageText = "没有找到内容"

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

@@ -512,8 +512,8 @@ let LOCKED_KEY  = "locked"
             if (model == nil) {
                 (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: false)
             } else {
-                if ((model?.isKind(of: KMBatesModel.self))!) {
-                    if ((model as! KMBatesModel).hasVaild) {
+                if ((model?.isKind(of: KMHeaderFooterObject.self))!) {
+                    if ((model as! KMHeaderFooterObject).hasVaild) {
                         (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: true)
                     } else {
                         (topBarView as! KMWatermarkAdjectiveTopBarView).isCanApply(can: false)

File diff suppressed because it is too large
+ 172 - 737
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist