Ver código fonte

【注释】Table注释开启文档注释转换效果修改

wanjun 10 meses atrás
pai
commit
e2c8b856aa

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

@@ -199,9 +199,6 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
             mainViewController?.document = pdfDocument
         }
         
-        if let pdfDoc = self.mainViewController?.document {
-            self.convertNotesUsingPDFDocument(pdfDoc)
-        }
         self.view = mainViewController?.view
         
         if let currentBrowser = currentWindowController?.browser {
@@ -902,51 +899,7 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
     @IBAction func showWindow(_ sender: Any?) {
         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 _PDFBundleFileWrapper(for name: String) -> FileWrapper {

+ 50 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift

@@ -131,6 +131,56 @@ extension KMMainViewController {
         }
     }
     
+    func convertNotesUsingPDFDocument(_ pdfDocument: CPDFDocument) {
+        beginProgressSheet(withMessage: NSLocalizedString("Converting notes", comment: "Message for progress sheet").appending("..."), maxValue: 0)
+        
+        let count = pdfDocument.pageCount
+        let pdfView = 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?
+                let inkAnnotation1 = annotation as? CPDFInkAnnotation
+                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)
+                if newAnnotation.contents != nil {
+                    if newAnnotation.contents.count == 0 {
+                        newAnnotation.autoUpdateString()
+                    }
+                }
+            }
+        }
+        
+        dismissProgressSheet()
+        
+        pdfView?.undoManager?.removeAllActions()
+        undoManager?.removeAllActions()
+    }
+    
     // MARK: - KMInterfaceThemeChangedProtocol
     
     override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {

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

@@ -2390,13 +2390,15 @@ let LOCKED_KEY  = "locked"
     
     //MARK: - PDFListViewDelegate
     func pdfViewDocumentDidLoaded(_ pdfView: CPDFView!) {
-//        KMPrint("pdfViewDocumentDidLoaded")
         
         self.removeBackgroundMaskView()
         if (!self.listView.document!.allowsCopying || !self.listView.document!.allowsPrinting) {
             self.showSecureLimitTip()
         }
         
+        if self.document != nil {
+            self.convertNotesUsingPDFDocument(self.document!)
+        }
         if (self._documentFirstLoad) {
             self.checkShouldAutoOpenLeftVC()
             if (KMPreferenceManager.shared.openLastUnlockedDocumentWhenAppStart) {