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

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

niehaoyu 2 месяцев назад
Родитель
Сommit
7c1920722f

+ 8 - 4
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotation+PDFListView.swift

@@ -77,10 +77,14 @@ extension CAnnotationType {
                 context.stroke(KMRectInset(NSRectToCGRect(rect), 0,0), width: lineWidth)
             }
         } else {
-            context.setLineWidth(lineWidth)
-            CPDFListViewDrawLineHandles(context, rect, 4.0/2)
-            // 绘制路径
-            context.strokePath()
+            if self.isResizable() {
+                context.setLineWidth(lineWidth)
+                CPDFListViewDrawLineHandles(context, rect, 4.0/2)
+                // 绘制路径
+                context.strokePath()
+            } else {
+                KMContextStrokeRect(context, KMRectInset(NSRectToCGRect(rect), lineWidth, lineWidth))
+            }
         }
         context.restoreGState()
         context.saveGState()

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFWidgetAnnotation+PDFListView.swift

@@ -33,7 +33,7 @@ enum CPDFWidgetShowState: Int, CaseIterable {
         if(isHover || pdfView.activeAnnotations.count > 1) {
             let offsetNum = CPDFListViewConfig.defaultManager.annotationBorderOffset
             rect = NSRectFromCGRect(KMRectInset(NSRectToCGRect(rect), -(offsetNum.floatValue).cgFloat, -(offsetNum.floatValue).cgFloat))
-            let length: [CGFloat] = [5,5]
+            let length: [CGFloat] = [2,2]
             KMContextSetLineDash(context, 0, length, 2)
             KMContextStrokeRectWithWidth(context, KMRectInset(NSRectToCGRect(rect), 0,0), lineWidth)
         } else {

+ 6 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Event.m

@@ -562,7 +562,12 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
         }
         
         //显示虚线
-        if((clickNewActiveAnnotation &&
+        if(clickNewActiveAnnotation && [clickNewActiveAnnotation isKindOfClass:[CPDFWidgetAnnotation class]]) {//form注释不显示虚线框
+            if (self.hoverAnnotation) {
+                self.hoverAnnotation = nil;
+                [self setNeedsDisplayAnnotationViewForPage:page];
+            }
+        } else if((clickNewActiveAnnotation &&
             (![self.activeAnnotations containsObject:clickNewActiveAnnotation] || [clickNewActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]]))) {
             self.hoverAnnotation = newActiveAnnotation;
             [self setNeedsDisplayAnnotationViewForPage:page];

+ 12 - 12
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Tool.m

@@ -154,7 +154,6 @@
     CPDFAreaOfInterest area = [self areaOfInterestForPoint:point];
     [self setCursorForAreaOfInterest:area];
     
-//    CPDFAreaOfInterest area = [super areaOfInterestForMouse:theEvent];
     NSPoint p = [theEvent locationInWindow];
     NSInteger modifiers = [theEvent standardPDFListViewModifierFlags];
     
@@ -168,27 +167,27 @@
         if ((area & CPDFPageArea) == 0 || CMoveToolMode == self.toolMode) {
             if ((area & CReadingBarArea) == 0)
                 area |= CDragArea;
-        } else if (CTextToolMode == self.toolMode || CNoteToolMode == self.toolMode || CFormToolMode == self.toolMode) {
+        } else if (CTextToolMode == self.toolMode ||
+                   CNoteToolMode == self.toolMode ||
+                   CFormToolMode == self.toolMode ||
+                   CEditLinkToolMode == self.toolMode) {
             if (CNoteToolMode == self.toolMode)
                 area &= ~CPDFLinkArea;
             
-            NSRect rect = CPDFListViewRectFromCenterAndSize(p, CGSizeMake(80, 100));
-            CPDFSelection *sel = [page selectionForRect:rect];
-            if ([self isEditWithCurrentFreeText:self.activeAnnotation] && [[self.activeAnnotation page] isEqual:page] && NSPointInRect(p, [self.activeAnnotation bounds])) {
+            NSRect rect = CPDFListViewRectFromCenterAndSize(p, CGSizeMake(10, 10));
+            if ([self isEditWithCurrentFreeText:self.activeAnnotation] &&
+                [[self.activeAnnotation page] isEqual:page] &&
+                NSPointInRect(p, [self.activeAnnotation bounds])) {
                 area = CPDFTextFieldArea;
             } else if ((area & CReadingBarArea) == 0) {
-                if ([[self.activeAnnotation page] isEqual:page] && [self.activeAnnotation isMovable] &&
+                if ([[self.activeAnnotation page] isEqual:page] &&
+                    [self.activeAnnotation isMovable] &&
                     ((resizeHandle = [self.activeAnnotation resizeHandleForPoint:p scaleFactor:[self scaleFactor]]) || [self.activeAnnotation hitTest:p]))
                     if ([self.activeAnnotation isKindOfClass:[KMTableAnnotation class]]  ) {
                         area |= CTableAreaOfInterestForResizeHandle(resizeHandle, page);
                     } else {
                         area |= CAreaOfInterestForResizeHandle(resizeHandle, page);
                     }
-                else if ((CTextToolMode == self.toolMode || self.hideNotes || [CPDFListView isMarkupAnnotationType:self.annotationType]) &&
-                         area == CPDFPageArea &&
-                         modifiers == 0 &&
-                         ![page selectionForRect:CPDFListViewRectFromCenterAndSize(p, CGSizeMake(80, 100))])
-                    area |= CDragArea;
             }
         } else {
             area = CPDFPageArea;
@@ -274,7 +273,8 @@
         CTextToolMode == self.toolMode ||
         CFormToolMode == self.toolMode ||
         CRedactToolMode == self.toolMode ||
-        CRedactErasureToolMode == self.toolMode) {
+        CRedactErasureToolMode == self.toolMode ||
+        CEditLinkToolMode == self.toolMode) {
         if (self.annotationType == CAnnotationTypeInk || self.annotationType == CAnnotationTypeEraser) {
             return NO;
         }

+ 31 - 13
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -1496,26 +1496,44 @@ void CPDFListViewOCDrawLineHandles(CGContextRef context, CGRect rect, CGFloat ra
 }
 
 - (BOOL)consistentTypeWithAnnotation:(CPDFAnnotation *)annotation {
-    if([CPDFListView isMarkupAnnotationType:self.annotationType]) {
-        if (![annotation isKindOfClass:[CPDFMarkupAnnotation class]])
+    if(CFormToolMode == self.toolMode) {
+        if (![annotation isKindOfClass:[CPDFWidgetAnnotation class]])
             return NO;
-    } else if (CAnnotationTypeLink == self.annotationType) {
-        if (![annotation isKindOfClass:[CPDFLinkAnnotation class]])
+    } else if(CRedactToolMode == self.toolMode) {
+        if(![annotation isKindOfClass:[CPDFRedactAnnotation class]])
             return NO;
-    } else  {
-        if(CFormToolMode == self.toolMode) {
-            if (![annotation isKindOfClass:[CPDFWidgetAnnotation class]])
+    } else if (CNoteToolMode == self.toolMode) {
+        if([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
+            if(![CPDFListView isMarkupAnnotationType:self.annotationType]) {
                 return NO;
-        } else if(CRedactToolMode == self.toolMode) {
-            if(![annotation isKindOfClass:[CPDFRedactAnnotation class]])
+            }
+        } else if([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+            return NO;
+        } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+            return NO;
+        } else {
+            if([CPDFListView isMarkupAnnotationType:self.annotationType]) {
                 return NO;
+            }
         }
-        if ([annotation isForm]) {
-            if (self.toolMode != CFormToolMode)
-                return NO;
+    } else if (CEditLinkToolMode == self.toolMode) {
+        if(![annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+            return NO;
         }
-
+    } else if (CMoveToolMode == self.toolMode ||
+               CMagnifyToolMode == self.toolMode ||
+               CSelectToolMode == self.toolMode ||
+               CSelectZoomToolMode == self.toolMode ||
+               CEditPDFToolMode == self.toolMode ||
+               CRedactErasureToolMode == self.toolMode ||
+               CDigitalSignToolMode == self.toolMode ||
+               COCRToolMode == self.toolMode ||
+               CCropToolMode == self.toolMode) {
+        return NO;
+    } else if (CTextToolMode == self.toolMode) {
+        return YES;
     }
+    
     return YES;
 }
 

+ 71 - 39
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -97,6 +97,9 @@ struct KMNMWCFlags {
     //春季活动
     var recommondPopWindowVC: KMRecommondPopWindow?
     
+    //数字签名状态
+    var signaturestateVC: CDSignatureCertificateStateViewController = CDSignatureCertificateStateViewController.init()
+
     //MARK: - 旧代码,有需要用到的拿出来,写好备注
     
     @IBOutlet weak var leftView: NSView!
@@ -1306,6 +1309,30 @@ struct KMNMWCFlags {
         }
     }
     
+    func popUpSignatureWidgetState(_ signature: CPDFSignature, _ pdfListView: CPDFListView) ->(){
+        signaturestateVC.signature = signature
+        signaturestateVC.pdfListView = pdfListView
+        signaturestateVC.actionBlock = { [weak self, weak signaturestateVC] stateVCSelf, actionType in
+            guard let weakSelf = self, let stateVC = signaturestateVC else { return }
+            if actionType == .cancel {
+                stateVC.dismiss(stateVCSelf)
+            } else if actionType == .confirm {
+                if let signer = signature.signers.first, let data = signer.certificates {
+                    let signatureDetail = DSignatureDetailsViewController.init()
+                    signatureDetail.certificates = data
+                    signatureDetail.signature = signature
+                    signatureDetail.pdfListView = pdfListView
+                    stateVCSelf.presentAsSheet(signatureDetail)
+                } else {
+                    NSSound.beep()
+                }
+            }
+        }
+        self.presentAsSheet(signaturestateVC)
+        signaturestateVC.reloadData()
+    }
+
+    
     // MARK: - 显示合并窗口
     public func showMergeWindow(url: URL? = nil, _ password: String?) {
         DispatchQueue.main.async {
@@ -3966,52 +3993,57 @@ extension KMMainViewController: CPDFViewDelegate,CPDFListViewDelegate {
     func pdfListViewEditAnnotation(_ pdfListView: CPDFListView!, for anotation: CPDFAnnotation!) {
         if anotation.isKind(of: CPDFSignatureWidgetAnnotation.self) {
             if let signatureWidgetAnnotation = anotation as? CPDFSignatureWidgetAnnotation {
-                
-                let widget = CPDFSignatureWidgetAnnotation.init(PDFListViewNoteWith: listView.document)
-                widget.bounds = NSMakeRect(-1000, -1000, 545, 178);
-                anotation.page.addAnnotation(widget)
-                
-                let configWindowVC = DSignatureConfigWindowController.init(windowNibName: "DSignatureConfigWindowController")
-                configWindowVC.viewType = .fileList;
-                configWindowVC.appearanceWidget = widget;
-                configWindowVC.isCreatDS = false
-                configWindowVC.complentionHandle = {[weak self] isSign, dic, config, isLock in
-                    widget.page.removeAnnotation(widget)
-                    if isSign {
-                        if (dic.object(forKey: SAVEFILEPATH_KEY) != nil) {
-                            let p12Path = dic.object(forKey: SAVEFILEPATH_KEY) as! String
-                            let password = dic.object(forKey: PASSWORD_KEY)
-                            if p12Path.count > 0 {
-                                self?.writeSignatureToWidget(signatureWidgetAnnotation, p12Path, password as! String, config, isLock)
+                let signature = signatureWidgetAnnotation.signature()
+                if ((signature) != nil) {
+                    popUpSignatureWidgetState(signature!, listView)
+                } else {
+                    let widget = CPDFSignatureWidgetAnnotation.init(PDFListViewNoteWith: listView.document)
+                    widget.bounds = NSMakeRect(-1000, -1000, 545, 178);
+                    anotation.page.addAnnotation(widget)
+                    
+                    let configWindowVC = DSignatureConfigWindowController.init(windowNibName: "DSignatureConfigWindowController")
+                    configWindowVC.viewType = .fileList;
+                    configWindowVC.appearanceWidget = widget;
+                    configWindowVC.isCreatDS = false
+                    configWindowVC.complentionHandle = {[weak self] isSign, dic, config, isLock in
+                        widget.page.removeAnnotation(widget)
+                        if isSign {
+                            if (dic.object(forKey: SAVEFILEPATH_KEY) != nil) {
+                                let p12Path = dic.object(forKey: SAVEFILEPATH_KEY) as! String
+                                let password = dic.object(forKey: PASSWORD_KEY)
+                                if p12Path.count > 0 {
+                                    self?.writeSignatureToWidget(signatureWidgetAnnotation, p12Path, password as! String, config, isLock)
+                                }
+                            }
+                        } else {
+                            if signatureWidgetAnnotation.isSignSignatureAdd() == true {
+                                self?.listView.remove(anotation)
                             }
-                        }
-                    } else {
-                        if signatureWidgetAnnotation.isSignSignatureAdd() == true {
-                            self?.listView.remove(anotation)
                         }
                     }
-                }
-                configWindowVC.actionBlock = {[weak self] controller, type in
-                    if (type == .cancel) {
-                        NSApplication.shared.stopModal()
-                        controller.window?.orderOut(nil)
-                        controller.window?.close()
-                        widget.page.removeAnnotation(widget)
-
-                        if signatureWidgetAnnotation.isSignSignatureAdd() == true {
-                            self?.listView.remove(anotation)
-                        } else {
-                            self?.listView.setNeedsDisplayAnnotationViewFor(anotation.page)
+                    configWindowVC.actionBlock = {[weak self] controller, type in
+                        if (type == .cancel) {
+                            NSApplication.shared.stopModal()
+                            controller.window?.orderOut(nil)
+                            controller.window?.close()
+                            widget.page.removeAnnotation(widget)
+                            
+                            if signatureWidgetAnnotation.isSignSignatureAdd() == true {
+                                self?.listView.remove(anotation)
+                            } else {
+                                self?.listView.setNeedsDisplayAnnotationViewFor(anotation.page)
+                            }
+                        } else if (type == .confirm) {
+                            NSApplication.shared.stopModal()
+                            controller.window?.orderOut(nil)
+                            controller.window?.close()
                         }
-                    } else if (type == .confirm) {
-                        NSApplication.shared.stopModal()
-                        controller.window?.orderOut(nil)
-                        controller.window?.close()
                     }
+                    configWindowVC.window?.center()
+                    NSApplication.shared.runModal(for: configWindowVC.window!)
                 }
-                configWindowVC.window?.center()
-                NSApplication.shared.runModal(for: configWindowVC.window!)
             }
+                
         } else if anotation.isKind(of: CPDFRedactAnnotation.self) {
             if let redactAnnotation = anotation as? CPDFRedactAnnotation {
                 let properties = KMRedactPropertiesWindowController()