Browse Source

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

niehaoyu 1 year ago
parent
commit
0b95857d32

+ 8 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationPropertiesViewController.m

@@ -125,8 +125,14 @@
     }
 
     if (_annotations.count > 1) {
-        [self selectAnnotations:_annotations];
-        return;
+        if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
+            [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
+            [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
+            
+        } else {
+            [self selectAnnotations:_annotations];
+            return;
+        }
     }
     
     if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){

+ 44 - 45
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/FormProperties/KMAnnotationTextWidgetOptionsViewController.swift

@@ -11,7 +11,7 @@ import Cocoa
     private var _annotations: [CPDFTextWidgetAnnotation] = []
     private var _formMode: CAnnotationType = .radioButton
     var pdfView: CPDFListView?
-    var annotationModel: CPDFAnnotationModel?
+    var _annotationModel: CPDFAnnotationModel?
 
     @IBOutlet private var textFilledAlignmentLabel: NSTextField! // 对齐方式
     @IBOutlet private var textFilledAlignmentPopUpBtn: KMPopUpButton!
@@ -83,8 +83,9 @@ import Cocoa
     }
     
     private func updateAnnotation() {
-        if annotationModel?.annotation != nil {
+        if annotationModel.annotation != nil {
             for tAnnotation in annotations {
+                tAnnotation.updateAppearanceStream()
                 pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
             }
         }
@@ -100,23 +101,6 @@ import Cocoa
             _formMode = newValue
             
             isFromMode = true
-            let defaults = UserDefaults.standard
-            var annotation: CPDFTextWidgetAnnotation? = nil
-            let bounds = NSMakeRect(0, 0, 60, 25)
-            
-            if formMode == .textField {
-                annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: pdfView!.document!)
-                annotation?.alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
-                annotation?.stringValue = defaults.string(forKey: SKAnnotationTextStringValueKey) ?? ""
-                
-                annotation?.isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
-            }
-            
-            if let annotation = annotation {
-                annotations = [annotation]
-            }
-            
-            self.annotation = annotation
         }
     }
 
@@ -129,6 +113,21 @@ import Cocoa
             annotation = _annotations.first
         }
     }
+    
+    var annotationModel: CPDFAnnotationModel {
+        get {
+            return _annotationModel!
+        }
+        set {
+            _annotationModel = newValue
+            formMode = _annotationModel?.annotationType ?? .textField
+            if _annotationModel?.annotations != nil {
+                if annotationModel.annotations.count > 0 {
+                    annotations = annotationModel.annotations as! [CPDFTextWidgetAnnotation]
+                }
+            }
+        }
+    }
 
     func updateAnnotationMode() {
         let sud = UserDefaults.standard
@@ -158,18 +157,18 @@ import Cocoa
     
     @IBAction func textFilledAlignmentAction(_ sender: NSPopUpButton) {
         for tAnnotation in annotations {
-            var annotationString = ""
-            if tAnnotation.stringValue.isEmpty {
-                annotationString = " "
-            } else {
-                let lastString = String(tAnnotation.stringValue.suffix(1))
-                
-                if lastString == " " {
-                    annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
-                } else {
-                    annotationString = "\(tAnnotation.stringValue) "
-                }
-            }
+//            var annotationString = ""
+//            if tAnnotation.stringValue.isEmpty {
+//                annotationString = " "
+//            } else {
+//                let lastString = String(tAnnotation.stringValue.suffix(1))
+//                
+//                if lastString == " " {
+//                    annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
+//                } else {
+//                    annotationString = "\(tAnnotation.stringValue) "
+//                }
+//            }
             
             switch sender.indexOfSelectedItem {
             case 0:
@@ -182,7 +181,7 @@ import Cocoa
                 break
             }
             
-            tAnnotation.stringValue = annotationString
+//            tAnnotation.stringValue = annotationString
         }
         
         updateAnnotation()
@@ -190,24 +189,24 @@ import Cocoa
     
     @IBAction func textFilledAllowNewLineAction(_ sender: NSButton) {
         for tAnnotation in annotations {
-            var annotationString = ""
-            
-            if tAnnotation.stringValue.isEmpty {
-                annotationString = " "
-            } else {
-                let lastString = String(tAnnotation.stringValue.suffix(1))
-                if lastString == " " {
-                    annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
-                } else {
-                    annotationString = "\(tAnnotation.stringValue) "
-                }
-            }
+//            var annotationString = ""
+//            
+//            if tAnnotation.stringValue.isEmpty {
+//                annotationString = " "
+//            } else {
+//                let lastString = String(tAnnotation.stringValue.suffix(1))
+//                if lastString == " " {
+//                    annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
+//                } else {
+//                    annotationString = "\(tAnnotation.stringValue) "
+//                }
+//            }
             
             if let textWidgetAnnotation = tAnnotation as? CPDFTextWidgetAnnotation {
                 textWidgetAnnotation.isMultiline = (sender.state == .on)
             }
             
-            tAnnotation.stringValue = annotationString
+//            tAnnotation.stringValue = annotationString
         }
         
         updateAnnotation()

+ 19 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/KMRightSideViewController.swift

@@ -53,7 +53,7 @@ class KMRightSideViewController: NSViewController,CipherTextViewDelegate {
     
     public func reloadDataWithPDFView(pdfView:CPDFListView,isShow:Bool) {
         if self.annotationProperties == nil {
-          self.subViewType = .AnnotationProperts
+            self.subViewType = .AnnotationProperts
         }
         if(!isShow) {
             self.isHidden = true
@@ -68,6 +68,24 @@ class KMRightSideViewController: NSViewController,CipherTextViewDelegate {
                 activeAnnotations.append(annotation as! CPDFAnnotation)
             }
         }
+        var isSameAnnotation: Bool = true
+        for tAnnotation in activeAnnotations {
+            if tAnnotation.className != selectedAnnotation?.className {
+                isSameAnnotation = false
+                break
+            }
+        }
+        if !isSameAnnotation {
+            self.annotationProperties.annotations = []
+            self.annotationProperties.isEmptyAnnotation = true
+            return
+        } else if selectedAnnotation is CPDFTextWidgetAnnotation || selectedAnnotation is CPDFChoiceWidgetAnnotation || selectedAnnotation is CPDFButtonWidgetAnnotation {
+            if pdfView.toolMode != .formToolMode {
+                self.annotationProperties.annotations = []
+                self.annotationProperties.isEmptyAnnotation = true
+                return
+            }
+        }
        
         let annotationType = pdfView.annotationType
         if KMAnnotationPropertiesViewController.height(with: selectedAnnotation) > 0 {