Browse Source

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

tangchao 11 months ago
parent
commit
e91dff5930

+ 11 - 2
PDF Office/PDF Master/Class/Batch/View/KMConvertCollectionViewHeader.swift

@@ -46,6 +46,7 @@ class KMConvertCollectionViewHeader: KMBaseXibView{
         self.layerColorView.layer?.cornerRadius = 12
         self.layerColorView.layer?.backgroundColor = NSColor(red: 1.0, green: 94/255.0, blue: 44/255.0, alpha: 1.0).cgColor
         
+        self.refreshData()
         
         NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil)
@@ -72,12 +73,20 @@ class KMConvertCollectionViewHeader: KMBaseXibView{
         }
     }
     
+    func refreshData() {
+        if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
+            containerView.isHidden = true
+        } else {
+            containerView.isHidden = false
+        }
+    }
+    
     @objc func IAPProductPurchasedNotification(notification: Notification) {
-        containerView.isHidden = true
+        self.refreshData()
     }
     
     @objc func IAPProductRestoreFinishedNotification(notification: Notification) {
-        containerView.isHidden = true
+        self.refreshData()
     }
     
 }

+ 10 - 5
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -1431,7 +1431,6 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
                     let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
                     var savePath = self.filePathCheck(path: savePathOld)
-                    NSLog("==savePath: %@", savePath)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
                     let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
@@ -1499,12 +1498,15 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
                     let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
                     if writeSuccess == true {
-                        self.savePdf(savePath)
+                        if self.checkOpenNewDocument(path: savePath) {
+                            self.savePdf(savePath)
+                        }
 //                        try? FileManager.default.removeItem(atPath: savePath)
                     } else {
                         
@@ -1518,12 +1520,15 @@ extension KMBrowserWindowController: KMSystemFileMenuProtocol {
         KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
             if let image = ima {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
-                    let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    let savePathOld = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
+                    var savePath = self.filePathCheck(path: savePathOld)
                     let newDocument = CPDFDocument()
                     _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
                     let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
                     if writeSuccess == true {
-                        self.savePdf(savePath)
+                        if self.checkOpenNewDocument(path: savePath) {
+                            self.savePdf(savePath)
+                        }
 //                        try? FileManager.default.removeItem(atPath: savePath)
                     } else {
                         

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

@@ -204,6 +204,7 @@ let KMColorPickerViewHeight: CGFloat = 64
     var lineStyleCount: Int = 0
     var isTextEdit: Bool = false
     var fonts: [[String : [String]]]!
+    var annotationAlignment: KMFreeTextAnnotationAlignmentType = .left
     
     var noteIcons: [NSImage?] = [nil, nil, nil, nil, nil, nil, nil]
     
@@ -1345,6 +1346,7 @@ let KMColorPickerViewHeight: CGFloat = 64
     }
     
     func alignmentTypeSelected(_ type: KMFreeTextAnnotationAlignmentType) {
+        annotationAlignment = type
         selectedAlignmentButtonLayer?.removeFromSuperlayer()
         selectedAlignmentButtonLayer = CALayer()
 
@@ -1852,56 +1854,77 @@ let KMColorPickerViewHeight: CGFloat = 64
     // MARK: Font、FontSize Action
     
     @IBAction func fontButtonAction(_ sender: NSButton) {
-        let fontWindowController = KMAnnotationFontWindowController.sharedAnnotationFont
-        let window = fontWindowController.window
-        fontWindowController.annotations = annotations
-        fontWindowController.annotationAlignCallback = { [weak self] selectedCount in
-            var alignmentType: KMFreeTextAnnotationAlignmentType = .left
-            if selectedCount == NSTextAlignment.left.rawValue {
-                alignmentType = .left
-            } else if selectedCount == NSTextAlignment.center.rawValue {
-                alignmentType = .center
-            } else if selectedCount == NSTextAlignment.right.rawValue {
-                alignmentType = .right
-            }
-            self!.alignmentTypeSelected(alignmentType)
-        }
+        let selectItem = self.fontPopUpButton.selectedItem
+        let resultAtt = NSMutableAttributedString(attributedString: selectItem!.attributedTitle!)
+        let familyString = resultAtt.string
+        let styleString = self.fontStylePopUpButton.selectedItem?.title
+        let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
+        let fontSizeString = fontSizeComboBox.stringValue.replacingOccurrences(of: " pt", with: "")
+        let newFont = NSFont(descriptor: attributeFontDescriptor, size: fontSizeString.stringToCGFloat())
+        let fontModel = KMFontModel(fontName: familyString, fontWeight: styleString!, fontSize: fontSizeString.stringToCGFloat(), fontColor: textColorPickerView.color ?? .black, fontAlignment: annotationAlignment, annotationType: annotationModel!.annotationType)
         
-        fontWindowController.annotationCallback = { [weak self] annotation in
-            if annotation is CPDFFreeTextAnnotation {
-                if let family = (annotation as! CPDFFreeTextAnnotation).font?.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
-                   let style = (annotation as! CPDFFreeTextAnnotation).font?.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
-                    
-                    DispatchQueue.main.async {
-                        let selectedStyleIndex = self!.setFontStyle(fontName: family, currentStyle: style)
-                        self!.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
-                    }
-                    
-                    DispatchQueue.global(qos: .default).async {
-                        let fonts = NSFontManager.shared.availableFontFamilies
-                        let menu = NSMenu()
-                        var selectedIndex = 0
-                        
-                        for (index, fontName) in fonts.enumerated() {
-                            if let font = NSFont(name: fontName, size: 12.0) {
-                                let attributedString = NSAttributedString(string: fontName, attributes: [.font: font])
-                                let item = NSMenuItem()
-                                item.attributedTitle = attributedString
-                                menu.addItem(item)
-                                if (annotation as! CPDFFreeTextAnnotation).font?.fontName == font.fontName {
-                                    selectedIndex = index
-                                }
-                            }
+        let fontWindowController = KMAnnotationFontWindowController.initWindowController(fontModel)
+        let window = fontWindowController.window
+        fontWindowController.callback = { [weak self] model in
+            self!.alignmentTypeSelected(model.fontAlignment)
+            self!.textColorPickerView.color = model.fontColor
+            
+            DispatchQueue.global(qos: .default).async {
+                let fonts = NSFontManager.shared.availableFontFamilies
+                let menu = NSMenu()
+                var selectedIndex = 0
+                
+                for (index, fontName) in fonts.enumerated() {
+                    if let font = NSFont(name: fontName, size: 12.0) {
+                        let attributedString = NSAttributedString(string: fontName, attributes: [.font: font])
+                        let item = NSMenuItem()
+                        item.attributedTitle = attributedString
+                        menu.addItem(item)
+                        if model.fontName == font.fontName {
+                            selectedIndex = index
                         }
-                        DispatchQueue.main.async {
-                            self!.fontPopUpButton.menu = menu
-                            self!.fontPopUpButton.selectItem(at: selectedIndex)
+                    }
+                }
+                DispatchQueue.main.async {
+                    self!.fontPopUpButton.menu = menu
+                    self!.fontPopUpButton.selectItem(at: selectedIndex)
+                }
+            }
+            let selectedStyleIndex = self!.setFontStyle(fontName: model.fontName, currentStyle: model.fontWeight)
+            self!.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
+            self!.fontSizeComboBox.stringValue = String(format: "%.f pt", model.fontSize)
+            
+            if self!.annotationModel?.annotations != nil {
+                let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: model.fontName, .face: model.fontWeight])
+                let annotationFont = NSFont(descriptor: attributeFontDescriptor, size: model.fontSize)
+
+                for tAnnotation in self!.annotations {
+                    if tAnnotation is CPDFFreeTextAnnotation {
+                        (tAnnotation as! CPDFFreeTextAnnotation).font = annotationFont
+                        (tAnnotation as! CPDFFreeTextAnnotation).fontColor = model.fontColor
+                        if model.fontAlignment == .left {
+                            (tAnnotation as! CPDFFreeTextAnnotation).alignment = .left
+                        } else if model.fontAlignment == .center {
+                            (tAnnotation as! CPDFFreeTextAnnotation).alignment = .center
+                        } else if model.fontAlignment == .right {
+                            (tAnnotation as! CPDFFreeTextAnnotation).alignment = .right
                         }
                     }
                 }
+                self!.updateAnnotation()
+            } else {
+                self!.annotationModel?.setFontName(model.fontName)
+                self!.annotationModel?.setFontSize(model.fontSize)
+                self!.annotationModel?.setFontColor(model.fontColor)
+                if model.fontAlignment == .left {
+                    self!.annotationModel?.setAlignment(.left)
+                } else if model.fontAlignment == .center {
+                    self!.annotationModel?.setAlignment(.center)
+                } else if model.fontAlignment == .right {
+                    self!.annotationModel?.setAlignment(.right)
+                }
             }
         }
-        
         window?.orderFront(sender)
     }
     

+ 32 - 32
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.xib

@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="Named colors" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMGeneralAnnotationViewController" customModule="PDF_Master" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMGeneralAnnotationViewController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="ColorViewTopConstant" destination="Ges-DJ-Po0" id="cAd-da-wOF"/>
                 <outlet property="addParagraphBox" destination="3Jc-Uq-mgA" id="bVP-xZ-ios"/>
@@ -162,7 +162,7 @@
                                             <action selector="fontButtonAction:" target="-2" id="dkT-3i-wVF"/>
                                         </connections>
                                     </button>
-                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="cAF-1K-YAd" customClass="KMPopUpButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="cAF-1K-YAd" customClass="KMPopUpButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="33" width="346" height="24"/>
                                         <popUpButtonCell key="cell" type="square" title="UltraLight" bezelStyle="shadowlessSquare" alignment="left" lineBreakMode="truncatingTail" state="on" inset="2" arrowPosition="noArrow" selectedItem="9nh-AB-IE0" id="5Vn-Fa-ghP">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -244,9 +244,9 @@
                                             <action selector="alignButtonAction:" target="-2" id="KCd-nU-dPy"/>
                                         </connections>
                                     </button>
-                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="AHs-kd-sAo" customClass="KMPopUpButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="AHs-kd-sAo" customClass="KMPopUpButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="65" width="449" height="24"/>
-                                        <popUpButtonCell key="cell" type="square" bezelStyle="shadowlessSquare" alignment="left" lineBreakMode="truncatingTail" inset="2" arrowPosition="noArrow" id="Vv5-1P-Y1g" customClass="KMPopUpButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                        <popUpButtonCell key="cell" type="square" bezelStyle="shadowlessSquare" alignment="left" lineBreakMode="truncatingTail" inset="2" arrowPosition="noArrow" id="Vv5-1P-Y1g" customClass="KMPopUpButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                             <font key="font" usesAppearanceFont="YES"/>
                                             <menu key="menu" id="fW2-Mn-ucz"/>
@@ -258,12 +258,12 @@
                                             <action selector="fontPopUpButtonAction:" target="-2" id="umX-SG-GYl"/>
                                         </connections>
                                     </popUpButton>
-                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ddA-v5-KF1" customClass="KMComboBox" customModule="PDF_Master" customModuleProvider="target">
+                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ddA-v5-KF1" customClass="KMComboBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="353" y="33" width="96" height="23"/>
                                         <constraints>
                                             <constraint firstAttribute="width" constant="92" id="oJG-Z9-pzj"/>
                                         </constraints>
-                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" completes="NO" numberOfVisibleItems="5" id="cvA-Kj-Sre" customClass="KMComboBoxCell" customModule="PDF_Master" customModuleProvider="target">
+                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" completes="NO" numberOfVisibleItems="5" id="cvA-Kj-Sre" customClass="KMComboBoxCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <font key="font" metaFont="system"/>
                                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -295,7 +295,7 @@
                                             <action selector="fontSizeComboBoxAction:" target="-2" id="p9w-Ix-F14"/>
                                         </connections>
                                     </comboBox>
-                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="KNQ-i0-GhJ" customClass="KMColorPickerView" customModule="PDF_Master" customModuleProvider="target">
+                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="KNQ-i0-GhJ" customClass="KMColorPickerView" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="99" width="449" height="32"/>
                                         <constraints>
                                             <constraint firstAttribute="height" constant="32" id="qOk-1z-Kcm"/>
@@ -354,7 +354,7 @@
                                             <rect key="frame" x="0.0" y="0.0" width="449" height="57"/>
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                             <subviews>
-                                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="ZtW-i2-s3s" customClass="KMColorPickerView" customModule="PDF_Master" customModuleProvider="target">
+                                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="ZtW-i2-s3s" customClass="KMColorPickerView" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                     <rect key="frame" x="0.0" y="0.0" width="449" height="57"/>
                                                     <connections>
                                                         <action selector="fillColorPickerViewAction:" target="-2" id="FSm-vz-Ldw"/>
@@ -378,7 +378,7 @@
                                             <rect key="frame" x="0.0" y="0.0" width="449" height="32"/>
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                             <subviews>
-                                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="xJJ-JD-2AF" customClass="KMColorPickerView" customModule="PDF_Master" customModuleProvider="target">
+                                                <customView translatesAutoresizingMaskIntoConstraints="NO" id="xJJ-JD-2AF" customClass="KMColorPickerView" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                     <rect key="frame" x="0.0" y="0.0" width="449" height="32"/>
                                                     <constraints>
                                                         <constraint firstAttribute="height" constant="32" id="gQe-IQ-c56"/>
@@ -410,13 +410,13 @@
                                                         <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                                     </textFieldCell>
                                                 </textField>
-                                                <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Qzi-o3-DRu" customClass="KMComboBox" customModule="PDF_Master" customModuleProvider="target">
+                                                <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Qzi-o3-DRu" customClass="KMComboBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                     <rect key="frame" x="376" y="-2" width="76" height="27"/>
                                                     <constraints>
                                                         <constraint firstAttribute="width" constant="72" id="Agl-cI-DK9"/>
                                                         <constraint firstAttribute="height" constant="24" id="rOY-qg-B8b"/>
                                                     </constraints>
-                                                    <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" buttonBordered="NO" completes="NO" numberOfVisibleItems="5" id="J98-7B-BLb" customClass="KMComboBoxCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" buttonBordered="NO" completes="NO" numberOfVisibleItems="5" id="J98-7B-BLb" customClass="KMComboBoxCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <font key="font" metaFont="system"/>
                                                         <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                                         <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -487,12 +487,12 @@
                                             <action selector="borderButtonAction:" target="-2" id="yhp-LA-40f"/>
                                         </connections>
                                     </button>
-                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="DvE-Q8-vIM" customClass="KMComboBox" customModule="PDF_Master" customModuleProvider="target">
+                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="DvE-Q8-vIM" customClass="KMComboBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="376" y="65" width="73" height="23"/>
                                         <constraints>
                                             <constraint firstAttribute="width" constant="69" id="RT6-4A-iQr"/>
                                         </constraints>
-                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" completes="NO" numberOfVisibleItems="5" id="vn5-gv-TuS" customClass="KMComboBoxCell" customModule="PDF_Master" customModuleProvider="target">
+                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="center" completes="NO" numberOfVisibleItems="5" id="vn5-gv-TuS" customClass="KMComboBoxCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <font key="font" metaFont="system"/>
                                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -532,7 +532,7 @@
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         </view>
                                     </box>
-                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="qpN-xA-FDn" customClass="KMButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="qpN-xA-FDn" customClass="KMButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="0.0" width="144" height="24"/>
                                         <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="XWY-h5-eoR">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -552,7 +552,7 @@
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         </view>
                                     </box>
-                                    <button tag="1" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oGT-YN-wXO" customClass="KMButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <button tag="1" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oGT-YN-wXO" customClass="KMButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="153" y="0.0" width="143" height="24"/>
                                         <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="yVa-dQ-A17">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -572,7 +572,7 @@
                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         </view>
                                     </box>
-                                    <button tag="2" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZjM-D6-rzr" customClass="KMButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <button tag="2" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZjM-D6-rzr" customClass="KMButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="305" y="0.0" width="144" height="24"/>
                                         <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="udR-nJ-pZY">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -637,12 +637,12 @@
                                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
                                     </textField>
-                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RfV-LZ-n4w" customClass="KMComboBox" customModule="PDF_Master" customModuleProvider="target">
+                                    <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RfV-LZ-n4w" customClass="KMComboBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="376" y="2" width="73" height="23"/>
                                         <constraints>
                                             <constraint firstAttribute="width" constant="69" id="8OG-pa-Aq1"/>
                                         </constraints>
-                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" alignment="center" completes="NO" numberOfVisibleItems="4" id="WNj-OS-5rP" customClass="KMComboBoxCell" customModule="PDF_Master" customModuleProvider="target">
+                                        <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" alignment="center" completes="NO" numberOfVisibleItems="4" id="WNj-OS-5rP" customClass="KMComboBoxCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <font key="font" metaFont="system"/>
                                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -691,7 +691,7 @@
                                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
                                     </textField>
-                                    <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="73D-Hs-5Dt" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                                    <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="73D-Hs-5Dt" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="0.0" width="36" height="24"/>
                                         <view key="contentView" id="ISg-af-EOT">
                                             <rect key="frame" x="1" y="1" width="34" height="22"/>
@@ -717,7 +717,7 @@
                                             <constraint firstAttribute="height" constant="24" id="WTd-3k-L5f"/>
                                         </constraints>
                                     </box>
-                                    <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="khE-p2-Wfd" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                                    <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="khE-p2-Wfd" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="44" y="0.0" width="36" height="24"/>
                                         <view key="contentView" id="Mhb-XI-4wP">
                                             <rect key="frame" x="1" y="1" width="34" height="22"/>
@@ -910,7 +910,7 @@
                                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
                                     </textField>
-                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="oZl-TH-Bvx" customClass="KMPopUpButton" customModule="PDF_Master" customModuleProvider="target">
+                                    <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="oZl-TH-Bvx" customClass="KMPopUpButton" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="-5" y="29" width="454" height="24"/>
                                         <popUpButtonCell key="cell" type="square" title="Item 1" bezelStyle="shadowlessSquare" alignment="left" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" arrowPosition="noArrow" selectedItem="fEY-zW-raT" id="JrJ-qI-5wL">
                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -974,7 +974,7 @@
                                             <subviews>
                                                 <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3Ed-Ae-CMS">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteAnnotationNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="8we-yJ-WKl" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteAnnotationNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="8we-yJ-WKl" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1004,7 +1004,7 @@
                                             <subviews>
                                                 <button tag="1" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pNP-oo-3HC">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteKeywordNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="x9S-PD-K5t" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteKeywordNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="x9S-PD-K5t" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1030,7 +1030,7 @@
                                             <subviews>
                                                 <button tag="3" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VCq-Fv-Klu">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteHelpNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="kSq-7X-thX" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteHelpNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="kSq-7X-thX" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1056,7 +1056,7 @@
                                             <subviews>
                                                 <button tag="4" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="d7b-6U-kd3">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteNewparagraphNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="Xdy-yH-fug" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteNewparagraphNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="Xdy-yH-fug" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1082,7 +1082,7 @@
                                             <subviews>
                                                 <button tag="5" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="sxj-hT-PcD">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteParagraphNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="uwc-Vw-AjX" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteParagraphNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="uwc-Vw-AjX" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1108,7 +1108,7 @@
                                             <subviews>
                                                 <button tag="6" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fgj-OF-eg6">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteInsertNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="OSE-y6-2oj" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteInsertNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="OSE-y6-2oj" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1134,7 +1134,7 @@
                                             <subviews>
                                                 <button tag="2" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="InC-Sr-498">
                                                     <rect key="frame" x="28" y="0.0" width="50" height="56"/>
-                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteNotesNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="4HQ-Cw-eAg" customClass="KMNoteIconButtonCell" customModule="PDF_Master" customModuleProvider="target">
+                                                    <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="KMImageNameUXIconPropertybarNoteNotesNor" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="4HQ-Cw-eAg" customClass="KMNoteIconButtonCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                         <font key="font" metaFont="smallSystem"/>
                                                     </buttonCell>
@@ -1259,7 +1259,7 @@
                                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
                                     </textField>
-                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="RBY-h3-kvf" customClass="KMColorPickerView" customModule="PDF_Master" customModuleProvider="target">
+                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="RBY-h3-kvf" customClass="KMColorPickerView" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="0.0" width="449" height="32"/>
                                         <constraints>
                                             <constraint firstAttribute="height" constant="32" id="H4i-Xv-jdK"/>
@@ -1337,7 +1337,7 @@
             <rect key="frame" x="0.0" y="0.0" width="430" height="80"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="2Yo-7R-xHO" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="2Yo-7R-xHO" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="0.0" width="430" height="80"/>
                     <view key="contentView" id="T8t-nY-fsz">
                         <rect key="frame" x="0.0" y="0.0" width="430" height="80"/>

+ 40 - 40
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/FormProperties/KMAnnotationFromViewController.swift

@@ -573,47 +573,47 @@ import Cocoa
     
     @IBAction func buttonClicked_ChangeFont(_ sender: Any) {
         let fontWindowController = KMAnnotationFontWindowController.sharedAnnotationFont
-        let window = fontWindowController.window
+        let window = fontWindowController!.window
         if fontWindowController != nil && window != nil {
-            fontWindowController.annotations = annotations
-
-            fontWindowController.annotationAlignCallback = { [weak self] selectedCount in
-                guard let self = self else { return }
-                
-                for tAnnotation in self.annotations {
-                    var annotationString = ""
-                    
-                    
-                    if tAnnotation.buttonWidgetStateString().isEmpty {
-                        annotationString = " "
-                    } else {
-                        let lastString = String(tAnnotation.buttonWidgetStateString().suffix(1))
-                        
-                        if lastString == " " {
-                            annotationString = String(tAnnotation.buttonWidgetStateString().prefix(tAnnotation.buttonWidgetStateString().count - 1))
-                        } else {
-                            annotationString = "\(tAnnotation.buttonWidgetStateString()) "
-                        }
-                    }
-                    
-                    switch selectedCount {
-                    case 0:
-                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
-                    case 2:
-                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
-                    case 1:
-                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
-                    case 3:
-                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .justified
-                    default:
-                        break
-                    }
-                    
-                    tAnnotation.setButtonWidgetStateString(annotationString)
-                }
-                
-                self.updateAnnotation()
-            }
+//            fontWindowController!.annotations = annotations
+            
+//            fontWindowController!.annotationAlignCallback = { [weak self] selectedCount in
+//                guard let self = self else { return }
+//                
+//                for tAnnotation in self.annotations {
+//                    var annotationString = ""
+//                    
+//                    
+//                    if tAnnotation.buttonWidgetStateString().isEmpty {
+//                        annotationString = " "
+//                    } else {
+//                        let lastString = String(tAnnotation.buttonWidgetStateString().suffix(1))
+//                        
+//                        if lastString == " " {
+//                            annotationString = String(tAnnotation.buttonWidgetStateString().prefix(tAnnotation.buttonWidgetStateString().count - 1))
+//                        } else {
+//                            annotationString = "\(tAnnotation.buttonWidgetStateString()) "
+//                        }
+//                    }
+//                    
+//                    switch selectedCount {
+//                    case 0:
+//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
+//                    case 2:
+//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
+//                    case 1:
+//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
+//                    case 3:
+//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .justified
+//                    default:
+//                        break
+//                    }
+//                    
+//                    tAnnotation.setButtonWidgetStateString(annotationString)
+//                }
+//                
+//                self.updateAnnotation()
+//            }
             
 //            fontWindowController.annotationCallback = {
 //                

+ 146 - 256
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/WindowController/KMAnnotationFontWindowController.swift

@@ -7,15 +7,31 @@
 
 import Cocoa
 
-@objcMembers class KMAnnotationFontWindowController: NSWindowController {
+@objcMembers
+class KMFontModel: NSObject {
+    var fontName: String = ""
+    var fontWeight: String = ""
+    var fontSize: CGFloat = 12.0
+    var fontColor: NSColor = .black
+    var fontAlignment: KMFreeTextAnnotationAlignmentType = .left
+    var annotationType: CAnnotationType
     
-    static let sharedAnnotationFont: KMAnnotationFontWindowController = KMAnnotationFontWindowController()
-
-    var _annotations: [CPDFAnnotation]?
+    init(fontName: String, fontWeight: String, fontSize: CGFloat, fontColor: NSColor, fontAlignment: KMFreeTextAnnotationAlignmentType, annotationType: CAnnotationType) {
+        self.fontName = fontName
+        self.fontWeight = fontWeight
+        self.fontSize = fontSize
+        self.fontColor = fontColor
+        self.fontAlignment = fontAlignment
+        self.annotationType = annotationType
+    }
+}
 
-    var annotationAlignCallback: ((Int) -> Void)?
-    var annotationCallback: ((CPDFAnnotation) -> Void)?
+@objcMembers class KMAnnotationFontWindowController: NSWindowController {
+    
+    static var sharedAnnotationFont: KMAnnotationFontWindowController!
     
+    var annotationFontModel: KMFontModel?
+    var callback: ((KMFontModel) -> Void)?
     @IBOutlet weak var fontLabel: NSTextField!
     @IBOutlet weak var fontComboBox: NSComboBox!
     @IBOutlet weak var fontWeightLabel: NSTextField!
@@ -40,35 +56,24 @@ import Cocoa
 
     @IBOutlet var fontAdjacencyLayoutConstraint: NSLayoutConstraint!
     @IBOutlet var rowHeightLayoutConstraint: NSLayoutConstraint!
-
-    var _annotation: CPDFAnnotation?
     
     // MARK: Init Methods
     
     deinit {
         NotificationCenter.default.removeObserver(self)
-
-        if let textAnnotation = self.annotation as? CPDFTextAnnotation {
-            let keys: [String] = ["string", "color"]
-            for key in keys {
-                textAnnotation.removeObserver(self, forKeyPath: key)
-            }
+    }
+    
+    static func initWindowController(_ fontModel: KMFontModel) -> KMAnnotationFontWindowController {
+        if sharedAnnotationFont != nil {
+            sharedAnnotationFont.annotationFontModel = fontModel
+            return sharedAnnotationFont
         } else {
-            let keys: [String] = ["string", "color", "interiorColor", "border", "font", "fontColor", "alignment"]
-            for key in keys {
-                self.annotation.removeObserver(self, forKeyPath: key)
-            }
+            let configWC: KMAnnotationFontWindowController = KMAnnotationFontWindowController.init(windowNibName: "KMAnnotationFontWindowController")
+            sharedAnnotationFont = configWC;
+            sharedAnnotationFont.annotationFontModel = fontModel
+            return sharedAnnotationFont
         }
     }
-    
-//    convenience init() {
-//        let windowNibName = NSNib.Name("KMAnnotationFontWindowController")
-//        self.init(windowNibName: "KMAnnotationFontWindowController")
-//    }
-//    
-//    required init?(coder: NSCoder) {
-//        super.init(coder: coder)
-//    }
 
     override func windowDidLoad() {
         super.windowDidLoad()
@@ -92,77 +97,26 @@ import Cocoa
         self.fontAdjacencyStepper.isHidden = true
         self.rowHeightStepper.isHidden = true
         
+        annotationFontReload()
+        reloadData()
+        
         NotificationCenter.default.addObserver(self, selector: #selector(alignmentTypeNotification(_:)), name: NSNotification.Name("KMAnnotationAlignmentTypeNotification"), object: nil)
     }
     
-    // MARK: Get、Set
-
-    var annotations: [CPDFAnnotation] {
-        set {
-            _annotations = newValue
-            
-            annotation = newValue.first!
-            self.reloadData()
-        }
-        get {
-            return _annotations!
-        }
-    }
-    
-    var annotation: CPDFAnnotation {
-        set {
-//            let equal: Bool = ((_annotation?.isEqual(newValue)) != nil)
-            let equal = self._annotation?.isEqual(to: newValue) ?? false
-            if equal {
-                if _annotation is CPDFTextAnnotation {
-                    let keys = ["string", "color"]
-                    for key in keys {
-                        _annotation?.removeObserver(self, forKeyPath: key)
-                    }
-                    _annotation = newValue
-                    for key in keys {
-                        _annotation?.addObserver(self, forKeyPath: key, options: [.new, .old], context: nil)
-                    }
-                } else {
-                    let keys = ["string", "color", "interiorColor", "border", "font", "fontColor", "alignment"]
-                    for key in keys {
-                        _annotation?.removeObserver(self, forKeyPath: key)
-                    }
-                    _annotation = newValue
-                    for key in keys {
-                        _annotation?.addObserver(self, forKeyPath: key, options: [.new, .old], context: nil)
-                    }
-                }
-            }
-        }
-        get {
-            return _annotation!
-        }
-    }
-    
     // MARK: private Method
     
     func reloadData() {
         if fontWeightPopUpButton != nil {
             fontWeightPopUpButton.removeAllItems()
         }
-        if annotation is CPDFFreeTextAnnotation {
-            fontSizePopUpButton.title = "\((annotation as! CPDFFreeTextAnnotation).font.pointSize) pt"
-        } else if annotation is CPDFWidgetAnnotation {
-            fontSizePopUpButton.title = "\((annotation as! CPDFWidgetAnnotation).font.pointSize) pt"
-        }
+        fontSizePopUpButton.title = "\(annotationFontModel?.fontSize ?? 12) pt"
 
         DispatchQueue.global(qos: .default).async {
             let fonts = NSFontManager.shared.availableFontFamilies
             var fontArr = [NSAttributedString]()
             var selectedIndex = 0
-            let family = ""
-            let style = ""
-            if self.annotation is CPDFFreeTextAnnotation {
-                (self.annotation as! CPDFFreeTextAnnotation).font.fontDescriptor.object(forKey: .family)
-            } else if self.annotation is CPDFWidgetAnnotation {
-                (self.annotation as! CPDFWidgetAnnotation).font.fontDescriptor.object(forKey: .face)
-            }
+            let family = self.annotationFontModel?.fontName
+            let style = self.annotationFontModel?.fontWeight
             
             for (index, fontName) in fonts.enumerated() {
                 if let font = NSFont(name: fontName, size: 12.0) {
@@ -170,14 +124,8 @@ import Cocoa
                     let string = NSAttributedString(string: fontName, attributes: attributes)
                     fontArr.append(string)
                     
-                    if self.annotation is CPDFFreeTextAnnotation {
-                        if (self.annotation as! CPDFFreeTextAnnotation).font.fontName == font.fontName {
-                            selectedIndex = index
-                        }
-                    } else if self.annotation is CPDFWidgetAnnotation {
-                        if (self.annotation as! CPDFWidgetAnnotation).font.fontName == font.fontName {
-                            selectedIndex = index
-                        }
+                    if self.annotationFontModel?.fontName == font.fontName {
+                        selectedIndex = index
                     }
                 }
             }
@@ -185,39 +133,19 @@ import Cocoa
             DispatchQueue.main.async {
                 self.fontComboBox.addItems(withObjectValues: fontArr)
                 self.fontComboBox.selectItem(at: selectedIndex)
-                let selectedStyleIndex = self.setFontStyle(fontName: family, currentStyle: style)
-                self.fontWeightPopUpButton.selectItem(at: selectedStyleIndex)
+                let selectedStyleIndex = self.setFontStyle(fontName: family!, currentStyle: style)
+                self.fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
             }
         }
         
-        if annotation is CPDFFreeTextAnnotation {
-            fontColorWell.color = (annotation as! CPDFFreeTextAnnotation).fontColor ?? UserDefaults.standard.color(forKey: CFreeTextNoteFontColorKey) ?? NSColor.black
-        } else if annotation is CPDFWidgetAnnotation {
-            fontColorWell.color = (annotation as! CPDFWidgetAnnotation).fontColor ?? UserDefaults.standard.color(forKey: CFreeTextNoteFontColorKey) ?? NSColor.black
-        }
-        
-        if self.annotation is CPDFFreeTextAnnotation {
-            switch (self.annotation as! CPDFFreeTextAnnotation).alignment {
-            case NSTextAlignment.left:
-                alignmentSegmentedControl.selectedSegment = 0
-            case NSTextAlignment.center:
-                alignmentSegmentedControl.selectedSegment = 1
-            case NSTextAlignment.right:
-                alignmentSegmentedControl.selectedSegment = 2
-            default:
-                break
-            }
-        } else if self.annotation is CPDFTextWidgetAnnotation {
-            switch (self.annotation as! CPDFTextWidgetAnnotation).alignment {
-            case NSTextAlignment.left:
-                alignmentSegmentedControl.selectedSegment = 0
-            case NSTextAlignment.center:
-                alignmentSegmentedControl.selectedSegment = 1
-            case NSTextAlignment.right:
-                alignmentSegmentedControl.selectedSegment = 2
-            default:
-                break
-            }
+        fontColorWell.color = annotationFontModel!.fontColor
+        switch annotationFontModel!.fontAlignment {
+        case .left:
+            alignmentSegmentedControl.selectedSegment = 0
+        case .center:
+            alignmentSegmentedControl.selectedSegment = 1
+        case .right:
+            alignmentSegmentedControl.selectedSegment = 2
         }
         
         fontAdjacencyLayoutConstraint.constant = fontAdjacencyStepper.isHidden ? -fontAdjacencyStepper.frame.size.height : 16.0
@@ -228,41 +156,65 @@ import Cocoa
         rowHeightLabel.isHidden = rowHeightStepper.isHidden
     }
     
-    func setFontStyle(fontName: String, currentStyle style: String?) -> Int {
-        var selectIndex = 0
+    func setFontStyle(fontName: String, currentStyle style: String?) -> UInt {
+        var selectIndex: UInt = 0
         let menu = NSMenu()
-
         if let fontFamily = NSFontManager.shared.availableMembers(ofFontFamily: fontName) {
-            for (index, array) in fontFamily.enumerated() {
-                let styleName = array[1] as! String
-
-                if style == styleName {
-                    selectIndex = index
-                }
-
-                let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [
-                    NSFontDescriptor.AttributeName.family: fontName,
-                    NSFontDescriptor.AttributeName.face: styleName
-                ])
-                
-                if let font = NSFont(descriptor: attributeFontDescriptor, size: 12.0) {
-                    let attributedString = NSAttributedString(string: styleName, attributes: [NSAttributedString.Key.font: font])
+            for i in 0..<fontFamily.count {
+                let array = fontFamily[i]
+                if let styleName = array[1] as? String {
+                    if style == styleName {
+                        selectIndex = UInt(i)
+                    }
+                    let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: fontName, NSFontDescriptor.AttributeName.face: styleName])
+                    let font = NSFont(descriptor: attributeFontDescriptor, size: 12.0)
+                    let attrited = [NSAttributedString.Key.font: font]
+                    let string = NSAttributedString(string: styleName, attributes: attrited)
                     let item = NSMenuItem()
-                    item.attributedTitle = attributedString
+                    item.attributedTitle = string
+                    
                     menu.addItem(item)
                 }
             }
         }
-
+        
         if style == nil {
             selectIndex = 0
         }
-
+        
         fontWeightPopUpButton.menu = menu
-
+        
         return selectIndex
     }
 
+    func annotationFontReload() {
+        DispatchQueue.global(qos: .default).async { [self] in
+            let fonts = NSFontManager.shared.availableFontFamilies
+            let menu = NSMenu()
+            var selectedIndex = 0
+            
+            for (index, fontName) in fonts.enumerated() {
+                if let font = NSFont(name: fontName, size: 12.0) {
+                    let attributedString = NSAttributedString(string: fontName, attributes: [NSAttributedString.Key.font: font])
+                    let item = NSMenuItem()
+                    item.attributedTitle = attributedString
+                    menu.addItem(item)
+                    
+                    if annotationFontModel?.fontName == font.fontName {
+                        selectedIndex = index
+                    }
+                }
+            }
+            DispatchQueue.main.async { [self] in
+                fontComboBox.menu = menu
+                fontComboBox.selectItem(at: selectedIndex)
+                
+                let selectedStyleIndex = setFontStyle(fontName: annotationFontModel!.fontName, currentStyle: annotationFontModel!.fontWeight)
+                fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
+            }
+        }
+    }
+
     // MARK: Action
     
     @IBAction func fontComboBoxAction(_ sender: NSComboBox) {
@@ -271,138 +223,76 @@ import Cocoa
         let familyString = resultAtt.string
         let selectIndex = setFontStyle(fontName: familyString, currentStyle: nil)
         let styleString = self.fontWeightPopUpButton.selectedItem?.title
-        self.fontWeightPopUpButton.selectItem(at: selectIndex)
+        self.fontWeightPopUpButton.selectItem(at: Int(selectIndex))
         
-        for tAnnotation in self.annotations {
-            if tAnnotation is CPDFFreeTextAnnotation {
-                if let font = (tAnnotation as! CPDFFreeTextAnnotation).font {
-                    if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? String {
-                        let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
-                        if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat((fontSize as NSString).floatValue)) {
-                            (tAnnotation as! CPDFFreeTextAnnotation).font = newFont
-                            if let annotationCallback = self.annotationCallback {
-                                annotationCallback(tAnnotation)
-                            }
-                        }
-                    }
-                }
-            } else if tAnnotation is CPDFWidgetAnnotation {
-                if let font = (tAnnotation as! CPDFWidgetAnnotation).font {
-                    if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? String {
-                        let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
-                        if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat((fontSize as NSString).floatValue)) {
-                            (tAnnotation as! CPDFWidgetAnnotation).font = newFont
-                            if let annotationCallback = self.annotationCallback {
-                                annotationCallback(tAnnotation)
-                            }
-                        }
-                    }
-                }
+        let font = NSFont(name: familyString, size: fontSizePopUpButton.stringValue.stringToCGFloat()) ?? NSFont.systemFont(ofSize: 16)
+        if let family = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
+           let style = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
+            DispatchQueue.main.async {
+                let selectedStyleIndex = self.setFontStyle(fontName: family, currentStyle: style)
+                self.fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
             }
         }
+        annotationFontModel!.fontName = familyString
+        annotationFontModel!.fontWeight = fontWeightPopUpButton.selectedItem!.title
+        if let callback = self.callback {
+            callback(annotationFontModel!)
+        }
     }
     
     @IBAction func fontSizeComboBoxAction(_ sender: NSPopUpButton) {
-        for tAnnotation in annotations {
-            if tAnnotation is CPDFFreeTextAnnotation {
-                if var font = (tAnnotation as! CPDFFreeTextAnnotation).font {
-                    let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
-                    if let fontSize = Float(fontSizeString) {
-                        font = NSFont(name: font.fontName, size: CGFloat(fontSize))!
-                        (tAnnotation as! CPDFFreeTextAnnotation).font = font
-                    }
-                }
-            } else if tAnnotation is CPDFWidgetAnnotation {
-                if var font = (tAnnotation as! CPDFWidgetAnnotation).font {
-                    let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
-                    if let fontSize = Float(fontSizeString) {
-                        font = NSFont(name: font.fontName, size: CGFloat(fontSize))!
-                        (tAnnotation as! CPDFWidgetAnnotation).font = font
-                    }
-                }
-            }
-            
-            if let annotationCallback = annotationCallback {
-                annotationCallback(tAnnotation)
-            }
+        let selectItem = self.fontComboBox.indexOfSelectedItem
+        let resultAtt = NSMutableAttributedString(attributedString: self.fontComboBox.itemObjectValue(at: selectItem) as! NSAttributedString)
+        let familyString = resultAtt.string
+        let styleString = self.fontWeightPopUpButton.selectedItem?.title
+        let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
+
+        annotationFontModel?.fontSize = fontSizeString.stringToCGFloat()
+        if let callback = self.callback {
+            callback(annotationFontModel!)
         }
     }
     
-    @IBAction func fontColorWellAction(_ sender: NSColorWell) {
-        for tAnnotation in annotations {
-            if tAnnotation is CPDFFreeTextAnnotation {
-                (tAnnotation as! CPDFFreeTextAnnotation).fontColor = sender.color
-            } else if tAnnotation is CPDFWidgetAnnotation {
-                (tAnnotation as! CPDFWidgetAnnotation).fontColor = sender.color
-            }
-            
-            if let annotationCallback = annotationCallback {
-                annotationCallback(tAnnotation)
-            }
+    @IBAction func fontStylePopUpButtonAction(_ sender: NSPopUpButton) {
+        guard let styleString = fontWeightPopUpButton.selectedItem?.title else {
+            return
         }
-    }
-    
-    @IBAction func alignButtonAction(_ sender: NSSegmentedControl) {
-        var alignCount = 0
+        let selectItem = self.fontComboBox.indexOfSelectedItem
+        let resultAtt = NSMutableAttributedString(attributedString: self.fontComboBox.itemObjectValue(at: selectItem) as! NSAttributedString)
+        let familyString = resultAtt.string
         
-        for tAnnotation in self.annotations {
-            if tAnnotation is CPDFFreeTextAnnotation {
-                switch sender.selectedSegment {
-                case 0:
-                    alignCount = 0
-                    (tAnnotation as! CPDFFreeTextAnnotation).alignment = .left
-                case 1:
-                    alignCount = 2
-                    (tAnnotation as! CPDFFreeTextAnnotation).alignment = .center
-                case 2:
-                    alignCount = 1
-                    (tAnnotation as! CPDFFreeTextAnnotation).alignment = .right
-                default:
-                    break
-                }
-            } else if tAnnotation is CPDFTextWidgetAnnotation {
-                switch sender.selectedSegment {
-                case 0:
-                    alignCount = 0
-                    (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
-                case 1:
-                    alignCount = 2
-                    (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
-                case 2:
-                    alignCount = 1
-                    (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
-                default:
-                    break
-                }
-            }
+        annotationFontModel?.fontName = familyString
+        annotationFontModel?.fontWeight = styleString
+        if let callback = self.callback {
+            callback(annotationFontModel!)
         }
-        
-        self.annotationAlignCallback!(alignCount)
     }
     
-    // MARK: Notification
-    
-    // 监听属性变化
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
-        guard let observedObject = object as AnyObject?, observedObject !== self.annotation else {
-            return
+    @IBAction func fontColorWellAction(_ sender: NSColorWell) {
+        annotationFontModel?.fontColor = sender.color
+        if let callback = self.callback {
+            callback(annotationFontModel!)
         }
 
-        let newValue = change?[.newKey] ?? NSNull()
-        let oldValue = change?[.oldKey] ?? NSNull()
-
-        if (newValue as AnyObject).isEqual(oldValue) {
-            return
+    }
+    
+    @IBAction func alignButtonAction(_ sender: NSSegmentedControl) {
+        switch sender.selectedSegment {
+        case 0:
+            annotationFontModel?.fontAlignment = .left
+        case 1:
+            annotationFontModel?.fontAlignment = .center
+        case 2:
+            annotationFontModel?.fontAlignment = .right
+        default:
+            break
         }
-
-        if keyPath == "string" {
-            if let newValue = newValue as? NSNull {
-                return
-            }
-        } else {
-            reloadData()
+        if let callback = self.callback {
+            callback(annotationFontModel!)
         }
     }
+    
+    // MARK: Notification
 
 
     // 处理对齐类型通知

+ 1 - 1
PDF Office/PDF Master/Class/Purchase/DMG/Verification/VerificationManager/VerificationManager.h

@@ -12,7 +12,7 @@
 //#import "ASIFormDataRequest.h"
 //#import "JSONKit.h"
 
-#define kTestMode   0
+#define kTestMode   1
 
 #if kTestMode