Browse Source

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

niehaoyu 10 months ago
parent
commit
c9fc13067f

+ 1 - 0
PDF Office/PDF Master/Class/Common/OC/Batch/KMOCTool.h

@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
 +(CGRect)localCropRectForWindow:(CGWindowID)wNumber withBounds:(CGRect)bounds;
 +(NSAttributedString *)transformAttr:(NSAttributedString *)astring withString:(NSString *)str;
 +(NSDictionary *)convertExcelToPdfFilePath:(NSString *)filePath savePath:(NSString *)savePath;
++(NSDictionary *)convertOfficeFileToPdf:(NSString *)convertString;
 @end
 
 NS_ASSUME_NONNULL_END

+ 7 - 0
PDF Office/PDF Master/Class/Common/OC/Batch/KMOCTool.m

@@ -282,4 +282,11 @@ static NSData *convertStringsToPDF(NSArray<NSAttributedString *> *strings)
     return dic;
 }
 
++ (NSDictionary *)convertOfficeFileToPdf:(NSString *)convertString{
+    NSDictionary * dic = nil;
+    NSAppleScript *docScript = [[NSAppleScript alloc] initWithSource:convertString];
+    [docScript executeAndReturnError:&dic];
+    return dic;
+}
+
 @end

+ 9 - 5
PDF Office/PDF Master/Class/DigtalSignature/CPDFDigtalView/KMPDFDigitalSignViewController.swift

@@ -361,11 +361,15 @@ class KMPDFDigitalSignViewController: NSViewController, CPDFViewDelegate, CPDFDi
                 stateVCSelf.dismiss(stateVCSelf)
             } else if actionType == .confirm {
                 let signer = signature.signers.first
-                let signatureDetail = DSignatureDetailsViewController.init()
-                signatureDetail.certificates = (signer?.certificates)!
-                signatureDetail.signature = signature
-                signatureDetail.pdfListView = pdfListView
-                stateVCSelf.presentAsSheet(signatureDetail)
+                if let data = signer?.certificates {
+                    let signatureDetail = DSignatureDetailsViewController.init()
+                    signatureDetail.certificates = data
+                    signatureDetail.signature = signature
+                    signatureDetail.pdfListView = pdfListView
+                    stateVCSelf.presentAsSheet(signatureDetail)
+                } else {
+                    NSSound.beep()
+                }
             }
         }
         self.presentAsSheet(self.stateVC)

+ 18 - 32
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -429,43 +429,29 @@ extension KMHomeViewController {
                         showLimitWindowAlert(url: url)
                         return
                     }
-                    KMMainDocument().tryToUnlockDocument(pdfDoc!)
-                    var selectDocument: KMMainDocument? = nil
-                    if ((document?.isKind(of: KMMainDocument.self)) != nil) {
-                        selectDocument = (document as! KMMainDocument)
-                    }
-                    if selectDocument != nil {
-                        let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
-                        selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
-                        if (selectDocument?.browser.window.isVisible)! as Bool {
+                }
+                
+                KMMainDocument().tryToUnlockDocument(pdfDoc!)
+                var selectDocument: KMMainDocument? = nil
+                if ((document?.isKind(of: KMMainDocument.self)) != nil) {
+                    selectDocument = (document as! KMMainDocument)
+                }
+                if selectDocument != nil {
+                    if selectDocument?.browser != nil {
+                        let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument) ?? 0
+                        selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
+                        let isVisible: Bool = selectDocument?.browser.window.isVisible ?? false
+                        let isMiniaturized: Bool = selectDocument?.browser.window.isMiniaturized ?? false
+                        
+                        if isVisible {
                             selectDocument?.browser.window.orderFront(nil)
-                        } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
+                        } else if isMiniaturized {
                             selectDocument?.browser.window.orderFront(nil)
                         }
-                    } else {
-                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
-                            
-                        }
                     }
                 } else {
-                    var selectDocument: KMMainDocument? = nil
-                    if ((document?.isKind(of: KMMainDocument.self)) != nil) {
-                        selectDocument = (document as! KMMainDocument)
-                    }
-                    if selectDocument != nil {
-                        if selectDocument?.browser != nil {
-                            let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
-                            selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
-                            if (selectDocument?.browser.window.isVisible)! as Bool {
-                                selectDocument?.browser.window.orderFront(nil)
-                            } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
-                                selectDocument?.browser.window.orderFront(nil)
-                            }
-                        }
-                    } else {
-                        NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
-                            
-                        }
+                    NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                        
                     }
                 }
             } else {

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

@@ -1028,8 +1028,10 @@ extension KMHeaderFooterView {
     }
 
     @IBAction func chooseColor(_ sender: NSColorWell) {
-        headerFooterObj.textColor =  KMWatermarkAdjectiveText.color(red: sender.color.redComponent, green: sender.color.greenComponent, blue: sender.color.blueComponent, alpha: sender.color.alphaComponent)
-        self.updatePDFView()
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            headerFooterObj.textColor =  KMWatermarkAdjectiveText.color(red: color.redComponent, green: color.greenComponent, blue: color.blueComponent, alpha: color.alphaComponent)
+            self.updatePDFView()
+        }
     }
 
     @IBAction func chooseFont(_ sender: NSComboBox) {

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

@@ -780,8 +780,10 @@ extension KMAddBackgroundView {
 //    }
     
     @objc func colorWellDidChange(_ sender: NSColorWell) {
-        background.color = sender.color
-        self.updatePDFView()
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            background.color = color
+            self.updatePDFView()
+        }
     }
 
     @IBAction func radioStepperAction(_ sender: NSStepper) {

+ 31 - 13
PDF Office/PDF Master/Class/PDFTools/Convert/NewController/Common/KMConvertPDFManager.swift

@@ -180,11 +180,12 @@ class KMConvertPDFManager: NSObject {
             convertString.append("if not isRun then quit\n")
             convertString.append("end tell\n")
 
-            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
-            let docScript = NSAppleScript(source: convertString)
-            docScript?.executeAndReturnError(dic)
+//            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
+//            let docScript = NSAppleScript(source: convertString)
+//            docScript?.executeAndReturnError(dic)
+            let dic = KMOCTool.convertOfficeFile(toPdf: convertString)
             DispatchQueue.main.async {
-                completionHandler(true, dic?.pointee)
+                completionHandler(true, dic as NSDictionary)
             }
         }
     }
@@ -239,11 +240,12 @@ class KMConvertPDFManager: NSObject {
             convertString.append("close active presentation\n")
             convertString.append("end tell\n")
 
-            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
-            let docScript = NSAppleScript(source: convertString)
-            docScript?.executeAndReturnError(dic)
+//            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
+//            let docScript = NSAppleScript(source: convertString)
+//            docScript?.executeAndReturnError(dic)
+            let dic = KMOCTool.convertOfficeFile(toPdf: convertString)
             DispatchQueue.main.async {
-                completionHandler(true, dic?.pointee)
+                completionHandler(true, dic as NSDictionary)
             }
         }
     }
@@ -275,7 +277,22 @@ class KMConvertPDFManager: NSObject {
     
     class func convertExcelPath(_ filePath: String, savePath: String, completionHandler: @escaping ((Bool, NSDictionary?) -> Void)) {
         DispatchQueue.global().async {
-            let dic = KMOCTool.convertExcel(toPdfFilePath: filePath, savePath: savePath)
+            var convertString = String(format: "set filePath to\"%@\"\n", filePath)
+            convertString = convertString.appendingFormat("set savePath to \"%@\"\n", savePath)
+            convertString.append("set tFile to (POSIX path of filePath) as POSIX file\n")
+            convertString.append("tell application \"Microsoft Excel\"\n")
+            convertString.append("set isRun to running\n")
+            convertString.append("set wkbk1 to open workbook workbook file name tFile\n")
+            convertString.append("alias savePath\n")
+            convertString.append("save workbook as wkbk1 filename savePath file format PDF file format with overwrite\n")
+            convertString.append("close wkbk1 saving no\n")
+            convertString.append("if not isRun then quit\n")
+            convertString.append("end tell\n")
+            
+//            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
+//            let docScript = NSAppleScript(source: convertString)
+//            docScript?.executeAndReturnError(dic)
+            let dic = KMOCTool.convertOfficeFile(toPdf: convertString)
             DispatchQueue.main.async {
                 completionHandler(true, dic as NSDictionary)
             }
@@ -294,11 +311,12 @@ class KMConvertPDFManager: NSObject {
             convertString.append("if not isRun then quit\n")
             convertString.append("end tell")
 
-            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
-            let docScript = NSAppleScript(source: convertString)
-            docScript?.executeAndReturnError(dic)
+//            let dic: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil
+//            let docScript = NSAppleScript(source: convertString)
+//            docScript?.executeAndReturnError(dic)
+            let dic = KMOCTool.convertOfficeFile(toPdf: convertString)
             DispatchQueue.main.async {
-                completionHandler(true, dic?.pointee)
+                completionHandler(true, dic as NSDictionary)
             }
         }
     }

+ 5 - 2
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -914,8 +914,11 @@ extension KMWatermarkView {
     }
     
     @IBAction func colorWellColorChanged(_ sender: NSColorWell) {
-        self.watermark.textColor = KMWatermarkAdjectiveText.color(red: sender.color.redComponent, green: sender.color.greenComponent, blue: sender.color.blueComponent, alpha: sender.color.alphaComponent)
-        updatePDFView()
+        let convertedColor = sender.color.usingColorSpaceName(NSColorSpaceName.deviceRGB)
+        if let rgbColor = convertedColor {
+            self.watermark.textColor = KMWatermarkAdjectiveText.color(red: rgbColor.redComponent, green: rgbColor.greenComponent, blue: rgbColor.blueComponent, alpha: rgbColor.alphaComponent)
+            updatePDFView()
+        }
     }
     
     @IBAction func radioStepperAction(_ sender: NSStepper) {

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.xib

@@ -112,6 +112,7 @@
                                                     <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                                     <size key="minSize" width="247" height="58"/>
                                                     <size key="maxSize" width="262" height="10000000"/>
+                                                    <color key="insertionPointColor" name="textInsertionPointColor" catalog="System" colorSpace="catalog"/>
                                                 </textView>
                                             </subviews>
                                         </clipView>

+ 5 - 3
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/WindowController/KMAnnotationFontWindowController.swift

@@ -283,9 +283,11 @@ class KMFontModel: NSObject {
     }
     
     @IBAction func fontColorWellAction(_ sender: NSColorWell) {
-        annotationFontModel?.fontColor = sender.color
-        if let callback = self.callback {
-            callback(annotationFontModel!)
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            annotationFontModel?.fontColor = color
+            if let callback = self.callback {
+                callback(annotationFontModel!)
+            }
         }
 
     }

+ 9 - 3
PDF Office/PDF Master/Class/Preference/Controller/KMDisplayPreferences.swift

@@ -184,15 +184,21 @@ import Cocoa
     }
     
     @objc func normalColorAction(_ sender: NSColorWell) {
-        KMPreference.shared.displayBackgroundNormalColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.displayBackgroundNormalColor = color
+        }
     }
     
     @objc func fullScreenColorAction(_ sender: NSColorWell) {
-        KMPreference.shared.displayBackgroundFullScreenColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.displayBackgroundFullScreenColor = color
+        }
     }
     
     @objc func readBarColorAction(_ sender: NSColorWell) {
-        KMPreference.shared.readBarColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.readBarColor = color
+        }
     }
     
     @objc func invertBarAction(_ sender: NSButton) {

+ 30 - 10
PDF Office/PDF Master/Class/Preference/Controller/KMNotesPreferences.swift

@@ -316,11 +316,15 @@ class KMNotesPreferences: NSViewController {
     }
     
     @objc func anchoredColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupNoteColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupNoteColor = color
+        }
     }
     
     @objc func lineColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupLineColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupLineColor = color
+        }
     }
     
     @objc func lineInteriorColorWellAction(_ sender: NSColorWell) {
@@ -328,35 +332,51 @@ class KMNotesPreferences: NSViewController {
     }
     
     @objc func circleColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupCircleBorderColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupCircleBorderColor = color
+        }
     }
     
     @objc func circleInteriorColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupCircleFillColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupCircleFillColor = color
+        }
     }
     
     @objc func rectColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupRectangleBorderColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupRectangleBorderColor = color
+        }
     }
     
     @objc func rectInteriorColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupRectangleFillColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupRectangleFillColor = color
+        }
     }
     
     @objc func highlightColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupHighlightColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupHighlightColor = color
+        }
     }
     
     @objc func underlineColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupUnderlineColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupUnderlineColor = color
+        }
     }
     
     @objc func strikeThroughColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupStrikthroughColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupStrikthroughColor = color
+        }
     }
     
     @objc func freehandColorWellAction(_ sender: NSColorWell) {
-        KMPreference.shared.markupPenColor = sender.color
+        if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
+            KMPreference.shared.markupPenColor = color
+        }
     }
     
     // MARK: - Font