Explorar o código

【2025】【OCR】区域OCR按钮逻辑补充

lizhe hai 3 meses
pai
achega
3fe78c9c76

+ 13 - 7
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -1589,21 +1589,27 @@ struct KMNMWCFlags {
             popWindow.listView = listView
             if listView.toolMode == .CSelectToolMode {
                 popWindow.popType = .crop
+                popWindow.cropCurrentCallback = {[weak self] in
+                    let rect = self?.listView.currentSelectionRect() ?? CGRect.zero
+                    let orgPage : CPDFPage = self?.listView.currentSelectionPage() ?? CPDFPage()
+                    self?.cropPages(atIndexs: [orgPage.pageIndex()], to: [rect])
+                    self?.closePopOperationWindow()
+                }
             } else if listView.toolMode == .COCRToolMode {
                 popWindow.popType = .ocr
+                popWindow.OCRAction = { [weak self] in
+//                    let rect = self?.listView.currentSelectionRect() ?? CGRect.zero
+//                    let orgPage : CPDFPage = self?.listView.currentSelectionPage() ?? CPDFPage()
+//                    self?.cropPages(atIndexs: [orgPage.pageIndex()], to: [rect])
+//                    self?.closePopOperationWindow()
+                }
             }
-            updatePopOperationPopWinodwFrame()
             popWindow.updatePDFViewCallback = {[weak self] in
                 self?.closePopOperationWindow()
                 self?.listView.setNeedsDisplayForVisiblePages()
             }
+            updatePopOperationPopWinodwFrame()
             
-            popWindow.cropCurrentCallback = {[weak self] in
-                let rect = self?.listView.currentSelectionRect() ?? CGRect.zero
-                let orgPage : CPDFPage = self?.listView.currentSelectionPage() ?? CPDFPage()
-                self?.cropPages(atIndexs: [orgPage.pageIndex()], to: [rect])
-                self?.closePopOperationWindow()
-            }
         } else {
             closePopOperationWindow()
         }

+ 8 - 0
PDF Office/PDF Master/KMClass/PDFListView/WindowController/KMNPopOperationWindowController.swift

@@ -17,6 +17,8 @@ import KMComponentLibrary
 
 typealias OperaCropCallback = () -> ()
 
+typealias KMNPopOperationWindowControllerOCRAction = () -> ()
+
 class KMNPopOperationWindowController: KMNBaseWindowController {
     
     @IBOutlet weak var contentBox: NSBox!
@@ -47,6 +49,8 @@ class KMNPopOperationWindowController: KMNBaseWindowController {
     
     var updatePDFViewCallback: UpdatePDFViewCallback?
     
+    var OCRAction: KMNPopOperationWindowControllerOCRAction?
+    
     weak var listView:CPDFListView?
     
     public var popType:OperationType = .operationNone {
@@ -203,9 +207,13 @@ class KMNPopOperationWindowController: KMNBaseWindowController {
     
     //MARK: - Action
     @objc func cancelButtonClicked(_ sender: NSView) {
+        listView?.selectionRect = NSZeroRect
+        listView?.selectionPageIndex = UInt(NSNotFound)
+        updatePDFViewCallback?()
     }
     
     @objc func ocrButtonClicked(_ sender: NSView) {
+        OCRAction?()
     }
     
     @objc func addButtonClicked(_ sender: NSView) {