|
@@ -1797,10 +1797,7 @@ struct KMNMWCFlags {
|
|
|
} 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()
|
|
|
+ self?.convertSelectionRectOCR(rect: self?.listView.currentSelectionRect() ?? CGRectZero)
|
|
|
}
|
|
|
}
|
|
|
popWindow.updatePDFViewCallback = {[weak self] in
|
|
@@ -2981,6 +2978,52 @@ struct KMNMWCFlags {
|
|
|
self.view.window?.addChildWindow(winC.window!, ordered: .above)
|
|
|
}
|
|
|
|
|
|
+ // MARK: -显示加密弹窗
|
|
|
+
|
|
|
+
|
|
|
+ //MARK: - Redact密文
|
|
|
+ func showRedactProperty(readactAnnotation: CPDFRedactAnnotation?) {
|
|
|
+ let properties = KMRedactPropertiesWindowController()
|
|
|
+ properties.readactAnnotation = readactAnnotation
|
|
|
+ self.km_beginSheet(windowC: properties)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: - 测量
|
|
|
+ func refreshMeasureInfo() {
|
|
|
+ if let annotation = listView.activeAnnotation {
|
|
|
+ if (listView.activeAnnotation.isKind(of: CPDFLineAnnotation.self)) {
|
|
|
+ if (!(listView.activeAnnotation as! CPDFLineAnnotation).isMeasure) {
|
|
|
+ cancelMeasureType()
|
|
|
+ } else {
|
|
|
+ if distanceMeasureInfoWindowController == nil {
|
|
|
+ let measureInfo = CPDFDistanceMeasureInfo()
|
|
|
+ distanceMeasureInfoWindowController = CDistanceMeasureInfoWindowController()
|
|
|
+ distanceMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
+ distanceMeasureInfoWindowController?.delegate = self
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (!listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) && !listView.activeAnnotation.isKind(of: CPDFPolylineAnnotation.self)) {
|
|
|
+ cancelMeasureType()
|
|
|
+ } else if (listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) || listView.activeAnnotation.isKind(of: CPDFPolylineAnnotation.self)) {
|
|
|
+ if perimeterMeasureInfoWindowController == nil {
|
|
|
+ let measureInfo = CPDFPerimeterMeasureInfo()
|
|
|
+ perimeterMeasureInfoWindowController = CPerimeterMeasureInfoWindowController()
|
|
|
+ perimeterMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
+ perimeterMeasureInfoWindowController?.delegate = self
|
|
|
+ }
|
|
|
+ if areaMeasureInfoWindowController == nil {
|
|
|
+ let measureInfo = CPDFAreaMeasureInfo()
|
|
|
+ areaMeasureInfoWindowController = CAreaMeasureInfoWindowController()
|
|
|
+ areaMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
+ areaMeasureInfoWindowController?.delegate = self
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cancelMeasureType()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//MARK: Compress
|
|
@@ -3028,6 +3071,7 @@ extension KMMainViewController {
|
|
|
|
|
|
//MARK: - OCR
|
|
|
extension KMMainViewController {
|
|
|
+ //window
|
|
|
func showOCRWindow() {
|
|
|
if !IAPProductsManager.default().isAvailableAllFunction(){
|
|
|
let winC = KMPurchaseCompareWindowController.sharedInstance()
|
|
@@ -3097,7 +3141,7 @@ extension KMMainViewController {
|
|
|
|
|
|
KMOCRManager.manager.convertScanFile(document: document, model: model, progress: { progress in
|
|
|
|
|
|
- }) { [weak self] document, error in
|
|
|
+ }) { [weak self] document, text, error in
|
|
|
window.endLoading()
|
|
|
window.km_quick_endSheet()
|
|
|
if !model.saveAsPDF {
|
|
@@ -3116,7 +3160,7 @@ extension KMMainViewController {
|
|
|
|
|
|
KMOCRManager.manager.convertOCR(document: document, model: model, progress: { progress in
|
|
|
|
|
|
- }) { [weak self] document, error in
|
|
|
+ }) { [weak self] document, text, error in
|
|
|
// self?.view.window?.windowController.endLoading()
|
|
|
// window.km_quick_endSheet()
|
|
|
if !model.saveAsPDF {
|
|
@@ -3124,53 +3168,44 @@ extension KMMainViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // MARK: -显示加密弹窗
|
|
|
-
|
|
|
|
|
|
- //MARK: - Redact密文
|
|
|
- func showRedactProperty(readactAnnotation: CPDFRedactAnnotation?) {
|
|
|
- let properties = KMRedactPropertiesWindowController()
|
|
|
- properties.readactAnnotation = readactAnnotation
|
|
|
- self.km_beginSheet(windowC: properties)
|
|
|
-
|
|
|
+ func convertOCRSaveAsTXT(text: String) {
|
|
|
+ NSPanel.savePanel(NSWindow.currentWindow()) { panel in
|
|
|
+ let url: URL = self.listView.document.documentURL
|
|
|
+ panel.nameFieldStringValue = ""+url.deletingPathExtension().lastPathComponent+"_OCR"
|
|
|
+ panel.allowedFileTypes = ["txt"]
|
|
|
+ } completion: { [unowned self] response, url in
|
|
|
+ if (response == .cancel) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let saveAsPDFFilePath = url?.path ?? ""
|
|
|
+ let outputURL = URL(fileURLWithPath: saveAsPDFFilePath)
|
|
|
+ try? text.write(to: outputURL, atomically: true, encoding: .utf8)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //MARK: - 测量
|
|
|
- func refreshMeasureInfo() {
|
|
|
- if let annotation = listView.activeAnnotation {
|
|
|
- if (listView.activeAnnotation.isKind(of: CPDFLineAnnotation.self)) {
|
|
|
- if (!(listView.activeAnnotation as! CPDFLineAnnotation).isMeasure) {
|
|
|
- cancelMeasureType()
|
|
|
- } else {
|
|
|
- if distanceMeasureInfoWindowController == nil {
|
|
|
- let measureInfo = CPDFDistanceMeasureInfo()
|
|
|
- distanceMeasureInfoWindowController = CDistanceMeasureInfoWindowController()
|
|
|
- distanceMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
- distanceMeasureInfoWindowController?.delegate = self
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (!listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) && !listView.activeAnnotation.isKind(of: CPDFPolylineAnnotation.self)) {
|
|
|
- cancelMeasureType()
|
|
|
- } else if (listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) || listView.activeAnnotation.isKind(of: CPDFPolylineAnnotation.self)) {
|
|
|
- if perimeterMeasureInfoWindowController == nil {
|
|
|
- let measureInfo = CPDFPerimeterMeasureInfo()
|
|
|
- perimeterMeasureInfoWindowController = CPerimeterMeasureInfoWindowController()
|
|
|
- perimeterMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
- perimeterMeasureInfoWindowController?.delegate = self
|
|
|
- }
|
|
|
- if areaMeasureInfoWindowController == nil {
|
|
|
- let measureInfo = CPDFAreaMeasureInfo()
|
|
|
- areaMeasureInfoWindowController = CAreaMeasureInfoWindowController()
|
|
|
- areaMeasureInfoWindowController?.measureInfo = measureInfo
|
|
|
- areaMeasureInfoWindowController?.delegate = self
|
|
|
- }
|
|
|
+ func convertSelectionRectOCR(rect: NSRect) {
|
|
|
+ let rect = NSIntegralRect(rect)
|
|
|
+ let orgPage : CPDFPage = listView.currentSelectionPage() ?? CPDFPage()
|
|
|
+
|
|
|
+ if let page : CPDFPage = orgPage.copy() as? CPDFPage {
|
|
|
+ page.setBounds(rect, for: .cropBox)
|
|
|
+ let image = page.thumbnail(of: rect.size) ?? NSImage()
|
|
|
+ guard let model = self.rightSideController?.tool_OCRController?.model else { return }
|
|
|
+ model.pageRange = [Int(orgPage.pageIndex())]
|
|
|
+ KMOCRManager.manager.convertOCR(images: [image], model: model, progress: { progress in
|
|
|
+
|
|
|
+ }) { [weak self] document, text, error in
|
|
|
+ self?.rightSideController?.tool_OCRController?.model.text = text ?? ""
|
|
|
+ self?.rightSideController?.tool_OCRController?.reloadData()
|
|
|
+ //关闭窗口
|
|
|
+ self?.listView.selectionRect = NSZeroRect
|
|
|
+ self?.listView.selectionPageIndex = UInt(NSNotFound)
|
|
|
+ self?.closePopOperationWindow()
|
|
|
+ self?.listView.setNeedsDisplayForVisiblePages()
|
|
|
}
|
|
|
- } else {
|
|
|
- cancelMeasureType()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//MARK: - 代理方法
|
|
@@ -3740,8 +3775,7 @@ extension KMMainViewController: KMRightSideControllerDelegate {
|
|
|
|
|
|
func kmRightSideControllerOCRDoneAction(_ controller: KMRightSideController, _ model: KMOCRModel) {
|
|
|
if model.showType == .area {
|
|
|
-
|
|
|
-
|
|
|
+ self.convertOCRSaveAsTXT(text: model.text)
|
|
|
} else {
|
|
|
if model.saveAsPDF {
|
|
|
if model.saveType == .PDF {
|