Browse Source

【综合】功能流程自测试

niehaoyu 8 months ago
parent
commit
f4a457c856

+ 18 - 2
PDF Office/PDF Master/Class/PDFTools/CustomStamp/CustomStampWindowController.swift

@@ -100,16 +100,19 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
         self.leftToolbar = CustomStampLeftToolbar.createFromNib()
         self.leftToolbar.frame = self.leftContendView.bounds
         self.leftToolbar.autoresizingMask = [.width, .height]
-        self.leftToolbar.clickHandle = {[weak self] view , toolbarType in
+        self.leftToolbar.clickHandle = {[weak self] view , toolbarType, string in
             
             self?.pdfView.customStampAnnotationType = String(toolbarType.rawValue)
             if toolbarType == .move {
-                
+                self?.pdfView.annotationType = .unkown
             }else if toolbarType == .text ||
                 toolbarType == .dateText ||
                 toolbarType == .idText {
                 self?.pdfView.toolMode = .noteToolMode
                 self?.pdfView.annotationType = .freeText
+                if string.isEmpty == false {
+                    self?.pdfView.customStampTextValue = string
+                }
             } else if toolbarType == .image {
                 self?.pdfView.annotationType = .addImage
                 self?.chooseImage()
@@ -162,6 +165,9 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
                 self.pdfView.addAnnotation(with: image, isRemoveBGColor: isRemoveBGColor)
                 
                 self.updateRightToolBarInfo()
+            } else {
+                self.leftToolbar.toolbarType = .move
+                self.leftToolbar.reloadData()
             }
         }
     }
@@ -179,6 +185,8 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
                 
             }
             self?.window?.endSheet(view.window!)
+            self?.leftToolbar.toolbarType = .move
+            self?.leftToolbar.reloadData()
         }
         
         self.window!.beginSheet(self.stampListWC.window!, completionHandler: {[weak self] response in
@@ -253,6 +261,14 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
         }
     }
     
+    func pdfListViewAddAnnotations(_ pdfListView: CPDFListView!, forAdd annotations: [CPDFAnnotation]!, in pdfPage: CPDFPage!) {
+        if self.leftToolbar.toolbarType != .move {
+            self.leftToolbar.toolbarType = .move
+            self.leftToolbar.reloadData()
+        }
+        
+    }
+    
     //MARK:
 }
 

+ 23 - 0
PDF Office/PDF Master/Class/PDFTools/CustomStamp/Extension/CPDFFreeTextAnnotation+CustomStamp.swift

@@ -0,0 +1,23 @@
+//
+//  CPDFFreeTextAnnotation+CustomStamp.swift
+//  PDF Reader Pro
+//
+//  Created by Niehaoyu on 2024/7/1.
+//
+
+import Foundation
+
+@objc extension CPDFFreeTextAnnotation {
+    
+    
+    @objc static var _customStampAnnotationType = "customStampAnnotationType"
+    @objc var customStampAnnotationType: String {
+        get {
+            return objc_getAssociatedObject(self, &Self._customStampAnnotationType) as? String ?? "0"
+        }
+        set {
+            objc_setAssociatedObject(self, &Self._customStampAnnotationType, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+        }
+    }
+    
+}

+ 10 - 0
PDF Office/PDF Master/Class/PDFTools/CustomStamp/Extension/CPDFListView+CustomStamp.swift

@@ -28,4 +28,14 @@ import Foundation
             objc_setAssociatedObject(self, &Self._customStampAnnotationType, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
         }
     }
+    
+    @objc static var _customStampTextValue = "customStampTextValue"
+    @objc var customStampTextValue: String {
+        get {
+            return objc_getAssociatedObject(self, &Self._customStampTextValue) as? String ?? "0"
+        }
+        set {
+            objc_setAssociatedObject(self, &Self._customStampTextValue, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+        }
+    }
 }

+ 82 - 25
PDF Office/PDF Master/Class/PDFTools/CustomStamp/Views/CustomStampLeftToolbar.swift

@@ -28,9 +28,10 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
     @IBOutlet var stampBox: NSBox!
     @IBOutlet var stampButton: KMButton!
     
+    var originalType: CSToolbarType = .none
     var toolbarType: CSToolbarType = .move
     
-    var clickHandle: ((_ view: CustomStampLeftToolbar, _ actionType: CSToolbarType)->Void)?
+    var clickHandle: ((_ view: CustomStampLeftToolbar, _ actionType: CSToolbarType, _ string: String)->Void)?
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
@@ -70,16 +71,6 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
         self.dateBox?.menu = dateMenu
         
         
-        var idNames = ["名称", "登录名", "电子邮件", "组织名称"]
-        let idMenu = NSMenu.init()
-        for idx in 0...idNames.count-1 {
-            let string = idNames[idx]
-            let menuItem = NSMenuItem.init(title: string, action: #selector(menuItemClick(_:)), keyEquivalent: "")
-            menuItem.tag = 1000 + idx
-            menuItem.target = self
-            idMenu.addItem(menuItem)
-        }
-        self.peopleBox?.menu = idMenu
         
         
     }
@@ -109,45 +100,103 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
     //MARK: IBAction
     @IBAction func buttonAction(_ sender: NSButton) {
         
-        let originalType = self.toolbarType
+        originalType = self.toolbarType
         
         if sender == self.arrowBtn {
             self.toolbarType = .move
+            
+            self.reloadData()
+            
+            guard let callBack = self.clickHandle else {
+                return
+            }
+            callBack(self, self.toolbarType, "")
+            
         } else if sender == self.textButton {
             self.toolbarType = .text
-        } else if sender == self.dateButton {
-            self.toolbarType = .dateText
             
+            self.reloadData()
+            
+            guard let callBack = self.clickHandle else {
+                return
+            }
+            callBack(self, self.toolbarType, "")
+            
+        } else if sender == self.dateButton {
             let menu = self.dateBox?.menu
             menu?.popUp(positioning: menu?.item(at: 0), at: CGPoint(x: 0, y: 15), in: sender)
             
         } else if sender == self.peopleButton {
-            self.toolbarType = .idText
             
+            
+            var idNames = ["名称", "登录名", "电子邮件", "组织名称"]
+            let idMenu = NSMenu.init()
+            for idx in 0...idNames.count-1 {
+                let string = idNames[idx]
+                let menuItem = NSMenuItem.init(title: string, action: #selector(idMenuItemClick(_:)), keyEquivalent: "")
+                menuItem.tag = 1000 + idx
+                 
+                if idx == 0 {
+                    if KMProfileInfo.shared().fullName.isEmpty == false {
+                        menuItem.target = self
+                    }
+                } else if idx == 1 {
+                    if NSFullUserName().isEmpty == false {
+                        menuItem.target = self
+                    }
+                } else if idx == 2 {
+                    if KMProfileInfo.shared().email.isEmpty == false {
+                        menuItem.target = self
+                    }
+                } else if idx == 3 {
+                    if KMProfileInfo.shared().OrganizeName.isEmpty == false {
+                        menuItem.target = self
+                    }
+                }
+                idMenu.addItem(menuItem)
+            }
+            self.peopleBox?.menu = idMenu
             let menu = self.peopleBox?.menu
             menu?.popUp(positioning: menu?.item(at: 0), at: CGPoint(x: 0, y: 15), in: sender)
             
         } else if sender == self.imageButton {
             self.toolbarType = .image
+            self.reloadData()
+            guard let callBack = self.clickHandle else {
+                return
+            }
+            callBack(self, self.toolbarType, "")
             
         } else if sender == self.stampButton {
             self.toolbarType = .stamp
-             
+            self.reloadData()
+            guard let callBack = self.clickHandle else {
+                return
+            }
+            callBack(self, self.toolbarType, "")
+        }
+        
+    }
+    
+    @objc func idMenuItemClick(_ item: NSMenuItem) {
+        var string = item.title
+        if item.tag == 1000 {
+            string = KMProfileInfo.shared().fullName
+        } else if item.tag == 1001 {
+            string = NSFullUserName()
+        } else if item.tag == 1002 {
+            string = KMProfileInfo.shared().email
+        } else if item.tag == 1003 {
+            string = KMProfileInfo.shared().OrganizeName
         }
+        
+        self.toolbarType = .idText
         self.reloadData()
         
         guard let callBack = self.clickHandle else {
             return
         }
-        callBack(self, self.toolbarType)
-        
-        
-        
-    }
-    
-    @objc func menuItemClick(_ item: NSMenuItem) {
-        let string = item.title
-        
+        callBack(self, self.toolbarType, string)
     }
     
     @objc func dateMenuItemClick(_ item: NSMenuItem) {
@@ -160,6 +209,14 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
 
         let dateString = dateFormatter.string(from: date)
         print(dateString)
+        
+        self.toolbarType = .dateText
+        self.reloadData()
+        
+        guard let callBack = self.clickHandle else {
+            return
+        }
+        callBack(self, self.toolbarType, dateString)
     }
     
 }

+ 2 - 1
PDF Office/PDF Master/Class/PDFTools/CustomStamp/Views/RightView/CSStampListView/CSStampListWindowController.swift

@@ -94,7 +94,8 @@ class CSStampListWindowController: NSWindowController {
         var filePath = ""
         if self.collectionView.selectionIndexes.count > 0 {
             let index = self.collectionView.selectionIndexes.first
-            filePath = self.imagePaths[index!]
+            let string = self.imagePaths[index!]
+            filePath = Bundle.main.path(forResource: string, ofType: "pdf")!
         }
         
         

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/CustomStamp/Views/RightView/Views/CSTextPropertyView.xib

@@ -194,7 +194,7 @@
                                             <segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="qjX-0f-9ZR">
                                                 <font key="font" metaFont="system"/>
                                                 <segments>
-                                                    <segment alignment="left" image="csAlignmentLeft" width="40"/>
+                                                    <segment image="csAlignmentLeft" width="40"/>
                                                     <segment image="csAlignmentCenter" width="40" tag="1"/>
                                                     <segment image="csAlignmentRight" width="40" tag="2">
                                                         <nil key="label"/>

+ 3 - 6
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -1068,12 +1068,9 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
     if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
         
         BOOL continueEdit = YES;
-        CSToolbarType toolbarType = (CSToolbarType)[self.customStampAnnotationType intValue];
-        if (toolbarType == CSToolbarTypeText) {
-            
-        } else if (toolbarType == CSToolbarTypeDateText) {
-            continueEdit = NO;
-        } else if (toolbarType == CSToolbarTypeIdText) {
+        
+        if ([((CPDFFreeTextAnnotation *)annotation).customStampAnnotationType isEqualToString:@"dateText"] ||
+            [((CPDFFreeTextAnnotation *)annotation).customStampAnnotationType isEqualToString:@"idText"]) {
             continueEdit = NO;
         }
         

+ 26 - 9
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -45,15 +45,25 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     
     NSPoint point = NSZeroPoint;
     CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:NO];
+    
+    BOOL isCustomStampPDFView = NO;
+    if ([self.isCustomStampType isEqualToString: @"1"]) {
+        isCustomStampPDFView = YES;
+    }
+    
     if ([self.activeAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]] && ([theEvent clickCount] == 1)) {
         if ([self isEditWithCurrentFreeText:(CPDFFreeTextAnnotation *)self.activeAnnotation]) {
             CRectEdges resizeHandle = [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]];
-            if (CNoEdgeMask == resizeHandle) {
-                [super mouseDown:theEvent];
-                [self updateActiveAnnotations:@[]];
-                [self setNeedsDisplayAnnotationViewForVisiblePages];
-            } else {
-                [self doDragAnnotationWithEvent:theEvent forAnnotation:self.activeAnnotation];
+            if (isCustomStampPDFView == NO) {
+                if (CNoEdgeMask == resizeHandle) {
+                    [super mouseDown:theEvent];
+                    [self updateActiveAnnotations:@[]];
+                    [self setNeedsDisplayAnnotationViewForVisiblePages];
+                } else {
+                    [self doDragAnnotationWithEvent:theEvent forAnnotation:self.activeAnnotation];
+                }
+            }else {
+                self.annotationType = CAnnotationTypeUnkown;
             }
             return;
         }
@@ -227,6 +237,12 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 self.annotationType == CAnnotationTypeSignSignature) {
                 [super mouseDown:theEvent];
             }
+            if (isCustomStampPDFView) {
+                if ([((CPDFFreeTextAnnotation *)self.activeAnnotation).customStampAnnotationType isEqualToString:@"dateText"] ||
+                    [((CPDFFreeTextAnnotation *)self.activeAnnotation).customStampAnnotationType isEqualToString:@"idText"]) {
+                    self.annotationType = CAnnotationTypeUnkown;
+                }
+            }
         }
     } else if ([self isSupportSelectAnnotation] && (area & CPDFImageArea) && CAnnotationTypeUnkown == self.annotationType) {
         [self updateActiveAnnotations:@[]];
@@ -2550,8 +2566,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 if (toolbarType == CSToolbarTypeText) {
                     
                 } else if (toolbarType == CSToolbarTypeDateText) {
-                    ((CPDFFreeTextAnnotation *)annotation).contents = @"2024-12-12";
-                    
+                    ((CPDFFreeTextAnnotation *)annotation).contents = self.customStampTextValue;
+                    ((CPDFFreeTextAnnotation *)annotation).customStampAnnotationType = @"dateText";
                     originalBounds = [annotation bounds];
                     originalBounds.size.width = 500;
                     NSRect newBounds = [self getValidFreetText:annotation rect:originalBounds];
@@ -2559,7 +2575,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                     annotation.bounds = originalBounds;
                     
                 } else if (toolbarType == CSToolbarTypeIdText) {
-                    ((CPDFFreeTextAnnotation *)annotation).contents = @"Kdan Mobile";
+                    ((CPDFFreeTextAnnotation *)annotation).contents = self.customStampTextValue;
+                    ((CPDFFreeTextAnnotation *)annotation).customStampAnnotationType = @"idText";
                     
                     originalBounds = [annotation bounds];
                     originalBounds.size.width = 500;

+ 8 - 0
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -3822,6 +3822,9 @@
 		BB78EAAA2B561F9700121691 /* KMFullScreenWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB78EAA92B561F9700121691 /* KMFullScreenWindow.swift */; };
 		BB78EAAB2B561F9700121691 /* KMFullScreenWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB78EAA92B561F9700121691 /* KMFullScreenWindow.swift */; };
 		BB78EAAC2B561F9700121691 /* KMFullScreenWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB78EAA92B561F9700121691 /* KMFullScreenWindow.swift */; };
+		BB7AF7B82C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7AF7B72C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift */; };
+		BB7AF7B92C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7AF7B72C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift */; };
+		BB7AF7BA2C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7AF7B72C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift */; };
 		BB7BC4D82AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7BC4D72AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift */; };
 		BB7BC4D92AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7BC4D72AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift */; };
 		BB7BC4DA2AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7BC4D72AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift */; };
@@ -6887,6 +6890,7 @@
 		BB7648EB29ECEEF400931039 /* KMAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMAppearance.swift; sourceTree = "<group>"; };
 		BB77C85E2BD506BE0065AFF2 /* CPDFAnnotation+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFAnnotation+KMExtension.swift"; sourceTree = "<group>"; };
 		BB78EAA92B561F9700121691 /* KMFullScreenWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMFullScreenWindow.swift; sourceTree = "<group>"; };
+		BB7AF7B72C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFFreeTextAnnotation+CustomStamp.swift"; sourceTree = "<group>"; };
 		BB7BC4D72AD3D6B700D6BEE6 /* PDFListView+KMExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PDFListView+KMExtensions.swift"; sourceTree = "<group>"; };
 		BB7E59F52BBA427C0021E63D /* KMBrowserWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBrowserWindow.swift; sourceTree = "<group>"; };
 		BB7F7BF629AA469F00A3E4E7 /* KMSigntureViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMSigntureViewItem.xib; sourceTree = "<group>"; };
@@ -12622,6 +12626,7 @@
 			isa = PBXGroup;
 			children = (
 				BB8F4A732C22D8F400F972AB /* CPDFListView+CustomStamp.swift */,
+				BB7AF7B72C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift */,
 			);
 			path = Extension;
 			sourceTree = "<group>";
@@ -16103,6 +16108,7 @@
 				BB3AD6F929935483004FC1AE /* Reachability.m in Sources */,
 				AD1FE84C2BD920C300AA4A9B /* TextFieldFormatter.m in Sources */,
 				ADAFDA762AEB5FCD00F084BC /* KMHomeHistoryCollectionItem.swift in Sources */,
+				BB7AF7B82C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */,
 				BBEC00BF295C306400A26C98 /* KMBatesPropertyController.swift in Sources */,
 				BB93CDE52AE757A000B29C57 /* KMToolbarItemView.swift in Sources */,
 				BBDDC9A62C23F85B00F5941E /* CustomStampRightToolbar.swift in Sources */,
@@ -17186,6 +17192,7 @@
 				BBC3482529559506008D2CD1 /* KMBackgroundManager.swift in Sources */,
 				BB276A4C2B0375FE00AB5578 /* KMOperationQueue.swift in Sources */,
 				ADFA8F0A2B579945002595A4 /* KMSearchFindView.swift in Sources */,
+				BB7AF7B92C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */,
 				9FF0D0542B6A3EE40018A732 /* CPDFListView+Form.swift in Sources */,
 				BB1B0AFC2B4FC6E900889528 /* KMCustomColorGuideView.swift in Sources */,
 				AD867FC629DFFBC400F00440 /* KMAnnotationOutlineRowView.swift in Sources */,
@@ -18513,6 +18520,7 @@
 				BB5DF1EB2959C5CB0025CDA1 /* KMHeaderFooterPreviewController.swift in Sources */,
 				AD3AAD3A2B0B7B1900DE5FE7 /* KMCompareToolbar.swift in Sources */,
 				AD8DD2A52A9C35B2007CC9D0 /* KMThumbnailManager.swift in Sources */,
+				BB7AF7BA2C32B5B600832735 /* CPDFFreeTextAnnotation+CustomStamp.swift in Sources */,
 				BB6719FF2AD2CE1B003D44D5 /* CPDFSquareAnnotation+PDFListView.swift in Sources */,
 				BBEDC22D2B98407000970C54 /* CPDFAction+KMExtension.swift in Sources */,
 				BBDDC9AC2C23FEE300F5941E /* CustomStampRightToolbar.swift in Sources */,

+ 2 - 18
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -1047,8 +1047,8 @@
             filePath = "PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1937"
-            endingLineNumber = "1937"
+            startingLineNumber = "1953"
+            endingLineNumber = "1953"
             landmarkName = "-doResizeLinkWithEvent:fromPoint:originalBounds:page:resizeHandle:"
             landmarkType = "7">
          </BreakpointContent>
@@ -3063,22 +3063,6 @@
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "74F99267-2455-4250-BAFC-6CFE3B77F0B7"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1610"
-            endingLineNumber = "1610"
-            landmarkName = "setFontStyle(fontName:currentStyle:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent