Explorar el Código

【OCR】- 新增OCR入口

lizhe hace 1 semana
padre
commit
f14fbf78aa

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.h

@@ -71,6 +71,8 @@ typedef NS_ENUM(NSInteger, CAnnotationType) {
     CAnnotationTypeEditTextImage,
     CAnnotationTypeAddText,
     CAnnotationTypeAddImage,
+    CAnnotationTypeFileOCR,
+    CAnnotationTypeAreaOCR,
     
     CAnnotationTypeRadioButton = 100,
     CAnnotationTypeCheckBox,

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -947,6 +947,8 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
             self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
         } else if (clickChaildToolType == .merge) {
             self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
+        } else if (clickChaildToolType == .areaOCR || clickChaildToolType == .fileOCR) {
+            self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
         }
     }
     

+ 41 - 2
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -28,6 +28,7 @@ import Cocoa
     case viewSetting
     case sign
     case AITools
+    case OCR
     
     func isToolMode() -> Bool {
         return (self == .Move || self == .Magnify || self == .Select || self == .SelectZoom)
@@ -97,6 +98,8 @@ import Cocoa
     case comparison = 8010
     case aiTools = 8011
     case measure = 8012
+    case fileOCR
+    case areaOCR
 }
 
 @objc protocol KMToolbarViewControllerDelegate {
@@ -286,7 +289,17 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
     
     @objc private func OCRbtnAction1(_ item: KMToolbarClickButton) {
         FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn": "Btn_Tbr_OCR"])
-        self._itemAction(item)
+        
+        if let item: KMToolbarItemView = item.clickObject as? KMToolbarItemView {
+            var type: KMToolbarType = .fileOCR
+            if (item.btnTag == KMToolbarType.fileOCR.rawValue) {
+                type = .fileOCR
+            } else if (item.btnTag == KMToolbarType.areaOCR.rawValue) {
+                type = .areaOCR
+            }
+            self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
+            self._itemSetPromptFlag(item: item)
+        }
     }
     @objc private func OCRbtnAction2(_ item: KMToolbarClickButton) {
         FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Converter", withProperties: ["SubTbr_Btn": "Btn_SubTbr_Converter_OCR"])
@@ -926,6 +939,8 @@ extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidatio
                     KMToolbarSnapshotIdentifier /*, KMToolbarTTSIdentifier*/]
         case .sign:
             return [KMToolbarToolSignBoxIdentifier, KMSignDigitalSignToolbarItemIdentifier]
+        case .OCR:
+            return [KMToolbarToolOCRFileIdentifier, KMToolbarToolOCRAreaIdentifier]
         default:
             break
         }
@@ -1104,6 +1119,8 @@ extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidatio
                     return item!
                 } else if KMSignIdentifiers.contains(identifier) {
                     self._setupSignItem(item)
+                } else if KMOCRIdentifiers.contains(identifier) {
+                    self._setupOCRItem(item)
                 }
             }
         } else {
@@ -1395,7 +1412,8 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
             item?.selectBackgroundType = .imageBox
-            item?.btnAction = #selector(OCRbtnAction1)
+            item?.btnTag = KMToolbarViewType.OCR.rawValue
+            item?.btnAction = #selector(leftControllButtonAction)
             item?.promptIdentifier = identifier
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
@@ -2634,6 +2652,27 @@ extension KMToolbarViewController {
             item?.menuFormRepresentation = menuItem
         }
     }
+    
+    private func _setupOCRItem(_ item: KMToolbarItemView?) {
+        let identifier = item?.itemIdentifier
+        if identifier == KMToolbarToolOCRFileIdentifier {
+            item?.image = NSImage(named: "KMImageNameButtonEidtPDFText")
+            item?.target = self
+            item?.btnTag = CAnnotationType.fileOCR.rawValue
+            item?.toolTip = NSLocalizedString("File", comment: "")
+            item?.titleName = NSLocalizedString("File", comment: "")
+            item?.boxImagePosition = .imageLeft
+            item?.btnAction = #selector(OCRbtnAction1)
+        }  else if identifier == KMToolbarToolOCRAreaIdentifier {
+            item?.image = NSImage(named: "KMImageNameButtonEidtPDFImage")
+            item?.target = self
+            item?.btnTag = CAnnotationType.areaOCR.rawValue
+            item?.toolTip = NSLocalizedString("Area", comment: "")
+            item?.titleName = NSLocalizedString("Area", comment: "")
+            item?.boxImagePosition = .imageLeft
+            item?.btnAction = #selector(OCRbtnAction1)
+        }
+    }
 }
 
 extension KMToolbarViewController: NSMenuItemValidation {

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/PublicKey.swift

@@ -184,8 +184,12 @@ let fillSignToolIdentifiers = [KMToolbarToolHookItemIdentifier, KMToolbarToolFor
 
 //Scan OCR
 let KMToolbarToolOCRTextIdentifier     =  "KMToolbarToolOCRTextIdentifier"
+let KMToolbarToolOCRFileIdentifier     =  "KMToolbarToolOCRFileIdentifier"
+let KMToolbarToolOCRAreaIdentifier     =  "KMToolbarToolOCRAreaIdentifier"
 let KMToolbarToolEnhancedScanIdentifier     =  "KMToolbarToolEnhancedScanIdentifier"
 
+let KMOCRIdentifiers = [KMToolbarToolOCRFileIdentifier, KMToolbarToolOCRAreaIdentifier]
+
 let KMToolbarViewSettingIdentifier = "KMToolbarSplitScreenModeItemIdentifier"
 let KMToolbarCropIdentifier = "KMToolbarCropItemIdentifier"
 let KMToolbarSnapshotIdentifier = "KMToolbarTakeSnapshotItemIdentifier"

+ 6 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3890,6 +3890,8 @@ extension KMMainViewController : KMToolbarViewControllerDelegate {
         }else if type == .Select {
             self.rightSideViewController.isHidden = true
             self.closeRightPane()
+        } else if (type == .OCR) {
+            
         }
     }
     
@@ -4711,6 +4713,10 @@ extension KMMainViewController : KMToolbarViewControllerDelegate {
                 self.rightSideViewController.reloadDataWithPDFView(pdfView: listView, isShow: true)
                 self.openRightPane()
             }
+            
+            if (type == .areaOCR || type == .fileOCR) {
+                self.showOCRWindow()
+            }
         }
     }