瀏覽代碼

【综合】自定义图章修改添加方式

niehaoyu 8 月之前
父節點
當前提交
b3cb3a7d1f

+ 12 - 9
PDF Office/PDF Master/Class/PDFTools/CustomStamp/CustomStampWindowController.swift

@@ -129,9 +129,11 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
                     self?.pdfView.customStampTextValue = string
                 }
             } else if toolbarType == .image {
-                self?.pdfView.annotationType = .addImage
+                self?.pdfView.toolMode = .noteToolMode
+                self?.pdfView.annotationType = .stamp
                 self?.chooseImage()
             } else if toolbarType == .stamp {
+                self?.pdfView.toolMode = .noteToolMode
                 self?.chooseStamp()
             }
              
@@ -207,7 +209,7 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
         openPanel.allowsMultipleSelection = false
         openPanel.accessoryView = accessoryCtr.view
         openPanel.canSelectHiddenExtension = true
-        openPanel.beginSheetModal(for: NSApp.mainWindow!) { [weak self] (result) in
+        openPanel.beginSheetModal(for: self.window!) { [weak self] (result) in
             if result == .OK {
                 guard let url = openPanel.url else {
                     return
@@ -220,11 +222,9 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
                     }
                 }
                 
-                let image = NSImage(contentsOfFile: url.path)
-                
-                let isRemoveBGColor = accessoryCtr.selectedButton.state == .on
-                self?.pdfView.addAnnotation(with: image, isRemoveBGColor: isRemoveBGColor)
-                
+                let stamp = CStampObject(imageStampFilePath: filePath)
+                stamp.nameString = ""
+                self?.pdfView.setAddStamp(stamp, keepToolModel: true)
                 self?.updateRightToolBarInfo()
             } else {
                 self?.leftToolbar.toolbarType = .move
@@ -240,8 +240,11 @@ class CustomStampWindowController: NSWindowController, CPDFViewDelegate, CPDFLis
                 
             } else if actionType == 1 {
                 
-                self?.pdfView.annotationType = .addImage
-                self?.pdfView.addAnnotation(with: NSImage(contentsOf: URL(fileURLWithPath: filePath!)), isRemoveBGColor: false)
+                self?.pdfView.annotationType = .stamp
+                let stamp = CStampObject(imageStampFilePath: filePath!)
+                stamp.nameString = ""
+                self?.pdfView.setAddStamp(stamp, keepToolModel: true)
+                
                 self?.updateRightToolBarInfo()
                 
             }

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

@@ -21,3 +21,17 @@ import Foundation
     }
     
 }
+
+@objc extension CPDFStampAnnotation {
+    
+    @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)
+        }
+    }
+    
+}

+ 5 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -241,6 +241,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 if ([((CPDFFreeTextAnnotation *)self.activeAnnotation).customStampAnnotationType isEqualToString:@"dateText"] ||
                     [((CPDFFreeTextAnnotation *)self.activeAnnotation).customStampAnnotationType isEqualToString:@"idText"]) {
                     self.annotationType = CAnnotationTypeUnkown;
+                } else if (self.annotationType == CAnnotationTypeStamp) {
+                    self.annotationType = CAnnotationTypeUnkown;
                 }
             }
         }
@@ -2603,6 +2605,9 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
         if(annotation) {
             [annotation updateAppearanceStream];
             [(CPDFListStampAnnotation *)annotation setBorderBoundsWithStamp:self.stampObject];
+            if ([self.isCustomStampType isEqualToString: @"1"]) {
+                ((CPDFListStampAnnotation *)annotation).customStampAnnotationType = @"customStamp";
+            }
             [self addAnnotation:annotation toPage:page];
         }
 //            [self updateActiveAnnotations:@[annotation]];