Просмотр исходного кода

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

tangchao 10 месяцев назад
Родитель
Сommit
581d22bac0

+ 9 - 0
PDF Office/PDF Master/Class/DigtalSignature/ViewControllers/CDSignatureCertificateCustomViewController.swift

@@ -427,6 +427,15 @@ class CDSignatureCertificateCustomViewController: NSViewController, NSTextFieldD
         openPanel.beginSheetModal(for: self.view.window!) { result in
             if result == .OK {
                 let fileURL = openPanel.urls.first
+                let document = CPDFDocument(url: fileURL)
+                if !document!.allowsCopying || !document!.allowsPrinting {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
+                    alert.runModal()
+                    return
+                }
+                
                 self.appearanceData.signatureConfig.text = ""
                 self.photoImage = NSImage(contentsOf: fileURL!)
                 self.appearanceData.signatureConfig.image = self.photoImage

+ 45 - 0
PDF Office/PDF Master/Class/Document/KMMainDocument.swift

@@ -195,6 +195,7 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
             mainViewController?.document = pdfDocument
         }
         
+        convertNotesUsingPDFDocument((mainViewController?.document)!)
         self.view = mainViewController?.view
         
         if let currentBrowser = currentWindowController?.browser {
@@ -892,6 +893,50 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
         KMPrint("showWindow")
     }
     
+    func convertNotesUsingPDFDocument(_ pdfDocument: CPDFDocument) {
+        mainViewController!.beginProgressSheet(withMessage: NSLocalizedString("Converting notes", comment: "Message for progress sheet").appending("..."), maxValue: 0)
+        
+        let count = pdfDocument.pageCount
+        let pdfView = mainViewController?.listView
+        
+        for i in 0..<count {
+            let page = pdfDocument.page(at: i)
+            
+            var addAnnotations = [CPDFAnnotation]()
+            var removeAnnotations = [CPDFAnnotation]()
+            
+            for annotation in page?.annotations ?? [] {
+                var newAnnotation: CPDFAnnotation?
+                if let inkAnnotation = annotation as? CPDFInkAnnotation, inkAnnotation.contents.hasPrefix("<?xml version=\"1.0\" encoding=\"utf-8\"?>") {
+                    let table = KMTableAnnotation(KMNoteBounds: annotation.bounds, document: pdfView!.document)
+                    table.border = annotation.border
+                    table.color = annotation.color
+                    table.createForm(withList: annotation.contents, andPaths: inkAnnotation.bezierPaths())
+                    table.updateAppearanceInk(withIsAdd: false)
+                    newAnnotation = table
+                }
+                if let newAnnotation = newAnnotation {
+                    addAnnotations.append(newAnnotation)
+                    removeAnnotations.append(annotation)
+                }
+            }
+            
+            for i in 0..<addAnnotations.count {
+                let newAnnotation = addAnnotations[i]
+                let annotation = removeAnnotations[i]
+                
+                // this is only to make sure markup annotations generate the lineRects, for thread safety
+                pdfView!.addAnnotation(with: newAnnotation, to: page)
+                pdfView!.remove(annotation)
+            }
+        }
+        
+        mainViewController!.dismissProgressSheet()
+        
+        pdfView?.undoManager?.removeAllActions()
+        undoManager?.removeAllActions()
+    }
+    
     // MARK: - Private Methods
     
     private func _km_write(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws {

+ 7 - 2
PDF Office/PDF Master/Class/PDFTools/Compare/ViewController/CoveringComplete/View/KMCompareCoveringView.swift

@@ -53,8 +53,12 @@ class KMCompareCoveringView: KMBaseXibView {
         oldPColorView.layer?.backgroundColor = KMCompareFilesConfig.defaultConfig.oldStrokeColor().cgColor
         nPDFColorView.layer?.backgroundColor = KMCompareFilesConfig.defaultConfig.newStrokeColor().cgColor
         
-        saveBtn.setTitleColor(NSColor.white)
-        closeBtn.setTitleColor(NSColor.white)
+//        saveBtn.setTitleColor(NSColor.white)
+//        closeBtn.setTitleColor(NSColor.white)
+        
+        saveBtn.contentTintColor = NSColor.white
+        
+        closeBtn.contentTintColor = NSColor.white
     }
 
     override func reloadData() {
@@ -67,6 +71,7 @@ class KMCompareCoveringView: KMBaseXibView {
         
         saveBtn.title = NSLocalizedString("Save", comment: "")
         closeBtn.title = NSLocalizedString("Close", comment: "")
+        
     }
     // MARK: - IBAction
 

+ 105 - 104
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/KMStampManager.swift

@@ -320,113 +320,114 @@ let CPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
                 return false
             }
         }
+        var newDictionary: [String: Any]
+        if let dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
+            newDictionary = dictionary
+        }else{
+            newDictionary = [:]
+        }
+        let tag = tagString()
+        var text = ""
+        var detailText = ""
         
-        if var dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
-            var newDictionary = dictionary
-            
-            let tag = tagString()
-            var text = ""
-            var detailText = ""
-            
-            var stampDictionary: [String: Any] = [:]
-            if let string = string {
-                stampDictionary[kStampOfStringKey] = string
-                text = string
-            }
-            if let dateString = dateString {
-                stampDictionary[kStampOfSubStringKey] = dateString
-                detailText = dateString
-            }
-            if let date = date {
-                stampDictionary[kStampDateKey] = date
-            }
-            if let time = time {
-                stampDictionary[kStampTimeKey] = time
-            }
-            stampDictionary[kStampOfCategoryKey] = categoryString.rawValue
-            
-            if let nameString = nameString {
-                stampDictionary[kStampOfNameKey] = nameString
-                detailText = "\(detailText) \(nameString)"
-            }
-            
-            var colorV = 0
-            if color == .white {
-                if shape == .rectangle {
-                    
-                } else if shape == .arrowLeft {
-                    
-                } else if shape == .arrowRight {
-                    
-                } else {
-                    colorV = 14
-                }
-            } else if color == .red {
-                if shape == .rectangle {
-                    colorV = 0
-                } else if shape == .arrowLeft {
-                    colorV = 8
-                } else if shape == .arrowRight {
-                    colorV = 11
-                } else {
-                    
-                }
-            } else if color == .green {
-                if shape == .rectangle {
-                    colorV = 1
-                } else if shape == .arrowLeft {
-                    colorV = 9
-                } else if shape == .arrowRight {
-                    colorV = 12
-                } else {
-                    
-                }
-            } else if color == .blue {
-                if shape == .rectangle {
-                    colorV = 2
-                } else if shape == .arrowLeft {
-                    colorV = 10
-                } else if shape == .arrowRight {
-                    colorV = 13
-                } else {
-                    
-                }
+        var stampDictionary: [String: Any] = [:]
+        if let string = string {
+            stampDictionary[kStampOfStringKey] = string
+            text = string
+        }
+        if let dateString = dateString {
+            stampDictionary[kStampOfSubStringKey] = dateString
+            detailText = dateString
+        }
+        if let date = date {
+            stampDictionary[kStampDateKey] = date
+        }
+        if let time = time {
+            stampDictionary[kStampTimeKey] = time
+        }
+        stampDictionary[kStampOfCategoryKey] = categoryString.rawValue
+        
+        if let nameString = nameString {
+            stampDictionary[kStampOfNameKey] = nameString
+            detailText = "\(detailText) \(nameString)"
+        }
+        
+        var colorV = 0
+        if color == .white {
+            if shape == .rectangle {
+                
+            } else if shape == .arrowLeft {
+                
+            } else if shape == .arrowRight {
+                
             } else {
                 colorV = 14
             }
-//            else if color == 3 { // KMAnnotationStampBlackColor
-////                                style = .black
-//                shape = .rectangle
-//            } else if color == 4 { // KMAnnotationStampLightRedColor
-//                style = .red
-//                shape = .rectangle
-//            } else if color == 5 { // KMAnnotationStampDarkRedColor
-//                style = .red
-//                shape = .rectangle
-//            } else if color == 6 { // KMAnnotationStampPurpleColor
-////                                style = .purple
-//                shape = .rectangle
-//            }
-            
-            
-            stampDictionary[kStampOfColorKey] = colorV
-            stampDictionary[kStampOfDateKey] = Date()
-            stampDictionary[kStampNeedExchangKey] = needExchangeFontSize ? "1" : "0"
-            
-            newDictionary[tag] = stampDictionary
-            
-            var stamp: CStampObject?
-            if categoryString == .text { // categoryString == 1
-                stamp = CStampObject(text: text, detailText: dateString ?? "", style: color, shape: shape )
-                stamp?.dateString = date ?? ""
-                stamp?.timeString = time ?? ""
+        } else if color == .red {
+            if shape == .rectangle {
+                colorV = 0
+            } else if shape == .arrowLeft {
+                colorV = 8
+            } else if shape == .arrowRight {
+                colorV = 11
+            } else {
+                
             }
-            
-            if (newDictionary as NSDictionary).write(toFile: kStampPlistPath.path, atomically: true), let stamp = stamp {
-                stamp.stampKey = tag
-                stamps.append(stamp)
-                return true
+        } else if color == .green {
+            if shape == .rectangle {
+                colorV = 1
+            } else if shape == .arrowLeft {
+                colorV = 9
+            } else if shape == .arrowRight {
+                colorV = 12
+            } else {
+                
             }
+        } else if color == .blue {
+            if shape == .rectangle {
+                colorV = 2
+            } else if shape == .arrowLeft {
+                colorV = 10
+            } else if shape == .arrowRight {
+                colorV = 13
+            } else {
+                
+            }
+        } else {
+            colorV = 14
+        }
+        //            else if color == 3 { // KMAnnotationStampBlackColor
+        ////                                style = .black
+        //                shape = .rectangle
+        //            } else if color == 4 { // KMAnnotationStampLightRedColor
+        //                style = .red
+        //                shape = .rectangle
+        //            } else if color == 5 { // KMAnnotationStampDarkRedColor
+        //                style = .red
+        //                shape = .rectangle
+        //            } else if color == 6 { // KMAnnotationStampPurpleColor
+        ////                                style = .purple
+        //                shape = .rectangle
+        //            }
+        
+        
+        stampDictionary[kStampOfColorKey] = colorV
+        stampDictionary[kStampOfDateKey] = Date()
+        stampDictionary[kStampNeedExchangKey] = needExchangeFontSize ? "1" : "0"
+        
+        newDictionary[tag] = stampDictionary
+        
+        var stamp: CStampObject?
+        if categoryString == .text { // categoryString == 1
+            stamp = CStampObject(text: text, detailText: dateString ?? "", style: color, shape: shape )
+            stamp?.dateString = date ?? ""
+            stamp?.timeString = time ?? ""
+        }
+        
+        if (newDictionary as NSDictionary).write(toFile: kStampPlistPath.path, atomically: true), let stamp = stamp {
+            stamp.stampKey = tag
+            stamps.append(stamp)
+            return true
         }
         
         return false
@@ -458,7 +459,7 @@ let CPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
                     return false
                 }
                 
-                if var dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
+                if let dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
                     var newDictionary = dictionary
                     
                     let stamp = CStampObject(imageStampFilePath: rPath)
@@ -479,7 +480,7 @@ let CPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
                         return true
                     }
                 } else {
-                    var newDictionary = NSMutableDictionary()
+                    let newDictionary = NSMutableDictionary()
                     
                     let stamp = CStampObject(imageStampFilePath: rPath)
                     stamp.nameString = nameString
@@ -516,7 +517,7 @@ let CPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
             return false
         }
         
-        if var dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
+        if let dictionary = NSDictionary(contentsOfFile: kStampPlistPath.path) as? [String: Any] {
             var newDictionary = dictionary
             newDictionary.removeValue(forKey: key)