Selaa lähdekoodia

【2025】【Edit】文字模块自定义字体信息处理

niehaoyu 2 kuukautta sitten
vanhempi
commit
afc6d6d0c9

+ 14 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFEditArea/CPDFListView+CPDFEditArea.swift

@@ -256,7 +256,6 @@ extension CPDFListView {
         for area in areas {
             self.setEditSelectionCFont(font, with: area)
             _ = self.editingSelectionCFont(with: area)
-            print("1")
         }
     }
     
@@ -292,6 +291,13 @@ extension CPDFListView {
         }
     }
     
+    func setEditingTextarea(isBold bold: Bool) {
+        let areas = self.km_editingTextAreas()
+        for area in areas {
+            _ = self.setCurrentSelectionIsBold(bold, with: area)
+        }
+    }
+    
     func setEditingTextarea_Italic() {
         let areas = self.km_editingTextAreas()
         for area in areas {
@@ -300,6 +306,13 @@ extension CPDFListView {
         }
     }
     
+    func setEditingTextarea(isItalic italic: Bool) {
+        let areas = self.km_editingTextAreas()
+        for area in areas {
+            _ = self.setCurrentSelectionIsItalic(italic, with: area)
+        }
+    }
+    
     func setEditingTextarea_Strikeout() {
         let areas = self.km_editingTextAreas()
         for area in areas {

+ 197 - 19
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/EditPDF/KMEditPDFTextPropertyViewController.swift

@@ -52,6 +52,10 @@ class KMEditPDFTextPropertyViewController: NSViewController {
     
     private var currentArea: CPDFEditTextArea?
     
+    //自定义
+    private var customTextModel: KMEditPDFTextFontModel = KMEditPDFTextFontModel()
+    private var selCustomFontType: KMEditPDFTextFontType = .customize
+    
     //MARK: - func
     override func viewDidAppear() {
         super.viewDidAppear()
@@ -77,8 +81,19 @@ class KMEditPDFTextPropertyViewController: NSViewController {
                                                                text: "")
         if true {
             var menuItemArr: [ComponentMenuitemProperty] = []
-            for string in KMEditPDFTextFontTypeWrapper.allValues() {
-                let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: string)
+            
+            var ids = [Customize_USERDEFAULTS, H1_USERDEFAULTS,
+                       H2_USERDEFAULTS, H3_USERDEFAULTS,
+                       B1_USERDEFAULTS, B2_USERDEFAULTS,
+                       B3_USERDEFAULTS]
+            var strings = KMEditPDFTextFontTypeWrapper.allValues()
+            for i in 0...strings.count - 1 {
+                let string = strings[i]
+                var id = string
+                if i < ids.count {
+                    id = ids[i]
+                }
+                let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: id)
                 menuItemArr.append(item)
             }
             fontTitleSelect.updateMenuItemsArr(menuItemArr)
@@ -176,14 +191,31 @@ class KMEditPDFTextPropertyViewController: NSViewController {
         alignmentBGView.addSubview(alignmentController!.view)
     }
     
+    //文字块变化时调用
+    func currentAreaChanged() {
+        fontTitleSelect.selectItemAtIndex(0)
+        
+        fontTitleButton.properties.isDisabled = true
+        fontTitleButton.reloadData()
+        
+        selCustomFontType = .customize
+    }
+    
     func reloadData() {
         
         let areas = pdfView?.km_editingTextAreas() ?? []
         if areas.count == 0 {
-            currentArea = nil
+            if let _ = currentArea {
+                currentArea = nil
+                
+                currentAreaChanged()
+            }
         } else if areas.count == 1 {
-            currentArea = areas.first
-            
+            if let area = areas.first, currentArea != area {
+                currentArea = area
+                
+                currentAreaChanged()
+            }
             alignmentBGView.isHidden = true
         } else if areas.count > 1 {
             alignmentBGView.isHidden = false
@@ -192,7 +224,11 @@ class KMEditPDFTextPropertyViewController: NSViewController {
             } else {
                 alignmentController?.updateMulti(true)
             }
-            currentArea = areas.first
+            if let area = areas.first, currentArea != area {
+                currentArea = area
+                
+                currentAreaChanged()
+            }
         }
         
         var fontName: String?
@@ -342,7 +378,93 @@ class KMEditPDFTextPropertyViewController: NSViewController {
         colorSlider.reloadData()
         colorOpacitySelect.reloadData()
         
+        self.checkFontTitleInfo()
+    }
+    
+    func checkFontTitleInfo() {
+        if self.fontTitleSelect.indexOfSelect() == 0 {
+            return
+        }
+        var type: KMEditPDFTextFontType = .customize
+        if self.fontTitleSelect.indexOfSelect() == 1 {
+            type = .h1
+        } else if self.fontTitleSelect.indexOfSelect() == 2 {
+            type = .h2
+        } else if self.fontTitleSelect.indexOfSelect() == 3 {
+            type = .h3
+        } else if self.fontTitleSelect.indexOfSelect() == 4 {
+            type = .b1
+        } else if self.fontTitleSelect.indexOfSelect() == 5 {
+            type = .b2
+        } else if self.fontTitleSelect.indexOfSelect() == 6 {
+            type = .b3
+        }
+        if type == .customize {
+            return
+        }
+        
+        let fontName = fontNameSelect.properties.text ?? ""
+        let fontStyle = fontStyleSelect.properties.text ?? ""
+        var fontSize = 12.0
+        let bold = fontStyle_boldItem.state == .pressed
+        let italic = fontStyle_ItalityItem.state == .pressed
+        var alignment: NSTextAlignment = .left
+        if fontAlign_centerItem.state == .pressed {
+            alignment = .center
+        } else if fontAlign_rightItem.state == .pressed {
+            alignment = .right
+        } else if fontAlign_justifyItem.state == .pressed {
+            alignment = .justified
+        }
+        
+        if let text = fontSizeSelect.properties.text, let textUnit = fontSizeSelect.properties.textUnit {
+            let result = text.stringByDeleteCharString(textUnit)
+            fontSize = result.stringToCGFloat()
+        }
         
+        let isChanged = KMEditPDFTextManager.manager.isModelChanged(type: type,
+                                                                    fontName: fontName, 
+                                                                    fontStyle: fontStyle,
+                                                                    fontSize: fontSize,
+                                                                    bold: bold,
+                                                                    italic: italic,
+                                                                    alignment: alignment)
+        
+        var fontTitleText = fontTitleSelect.properties.text ?? ""
+        if isChanged {
+            if fontTitleText.hasPrefix("* ") == false {
+                fontTitleText = "* " + fontTitleText
+            }
+        } else {
+            if fontTitleText.hasPrefix("* ") == true {
+                fontTitleText = fontTitleText.substring(form: 2)
+            }
+        }
+        fontTitleSelect.properties.text = fontTitleText
+        fontTitleSelect.reloadData()
+    }
+    
+    func updateAreaInfoWithCustomType(type: KMEditPDFTextFontType) {
+        var selModel: KMEditPDFTextFontModel?
+        if type != .customize {
+            selModel = KMEditPDFTextManager.manager.fetchUserDefaultData(type: type)
+        }
+        
+        if let model = selModel {
+            let fontName = model.fontName
+            let fontStyle = model.fontStyle
+            let fontSize = model.fontSize
+            let bold = model.bold
+            let italic = model.italic
+            let alignment = model.alignment
+            let font = CPDFFont(familyName: fontName, fontStyle: fontStyle)
+            
+            pdfView?.setEditingTextarea_font(font: font)
+            pdfView?.setEditingTextarea_FontSize(size: fontSize)
+            pdfView?.setEditingTextarea(isBold: bold)
+            pdfView?.setEditingTextarea(isItalic: italic)
+            pdfView?.setEditingTextarea_Alignment(align: alignment)
+        }
     }
     
     //MARK: - Action
@@ -365,15 +487,13 @@ class KMEditPDFTextPropertyViewController: NSViewController {
                 fontTitleGroup = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
             }
             fontTitleGroup?.groupDelegate = self
-            fontTitleGroup?.frame = CGRectMake(310, 0, 200, viewHeight)
+            fontTitleGroup?.frame = CGRectMake(310, 0, 140, viewHeight)
             fontTitleGroup?.updateGroupInfo(menuItemArr)
             
             var point = fontTitleButton.superview?.convert(fontTitleButton.frame.origin, to: nil) ?? CGPointZero
             point.y -= viewHeight
             fontTitleGroup?.showWithPoint(point, relativeTo: fontTitleButton)
         }
-        
-        reloadData()
     }
     
     override func mouseDown(with event: NSEvent) {
@@ -392,18 +512,44 @@ extension KMEditPDFTextPropertyViewController: ComponentSelectDelegate {
                 result = result.stringByDeleteCharString(textUnit)
             }
             if view == fontTitleSelect {
+                if menuItemProperty?.identifier == Customize_USERDEFAULTS {
+                    fontTitleButton.properties.isDisabled = true
+                    
+                    selCustomFontType = .customize
+                } else {
+                    fontTitleButton.properties.isDisabled = false
+                    
+                    var type: KMEditPDFTextFontType = .customize
+                    if menuItemProperty?.identifier == H1_USERDEFAULTS {
+                        type = .h1
+                    } else if menuItemProperty?.identifier == H2_USERDEFAULTS {
+                        type = .h2
+                    } else if menuItemProperty?.identifier == H3_USERDEFAULTS {
+                        type = .h3
+                    } else if menuItemProperty?.identifier == B1_USERDEFAULTS {
+                        type = .b1
+                    } else if menuItemProperty?.identifier == B2_USERDEFAULTS {
+                        type = .b2
+                    } else if menuItemProperty?.identifier == B3_USERDEFAULTS {
+                        type = .b3
+                    }
+                    selCustomFontType = type
+                    self.updateAreaInfoWithCustomType(type: type)
+                }
+                fontTitleButton.reloadData()
                 
             } else if view == fontNameSelect {
-                if let fontName = menuItemProperty?.text {
-                    var cFont = CPDFFont.init(familyName: fontName, fontStyle: "Regular")
-                    pdfView?.setEditingTextarea_font(font: cFont)
-                    
+                var styleName = "Regular"
+                let styleNames = CPDFFont.fontNames(forFamilyName: result)
+                if let first = styleNames.first {
+                    styleName = first
                 }
+                pdfView?.setEditingTextarea_font(font: CPDFFont(familyName: result, fontStyle: styleName))
+                
             } else if view == fontStyleSelect {
-                if let fontName = fontNameSelect.properties.text, let style = menuItemProperty?.text {
-                    var cFont = CPDFFont.init(familyName: fontName, fontStyle: style)
-                    pdfView?.setEditingTextarea_font(font: cFont)
-                }
+                let fontName = fontNameSelect.properties.text ?? "Helvetica"
+                pdfView?.setEditingTextarea_font(font: CPDFFont.init(familyName: fontName, fontStyle: result))
+                
             } else if view == fontSizeSelect {
                 if let text = menuItemProperty?.text {
                     let fontSize = result.stringToCGFloat()
@@ -503,9 +649,41 @@ extension KMEditPDFTextPropertyViewController: KMNAlignmentControllerDelegate {
 extension KMEditPDFTextPropertyViewController: ComponentGroupDelegate {
     func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
         if menuItemProperty?.identifier == "Redefine" {
-            
+            self.redefineCustomFontType()
         } else if menuItemProperty?.identifier == "Reset" {
-            
+            if selCustomFontType != .customize {
+                KMEditPDFTextManager.manager.resetTextPresupposition(type: selCustomFontType)
+                
+                self.updateAreaInfoWithCustomType(type: selCustomFontType)
+            }
         }
+        reloadData()
+    }
+    
+    func redefineCustomFontType() {
+        if selCustomFontType == .customize {
+            return
+        }
+        let fontName = fontNameSelect.properties.text ?? ""
+        let fontStyle = fontStyleSelect.properties.text ?? ""
+        var fontSize = 12.0
+        let bold = fontStyle_boldItem.state == .pressed
+        let italic = fontStyle_ItalityItem.state == .pressed
+        var alignment: NSTextAlignment = .left
+        
+        if fontAlign_centerItem.state == .pressed {
+            alignment = .center
+        } else if fontAlign_rightItem.state == .pressed {
+            alignment = .right
+        } else if fontAlign_justifyItem.state == .pressed {
+            alignment = .justified
+        }
+        
+        if let text = fontSizeSelect.properties.text, let textUnit = fontSizeSelect.properties.textUnit {
+            let result = text.stringByDeleteCharString(textUnit)
+            fontSize = result.stringToCGFloat()
+        }
+        
+        KMEditPDFTextManager.manager.reDefineTextPresupposition(type: selCustomFontType, fontName: fontName, fontStyle: fontStyle, fontSize: fontSize, bold: bold, italic: italic, alignment: alignment)
     }
 }

+ 106 - 298
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/EditPDF/Manager/KMEditPDFTextManager.swift

@@ -22,18 +22,12 @@ let FontColor_USERDEFAULTS = "CEditPDFTextDefaultFontColor"
 let FONTNAME_DEFAULT = "Helvetica"
 let FONTStyle_DEFAULT = "Regular"
 let FONTSIZE_DEFAULT = 12.0
-let CHANGE_DEFAULT = false
-let REDEFINE_DEFAULT = false
 let ALIGNMENT_DEFAULT = NSTextAlignment.left
-let COLOR_DEFAULT = "#000000"
 
 //属性类型
 let FONTNAME_KEY = "fontName"
 let FONTStyle_KEY = "fontStyle"
 let FONTSIZE_KEY = "fontSize"
-let CHANGE_KEY = "change"
-let REDEFINE_KEY = "redefine"
-let COLOR_KEY = "fontColor"
 let ALIGNMENT_KEY = "FontAlignment"
 let Bold_KEY = "bold"
 let Italic_KEY = "italic"
@@ -79,14 +73,15 @@ enum KMEditPDFTextFontType: String, CaseIterable {
 
 //默认字体样式
 let defaultTextPresupposition: NSDictionary = [
-    KMEditPDFTextFontType.commonly.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "12.0", REDEFINE_KEY: false, CHANGE_KEY: false, COLOR_KEY: COLOR_DEFAULT, ALIGNMENT_KEY: ALIGNMENT_DEFAULT, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.customize.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "12.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.h1.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold",FONTSIZE_KEY: "36.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.h2.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold", FONTSIZE_KEY: "24.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.h3.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold",FONTSIZE_KEY: "18.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.b1.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "14.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.b2.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "12.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any],
-    KMEditPDFTextFontType.b3.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "11.0", REDEFINE_KEY: false, CHANGE_KEY: false, Bold_KEY : false, Italic_KEY : false] as [String : Any]]
+    KMEditPDFTextFontType.commonly.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "12.0", ALIGNMENT_KEY: ALIGNMENT_DEFAULT, Bold_KEY : false, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.customize.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular",FONTSIZE_KEY: "12.0", Bold_KEY : false, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.h1.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold", FONTSIZE_KEY: "28.0", Bold_KEY : true, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.h2.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold", FONTSIZE_KEY: "20.0", Bold_KEY : true, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.h3.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Bold", FONTSIZE_KEY: "16.0", Bold_KEY : true, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.b1.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular", FONTSIZE_KEY: "14.0", Bold_KEY : false, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.b2.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular", FONTSIZE_KEY: "12.0", Bold_KEY : false, Italic_KEY : false] as [String : Any],
+    KMEditPDFTextFontType.b3.rawValue: [FONTNAME_KEY: "Helvetica", FONTStyle_KEY : "Regular", FONTSIZE_KEY: "8.0", Bold_KEY : false, Italic_KEY : false] as [String : Any]
+]
 
 //MARK: - KMEditPDFTextFontTypeWrapper
 class KMEditPDFTextFontTypeWrapper: NSObject {
@@ -101,8 +96,6 @@ class KMEditPDFTextFontModel: NSObject {
     var fontName: String = FONTNAME_DEFAULT
     var fontStyle: String = FONTStyle_DEFAULT
     var fontSize: CGFloat = FONTSIZE_DEFAULT
-    var change: Bool = CHANGE_DEFAULT
-    var redefine: Bool = REDEFINE_DEFAULT
     var type: KMEditPDFTextFontType = .customize
     var color: NSColor = NSColor.black
     var alignment: NSTextAlignment = ALIGNMENT_DEFAULT
@@ -118,75 +111,119 @@ class KMEditPDFTextFontModel: NSObject {
     
     var textFontNames: [String] = []
     var textPresuppositionArray: [KMEditPDFTextFontModel] = []
-    var textPresuppositionFontNameArray: [String] = []
-}
-
-
-//MARK: - public
-@objc extension KMEditPDFTextManager {
-    @objc func resetTextPresupposition(type: String) {
-        let dic: NSDictionary = defaultTextPresupposition[type] as! NSDictionary
-        self.setTextPresupposition(fontName: dic[FONTNAME_KEY] as! String, 
-                                   fontStyle: dic[FONTStyle_KEY] as? String ?? FONTStyle_DEFAULT,
-                                   fontSize: CGFloat(Float(dic[FONTSIZE_KEY] as? String ?? "12") ?? Float(FONTSIZE_DEFAULT)),
-                                   redefine: false,
-                                   change: false,
-                                   type: KMEditPDFTextFontType(rawValue: type) ?? .customize,
-                                   bold: dic[Bold_KEY] as? Bool ?? false, italic: dic[Italic_KEY] as? Bool ?? false)
-    }
     
-    @objc func changeTextPresupposition(fontName: String, fontStyle: String, fontSize: CGFloat, type: String) {
-        self.setTextPresupposition(fontName: fontName, 
-                                   fontStyle: fontStyle,
-                                   fontSize: fontSize,
-                                   change: true,
-                                   type: KMEditPDFTextFontType(rawValue: type) ?? .customize, bold: nil, italic: nil)
+    
+    override init() {
+        super.init()
+        
+        let _ = self.fetchAllUserDefaultData()
     }
     
-    @objc func reDefineTextPresupposition(fontName: String, fontStyle: String, fontSize: CGFloat, type: String) {
-        self.setTextPresupposition(fontName: fontName, 
-                                   fontStyle: fontStyle,
-                                   fontSize: fontSize,
-                                   redefine: true,
-                                   change: false,
-                                   type: KMEditPDFTextFontType(rawValue: type) ?? .customize,
-                                   bold: nil, italic: nil)
+    //设置相应的字体样式
+    private func setTextPresupposition(type: KMEditPDFTextFontType,
+                                       fontName: String,
+                                       fontStyle: String,
+                                       fontSize: CGFloat,
+                                       bold: Bool,
+                                       italic: Bool,
+                                       alignment: NSTextAlignment) {
+
+        let fontDic: NSDictionary = [FONTNAME_KEY: fontName,
+                                   FONTStyle_KEY : fontStyle,
+                                     FONTSIZE_KEY: String(format: "%.0f", fontSize),
+                                    ALIGNMENT_KEY: alignment.rawValue,
+                                        Bold_KEY : bold,
+                                      Italic_KEY : italic]
+        
+        let userDefaults = UserDefaults.standard
+        switch type {
+        case .commonly:
+            userDefaults.set(fontDic, forKey: Commonly_USERDEFAULTS)
+        case .customize:
+            userDefaults.set(fontDic, forKey: Customize_USERDEFAULTS)
+        case .h1:
+            userDefaults.set(fontDic, forKey: H1_USERDEFAULTS)
+        case .h2:
+            userDefaults.set(fontDic, forKey: H2_USERDEFAULTS)
+        case .h3:
+            userDefaults.set(fontDic, forKey: H3_USERDEFAULTS)
+        case .b1:
+            userDefaults.set(fontDic, forKey: B1_USERDEFAULTS)
+        case .b2:
+            userDefaults.set(fontDic, forKey: B2_USERDEFAULTS)
+        case .b3:
+            userDefaults.set(fontDic, forKey: B3_USERDEFAULTS)
+        }
+        userDefaults.synchronize()
     }
 }
 
+//MARK: - Compare
 extension KMEditPDFTextManager {
-    //改变单个字体样式
-    func changeTextPresupposition(fontName: String, fontStyle: String,fontSize: CGFloat, type: KMEditPDFTextFontType, bold: Bool?, italic: Bool?) {
-        self.setTextPresupposition(fontName: fontName, 
-                                   fontStyle: fontStyle,
-                                   fontSize: fontSize,
-                                   change: true,
-                                   type: type, bold: bold, italic: italic)
+    func isModelChanged(type: KMEditPDFTextFontType,
+                        fontName: String,
+                        fontStyle: String,
+                        fontSize: CGFloat,
+                        bold: Bool,
+                        italic: Bool,
+                        alignment: NSTextAlignment) -> Bool {
+        
+        let model = self.fetchUserDefaultData(type: type)
+        
+        if model.fontName != fontName {
+            return true
+        } else if model.fontStyle != fontStyle {
+            return true
+        } else if model.fontSize != fontSize {
+            return true
+        } else if model.bold != bold {
+            return true
+        } else if model.italic != italic {
+            return true
+        } else if model.alignment != alignment {
+            return true
+        } 
+        return false
     }
-    
+}
+
+//MARK: - 重定义 & 重置
+extension KMEditPDFTextManager {
     //重定义单个字体样式
-    func reDefineTextPresupposition(fontName: String, fontStyle: String, fontSize: CGFloat, type: KMEditPDFTextFontType) {
-        self.setTextPresupposition(fontName: fontName, 
+    func reDefineTextPresupposition(type: KMEditPDFTextFontType,
+                                    fontName: String,
+                                    fontStyle: String,
+                                    fontSize: CGFloat,
+                                    bold: Bool,
+                                    italic: Bool,
+                                    alignment: NSTextAlignment) {
+        
+        self.setTextPresupposition(type: type,
+                                   fontName: fontName,
                                    fontStyle: fontStyle,
                                    fontSize: fontSize,
-                                   redefine: true,
-                                   change: false,
-                                   type: type,
-                                   bold: nil, italic: nil)
+                                   bold: bold, italic:
+                                    italic,
+                                   alignment: alignment)
     }
     
     //重置单个字体样式
     func resetTextPresupposition(type: KMEditPDFTextFontType) {
         let dic: NSDictionary = defaultTextPresupposition[type.rawValue] as! NSDictionary
-        self.setTextPresupposition(fontName: dic[FONTNAME_KEY] as! String, 
+        self.setTextPresupposition(type: type,
+                                   fontName: dic[FONTNAME_KEY] as! String,
                                    fontStyle: dic[FONTStyle_KEY] as? String ?? FONTStyle_DEFAULT,
                                    fontSize: CGFloat(Float(dic[FONTSIZE_KEY] as? String ?? "12") ?? Float(FONTSIZE_DEFAULT)),
-                                   redefine: false,
-                                   change: false,
-                                   type: type,
-                                   bold: dic[Bold_KEY] as? Bool ?? false, italic: dic[Italic_KEY] as? Bool ?? false)
+                                   bold: dic[Bold_KEY] as? Bool ?? false,
+                                   italic: dic[Italic_KEY] as? Bool ?? false,
+                                   alignment: NSTextAlignment(rawValue: dic[ALIGNMENT_KEY] as? Int ?? 0) ?? NSTextAlignment.left)
     }
     
+}
+
+//MARK: - Fetch
+extension KMEditPDFTextManager {
+    
     //获取保存的自定义字体样式
     func fetchAllUserDefaultData() -> [KMEditPDFTextFontModel] {
         var resultArray: [KMEditPDFTextFontModel] = []
@@ -203,224 +240,6 @@ extension KMEditPDFTextManager {
         return resultArray
     }
     
-    //更新自定义字体文字信息
-    func updateTextPresuppositionFontNameArray() -> [String] {
-        let textPresuppositionArray = self.fetchAllUserDefaultData()
-        let textNameArray: [String] = KMEditPDFTextFontType.allValues()
-        
-        var resultArray: [String] = []
-        for index in 0...textNameArray.count - 1 {
-            let model = textPresuppositionArray[index]
-            var string = textNameArray[index]
-            let change: Bool = model.change
-            if change && model.type != .customize {
-                string = "*" + string
-            } else {
-                string = string.replacingOccurrences(of: "*", with: "")
-            }
-            resultArray.append(string)
-        }
-        
-        //获取显示文案
-        self.textPresuppositionFontNameArray = resultArray
-        return resultArray
-    }
-     
-    func fetchTextImage(textString: String = "Sample", alignment: NSTextAlignment, fontName: String, fontSize: CGFloat, color: NSColor, imageSize: CGSize) -> NSImage {
-        let string = NSLocalizedString(textString, comment: "")
-        let paragraphStyle = NSMutableParagraphStyle()
-        paragraphStyle.alignment = .center //alignment
-        let tempFontName = self.fetchFontName(fontName: fontName)
-        let style = self.fetchFontStyle(fontName: fontName)
-
-        let fontCurrentColor: NSColor = color
-        var attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family: tempFontName])
-        if style.count > 0 {
-            attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family: tempFontName, NSFontDescriptor.AttributeName.face : style])
-        }
-        var font = NSFont.init(descriptor: attributeFontDescriptor, size: CGFloat(fontSize))
-        if font == nil {
-            attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family: FONTNAME_DEFAULT])
-            font = NSFont.init(descriptor: attributeFontDescriptor, size: fontSize)
-        }
-        KMPrint("----------------" + tempFontName + "----------------" + style + "----------------")
-        if font == nil {
-            return NSImage()
-        }
-        
-        var red : CGFloat = 0.0
-        var green : CGFloat = 0.0
-        var blue : CGFloat = 0.0
-        var alpha : CGFloat = 0.0
-        var color : NSColor = NSColor.white
-        
-        fontCurrentColor.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
-        color = NSColor(red: red, green: green, blue: blue, alpha: alpha)
-        
-        let attributes = [NSAttributedString.Key.font: font,
-                          NSAttributedString.Key.foregroundColor: color,
-                          NSAttributedString.Key.paragraphStyle: paragraphStyle]
-        
-        let size = string.size(withAttributes:attributes as [NSAttributedString.Key : Any])
-        let image = NSImage(size: NSSize(width: imageSize.width, height: size.height))
-        if image.size.width != 0 && image.size.height != 0 {
-            image.lockFocus()
-            NSGraphicsContext.current?.imageInterpolation = .high
-            NSString(string: string).draw(in: NSRect(x: 0, y: 0, width: imageSize.width, height: image.size.height), withAttributes: attributes as [NSAttributedString.Key : Any])
-            NSGraphicsContext.current?.imageInterpolation = .default
-            image.unlockFocus()
-        }
-        return image
-    }
-    
-    func setCommonlyFontColor(color: NSColor) {
- 
-        let userDefaults = UserDefaults.standard
-        let model = self.fetchUserDefaultData(type: .commonly)
-        let colorString: String = color.toHex(alpha: true) ?? ""
-        let fontDic: NSDictionary = [FONTNAME_KEY: model.fontName, FONTSIZE_KEY: model.fontSize.description, REDEFINE_KEY: model.redefine, CHANGE_KEY: model.change, COLOR_KEY: colorString, ALIGNMENT_KEY: model.alignment.rawValue]
-        userDefaults.set(fontDic, forKey: Commonly_USERDEFAULTS)
-        userDefaults.synchronize()
-    }
-    
-    func setFontAlignment(alignment: NSTextAlignment) {
-        let userDefaults = UserDefaults.standard
-        let model = self.fetchUserDefaultData(type: .commonly)
-        let colorString: String = model.color.toHex(alpha: true) ?? ""
-        let fontDic: NSDictionary = [FONTNAME_KEY: model.fontName, FONTSIZE_KEY: model.fontSize.description, REDEFINE_KEY: model.redefine, CHANGE_KEY: model.change, COLOR_KEY: colorString, ALIGNMENT_KEY: alignment.rawValue]
-        userDefaults.set(fontDic, forKey: Commonly_USERDEFAULTS)
-        userDefaults.synchronize()
-    }
-}
-
-//MARK: - Tool
-extension KMEditPDFTextManager {
-    func checkFontStyle(style: String) -> String {
-        var result = style
-        if style == "Regular" || style == "Roman" {
-            result = ""
-        }
-        
-        if style.contains("BoldOblique") || style.contains("BoldItalic") {
- 
-        }
-        return result
-    }
-    
-    func checkFontName(fontName: String) -> String {
-        let fontNameArray = self.separatedFontName(string: fontName)
-        
-        var name = ""
-        var style = ""
-        if fontNameArray.count > 0 {
-            name = fontNameArray.first!
-        } else {
-            name = "Helvetica"
-        }
-        if fontNameArray.count == 2 {
-            style = fontNameArray.last!
-            style = self.checkFontStyle(style: style)
-            if style.count != 0 {
-                name = name + "-" + style
-            }
-        }
-        return name
-    }
-    
-    func fetchFontName(fontName: String) -> String {
-        let fontNameArray = self.separatedFontName(string: fontName)
-        
-        var name = ""
-        if fontNameArray.count > 0 {
-            name = fontNameArray.first!
-        } else {
-            name = "Helvetica"
-        }
-        return name
-    }
-    
-    func fetchFontStyle(fontName: String) -> String {
-        let fontNameArray = self.separatedFontName(string: fontName)
-        var style = ""
-        if fontNameArray.count == 2 {
-            style = fontNameArray.last!
-            style = self.checkFontStyle(style: style)
-        }
-        return style
-    }
-    
-    func separatedFontName(string: String) -> [String] {
-        var fontNameArray = string.components(separatedBy: "-")
-        if fontNameArray.count <= 1 {
-            fontNameArray = string.components(separatedBy: " ")
-        }
-        return fontNameArray
-    }
-    
-    func fetchFont(fontName: String, style: String, size: CGFloat) -> NSFont {
-        var fontStyle = style
-        
-        var attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family: fontName])
-        if fontStyle.count > 0 {
-            if fontStyle == "Regular" || fontStyle == "Roman" {
-                attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : fontName])
-            } else {
-                attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : fontName,NSFontDescriptor.AttributeName.face : fontStyle])
-            }
-        }
-        var font = NSFont.init(descriptor: attributeFontDescriptor, size: size)
-        if font == nil {
-            attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family: FONTNAME_DEFAULT])
-            font = NSFont.init(descriptor: attributeFontDescriptor, size: size)
-        }
-        
-        return font!
-    }
-}
-
-//MARK: - private
-extension KMEditPDFTextManager {
-    //设置相应的字体样式
-    private func setTextPresupposition(fontName: String, fontStyle: String, fontSize: CGFloat, redefine: Bool = false, change: Bool = false, type: KMEditPDFTextFontType, bold: Bool?, italic: Bool?) {
-         let model = self.fetchUserDefaultData(type: type)
-        let colorString: String = model.color.toHex(alpha: true) ?? ""
-        var boldV = model.bold
-        if let data = bold {
-            boldV = data
-        }
-        var italicV = model.italic
-        if let data = italic {
-            italicV = data
-        }
-        let fontDic: NSDictionary = [FONTNAME_KEY: fontName, FONTStyle_KEY : fontStyle, FONTSIZE_KEY: fontSize.description, REDEFINE_KEY: redefine, CHANGE_KEY: change, COLOR_KEY: colorString, ALIGNMENT_KEY: model.alignment.rawValue, Bold_KEY : boldV, Italic_KEY : italicV]
-        
-        let userDefaults = UserDefaults.standard
-        switch type {
-        case .commonly:
-            userDefaults.set(fontDic, forKey: Commonly_USERDEFAULTS)
-        case .customize:
-            userDefaults.set(fontDic, forKey: Customize_USERDEFAULTS)
-        case .h1:
-            userDefaults.set(fontDic, forKey: H1_USERDEFAULTS)
-        case .h2:
-            userDefaults.set(fontDic, forKey: H2_USERDEFAULTS)
-        case .h3:
-            userDefaults.set(fontDic, forKey: H3_USERDEFAULTS)
-        case .b1:
-            userDefaults.set(fontDic, forKey: B1_USERDEFAULTS)
-        case .b2:
-            userDefaults.set(fontDic, forKey: B2_USERDEFAULTS)
-        case .b3:
-            userDefaults.set(fontDic, forKey: B3_USERDEFAULTS)
-        default:
-            userDefaults.set(fontDic, forKey: Customize_USERDEFAULTS)
-            break
-        }
-        userDefaults.synchronize()
-        
-        _ = self.updateTextPresuppositionFontNameArray()
-    }
-    
     //获取保存的单个类型字体样式
     @objc func fetchUserDefaultDataWithTypeString(type: NSString) -> KMEditPDFTextFontModel {
         return self.fetchUserDefaultData(type: KMEditPDFTextFontType(rawValue: type as String)!)
@@ -446,38 +265,27 @@ extension KMEditPDFTextManager {
             data = (userDefaults.object(forKey: B2_USERDEFAULTS) ?? [String: Any]()) as! NSDictionary
         case .b3:
             data = (userDefaults.object(forKey: B3_USERDEFAULTS) ?? [String: Any]()) as! NSDictionary
-        default:
-            data = defaultTextPresupposition[KMEditPDFTextFontType.customize.rawValue] as! NSDictionary
-            break
         }
         if data.count == 0 {
             data = defaultTextPresupposition[type.rawValue] as! NSDictionary
         }
         
         let fontName = data[FONTNAME_KEY] as? String ?? FONTNAME_DEFAULT
+        let fontStyle = data[FONTStyle_KEY] as? String ?? FONTStyle_DEFAULT
         let fontSize: CGFloat = CGFloat(Float(data[FONTSIZE_KEY] as? String ?? "12") ?? Float(FONTSIZE_DEFAULT))
-        let redefine = data[REDEFINE_KEY] as? Bool ?? REDEFINE_DEFAULT
-        let change = data[CHANGE_KEY] as? Bool ?? CHANGE_DEFAULT
-        let colorString = data[COLOR_KEY] as? String ?? COLOR_DEFAULT
         let alignment = NSTextAlignment(rawValue: data[ALIGNMENT_KEY] as? Int ?? 0) ?? NSTextAlignment.left
- 
-        let fontStyle = data[FONTStyle_KEY] as? String ?? FONTStyle_DEFAULT
         let bold = data[Bold_KEY] as? Bool ?? false
         let italic = data[Italic_KEY] as? Bool ?? false
         
         let resultModel: KMEditPDFTextFontModel = KMEditPDFTextFontModel()
+        resultModel.type = type
         resultModel.fontName = fontName
+        resultModel.fontStyle = fontStyle
         resultModel.fontSize = fontSize
-        resultModel.redefine = redefine
-        resultModel.change = change
-        resultModel.type = type
-        resultModel.color = NSColor.km_init(hex: colorString)
         resultModel.alignment = alignment
-        
-        resultModel.fontStyle = fontStyle
         resultModel.bold = bold
         resultModel.italic = italic
- 
+        
         return resultModel
     }
 }