Procházet zdrojové kódy

OCR - 移除项目OCR库索引、注释OCR相关代码

wanjun před 1 rokem
rodič
revize
5cf6af8133

+ 0 - 62
PDF Office/PDF Office.xcodeproj/project.pbxproj

@@ -1855,37 +1855,6 @@
 		BB147047299DC0D200784A6A /* OIDServiceConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = BB146FAA299DC0D000784A6A /* OIDServiceConfiguration.m */; };
 		BB147048299DC0D200784A6A /* OIDServiceConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = BB146FAA299DC0D000784A6A /* OIDServiceConfiguration.m */; };
 		BB147049299DC0D200784A6A /* OIDServiceConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = BB146FAA299DC0D000784A6A /* OIDServiceConfiguration.m */; };
-		BB147052299E327200784A6A /* libDocumentAI.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704B299E327100784A6A /* libDocumentAI.dylib */; };
-		BB147053299E327200784A6A /* libDocumentAI.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704B299E327100784A6A /* libDocumentAI.dylib */; };
-		BB147054299E327200784A6A /* libDocumentAI.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704B299E327100784A6A /* libDocumentAI.dylib */; };
-		BB147055299E327300784A6A /* libopencv_world.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704C299E327100784A6A /* libopencv_world.dylib */; };
-		BB147056299E327300784A6A /* libopencv_world.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704C299E327100784A6A /* libopencv_world.dylib */; };
-		BB147057299E327300784A6A /* libopencv_world.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704C299E327100784A6A /* libopencv_world.dylib */; };
-		BB147059299E327400784A6A /* ComDocumentAIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704D299E327100784A6A /* ComDocumentAIKit.framework */; };
-		BB14705A299E327400784A6A /* ComDocumentAIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704D299E327100784A6A /* ComDocumentAIKit.framework */; };
-		BB14705B299E327400784A6A /* libopencv_world.4.2.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704E299E327100784A6A /* libopencv_world.4.2.0.dylib */; };
-		BB14705C299E327400784A6A /* libopencv_world.4.2.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704E299E327100784A6A /* libopencv_world.4.2.0.dylib */; };
-		BB14705D299E327500784A6A /* libopencv_world.4.2.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704E299E327100784A6A /* libopencv_world.4.2.0.dylib */; };
-		BB14705E299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704F299E327100784A6A /* libpaddle_light_api_shared.dylib */; };
-		BB14705F299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704F299E327100784A6A /* libpaddle_light_api_shared.dylib */; };
-		BB147060299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704F299E327100784A6A /* libpaddle_light_api_shared.dylib */; };
-		BB147061299E327500784A6A /* libpaddle_inference.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147050299E327100784A6A /* libpaddle_inference.dylib */; };
-		BB147062299E327600784A6A /* libpaddle_inference.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147050299E327100784A6A /* libpaddle_inference.dylib */; };
-		BB147063299E327600784A6A /* libpaddle_inference.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147050299E327100784A6A /* libpaddle_inference.dylib */; };
-		BB147064299E327600784A6A /* libopencv_world.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147051299E327100784A6A /* libopencv_world.4.2.dylib */; };
-		BB147065299E327600784A6A /* libopencv_world.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147051299E327100784A6A /* libopencv_world.4.2.dylib */; };
-		BB147066299E327700784A6A /* libopencv_world.4.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BB147051299E327100784A6A /* libopencv_world.4.2.dylib */; };
-		BB147068299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BB147067299E32A800784A6A /* CDoucumnetAIResource.bundle */; };
-		BB147069299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BB147067299E32A800784A6A /* CDoucumnetAIResource.bundle */; };
-		BB14706A299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BB147067299E32A800784A6A /* CDoucumnetAIResource.bundle */; };
-		BB14706B299E343C00784A6A /* ComDocumentAIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704D299E327100784A6A /* ComDocumentAIKit.framework */; };
-		BB14706C299E343C00784A6A /* ComDocumentAIKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704D299E327100784A6A /* ComDocumentAIKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
-		BB14706D299E344000784A6A /* libDocumentAI.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704B299E327100784A6A /* libDocumentAI.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
-		BB14706E299E344200784A6A /* libopencv_world.4.2.0.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704E299E327100784A6A /* libopencv_world.4.2.0.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
-		BB14706F299E344400784A6A /* libopencv_world.4.2.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB147051299E327100784A6A /* libopencv_world.4.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
-		BB147070299E344700784A6A /* libopencv_world.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704C299E327100784A6A /* libopencv_world.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
-		BB147071299E344A00784A6A /* libpaddle_inference.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB147050299E327100784A6A /* libpaddle_inference.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
-		BB147072299E344D00784A6A /* libpaddle_light_api_shared.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB14704F299E327100784A6A /* libpaddle_light_api_shared.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		BB162E8E294FFC0C0088E9D1 /* KMWatermarkPDFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB162E8D294FFC0C0088E9D1 /* KMWatermarkPDFView.swift */; };
 		BB162E8F294FFC0C0088E9D1 /* KMWatermarkPDFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB162E8D294FFC0C0088E9D1 /* KMWatermarkPDFView.swift */; };
 		BB162E90294FFC0C0088E9D1 /* KMWatermarkPDFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB162E8D294FFC0C0088E9D1 /* KMWatermarkPDFView.swift */; };
@@ -3029,16 +2998,9 @@
 				BB88E45129403B34002B3655 /* ComPDFKit_Conversion.framework in Embed Frameworks */,
 				ADE3C1CD29A5A7EE00793B13 /* AFNetworking.framework in Embed Frameworks */,
 				89752DAC2936ECED003FF08E /* Masonry.framework in Embed Frameworks */,
-				BB14706E299E344200784A6A /* libopencv_world.4.2.0.dylib in Embed Frameworks */,
-				BB14706C299E343C00784A6A /* ComDocumentAIKit.framework in Embed Frameworks */,
 				ADE3C1D629A5A91C00793B13 /* KMAdvertisement.framework in Embed Frameworks */,
-				BB147072299E344D00784A6A /* libpaddle_light_api_shared.dylib in Embed Frameworks */,
 				BBB9B33A299A5FD1004F3235 /* ObjectiveDropboxOfficial.framework in Embed Frameworks */,
-				BB147070299E344700784A6A /* libopencv_world.dylib in Embed Frameworks */,
 				BB2C6ACC28F40AE800478A33 /* ComPDFKit.framework in Embed Frameworks */,
-				BB14706F299E344400784A6A /* libopencv_world.4.2.dylib in Embed Frameworks */,
-				BB147071299E344A00784A6A /* libpaddle_inference.dylib in Embed Frameworks */,
-				BB14706D299E344000784A6A /* libDocumentAI.dylib in Embed Frameworks */,
 			);
 			name = "Embed Frameworks";
 			runOnlyForDeploymentPostprocessing = 0;
@@ -4361,20 +4323,13 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				BB147055299E327300784A6A /* libopencv_world.dylib in Frameworks */,
 				ADE3C1CC29A5A7EE00793B13 /* AFNetworking.framework in Frameworks */,
 				BBB9B339299A5FD1004F3235 /* ObjectiveDropboxOfficial.framework in Frameworks */,
-				BB147064299E327600784A6A /* libopencv_world.4.2.dylib in Frameworks */,
-				BB14705E299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */,
 				BB88E45029403B34002B3655 /* ComPDFKit_Conversion.framework in Frameworks */,
 				ADE3C1D529A5A91C00793B13 /* KMAdvertisement.framework in Frameworks */,
 				89D9896328FD23AE003A3E87 /* PDFKit.framework in Frameworks */,
-				BB147061299E327500784A6A /* libpaddle_inference.dylib in Frameworks */,
 				BB2C6ACB28F40AE800478A33 /* ComPDFKit.framework in Frameworks */,
 				89752DAB2936ECED003FF08E /* Masonry.framework in Frameworks */,
-				BB14705B299E327400784A6A /* libopencv_world.4.2.0.dylib in Frameworks */,
-				BB14706B299E343C00784A6A /* ComDocumentAIKit.framework in Frameworks */,
-				BB147052299E327200784A6A /* libDocumentAI.dylib in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4396,20 +4351,13 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				BB147056299E327300784A6A /* libopencv_world.dylib in Frameworks */,
 				ADE3C1C929A5A75E00793B13 /* AFNetworking.framework in Frameworks */,
 				BB88E44E294039FF002B3655 /* ComPDFKit_Conversion.framework in Frameworks */,
-				BB147065299E327600784A6A /* libopencv_world.4.2.dylib in Frameworks */,
-				BB14705F299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */,
 				BBB9B337299A5F35004F3235 /* ObjectiveDropboxOfficial.framework in Frameworks */,
 				ADE3C1D329A5A91600793B13 /* KMAdvertisement.framework in Frameworks */,
 				89D9896428FD23B8003A3E87 /* PDFKit.framework in Frameworks */,
-				BB147062299E327600784A6A /* libpaddle_inference.dylib in Frameworks */,
 				BB2C6AD028F445B600478A33 /* ComPDFKit.framework in Frameworks */,
 				89752DA92936ECE9003FF08E /* Masonry.framework in Frameworks */,
-				BB147059299E327400784A6A /* ComDocumentAIKit.framework in Frameworks */,
-				BB14705C299E327400784A6A /* libopencv_world.4.2.0.dylib in Frameworks */,
-				BB147053299E327200784A6A /* libDocumentAI.dylib in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4431,20 +4379,13 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				BB147057299E327300784A6A /* libopencv_world.dylib in Frameworks */,
 				ADE3C1CA29A5A75E00793B13 /* AFNetworking.framework in Frameworks */,
 				BB88E44F294039FF002B3655 /* ComPDFKit_Conversion.framework in Frameworks */,
-				BB147066299E327700784A6A /* libopencv_world.4.2.dylib in Frameworks */,
-				BB147060299E327500784A6A /* libpaddle_light_api_shared.dylib in Frameworks */,
 				BBB9B338299A5F35004F3235 /* ObjectiveDropboxOfficial.framework in Frameworks */,
 				ADE3C1D429A5A91600793B13 /* KMAdvertisement.framework in Frameworks */,
 				89D9896528FD23BF003A3E87 /* PDFKit.framework in Frameworks */,
-				BB147063299E327600784A6A /* libpaddle_inference.dylib in Frameworks */,
 				BB2C6AD328F445B900478A33 /* ComPDFKit.framework in Frameworks */,
 				89752DA72936ECE4003FF08E /* Masonry.framework in Frameworks */,
-				BB14705A299E327400784A6A /* ComDocumentAIKit.framework in Frameworks */,
-				BB14705D299E327500784A6A /* libopencv_world.4.2.0.dylib in Frameworks */,
-				BB147054299E327200784A6A /* libDocumentAI.dylib in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -8522,7 +8463,6 @@
 				9FBA0EE928FFC2FE001117AF /* Image.xcassets in Resources */,
 				BBA19F3229ADAC81001A285A /* signPicture_hover.pdf in Resources */,
 				BB2EDF73296ECE17003BCF58 /* KMPageEditThumbnailItem.xib in Resources */,
-				BB147068299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */,
 				BB49ED09293F461500C82CA2 /* KMConvertCSVWindowController.xib in Resources */,
 				9F1F82D5292F6D510092C4B4 /* KMPDFInsertPreviewViewController.xib in Resources */,
 				ADD1B6BF2942DD3D00C3FFF7 /* KMPrintChooseView.xib in Resources */,
@@ -8782,7 +8722,6 @@
 				ADB1FE8329752F3200ED072D /* KMBatchSecurityView.xib in Resources */,
 				894A00F62976314C0070ED83 /* KMPDFViewPanelSetViewController.xib in Resources */,
 				9F0CB48B29683DC400007028 /* KMPropertiesPanelPresetColorSubVC.xib in Resources */,
-				BB147069299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */,
 				89D2D2FF294C806000BFF5FE /* KMPDFThumbnailItem.xib in Resources */,
 				89E4E70C2963D62B002DBA6F /* KMAnnotationFontWindowController.xib in Resources */,
 				ADC25DFD2923BA710080A3F6 /* KMImageToPDFWindowController.xib in Resources */,
@@ -8947,7 +8886,6 @@
 				BB89724B294C19980045787C /* KMWatermarkAdjectiveListController.xib in Resources */,
 				BBA2109229ACBFDB00E6B346 /* nosign.pdf in Resources */,
 				9FDD0F982952FF4D000C4DAD /* $metadata.json in Resources */,
-				BB14706A299E32AB00784A6A /* CDoucumnetAIResource.bundle in Resources */,
 				ADE3C1C629A4C13700793B13 /* KMPrintAccessoryController_OC.xib in Resources */,
 				ADEC7A83299397F8009A8256 /* SF-Pro-Text-Regular.otf in Resources */,
 				BB49ED03293F459500C82CA2 /* KMConvertPPTsWindowController.xib in Resources */,

+ 1 - 1
PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIPDFView.h

@@ -17,7 +17,7 @@
 
 @property (nonatomic,retain) NSMutableArray <NSDictionary*>*resultDics;
 
-- (void)updateResult:(NSArray<COCRResult *> *)results recognitionRect:(CGRect)recognitionRect;
+//- (void)updateResult:(NSArray<COCRResult *> *)results recognitionRect:(CGRect)recognitionRect;
 
 - (NSRect)recognitionRect;
 

+ 160 - 160
PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIPDFView.m

@@ -14,7 +14,7 @@
 
 @interface KMDocumentAIPDFView()<NSPopoverDelegate>
 
-@property(nonatomic,retain) NSMutableArray<COCRResult *> * results;
+//@property(nonatomic,retain) NSMutableArray<COCRResult *> * results;
 
 @property(nonatomic,assign) CGRect drawRecognitionEreaRect;
 
@@ -22,7 +22,7 @@
 
 @property (nonatomic, assign) NSUInteger selectionPageIndex;
 
-@property (nonatomic, retain) COCRResult * activeResult;
+//@property (nonatomic, retain) COCRResult * activeResult;
 
 @property (nonatomic, assign) NSInteger activeResultIndex;
 
@@ -46,7 +46,7 @@
         __block typeof(self) blockSelf = self;
         self.documentAIPopViewController.callback = ^(NSInteger result) {
             if(result == 1) {
-                blockSelf.results[blockSelf.activeResultIndex].text = blockSelf.documentAIPopViewController.contentTextView.string?:@"";
+//                blockSelf.results[blockSelf.activeResultIndex].text = blockSelf.documentAIPopViewController.contentTextView.string?:@"";
                 [blockSelf setNeedsDisplayAnnotationViewForPage:blockSelf.activeResultPage];
             }
             if(blockSelf.popOver.isShown)
@@ -60,43 +60,43 @@
 }
 
 - (void)mouseDown:(NSEvent *)event {
-     if ([self doOCRResultWithEvent:event]) {
-        if(self.popOver.isShown) {
-            [self.popOver performClose:nil];
-        } else {
-            CGRect rect = [self convertRect:self.activeResult.textBounds fromPage:self.currentPage];
-            [self.popOver showRelativeToRect:rect ofView:self preferredEdge:NSRectEdgeMinY];
-            self.documentAIPopViewController.contentTextView.string = self.activeResult.text?:@"";
-        }
-    } else if ([self isRecognitionErea]) {
-        [self doSelectWithEvent:event];
-    }
+//     if ([self doOCRResultWithEvent:event]) {
+//        if(self.popOver.isShown) {
+//            [self.popOver performClose:nil];
+//        } else {
+//            CGRect rect = [self convertRect:self.activeResult.textBounds fromPage:self.currentPage];
+//            [self.popOver showRelativeToRect:rect ofView:self preferredEdge:NSRectEdgeMinY];
+//            self.documentAIPopViewController.contentTextView.string = self.activeResult.text?:@"";
+//        }
+//    } else if ([self isRecognitionErea]) {
+//        [self doSelectWithEvent:event];
+//    }
 }
 
-- (COCRResult *)doOCRResultWithEvent:(NSEvent *)theEvent {
-    COCRResult *result = nil;
-    NSPoint point = NSZeroPoint;
-    CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
-
-    for (NSInteger i = 0;i<self.results.count;i++) {
-        COCRResult *tResult = self.results[i];
-        if(CGRectContainsPoint(tResult.textBounds, point)){
-            result = tResult;
-            self.activeResultIndex = i;
-            break;
-        }
-    }
-    if(result) {
-        self.activeResult = result;
-        self.activeResultPage = page;
-    } else {
-        self.activeResult = nil;
-        self.activeResultPage = nil;
-        self.activeResultIndex = -1;
-    }
-
-    return result;
-}
+//- (COCRResult *)doOCRResultWithEvent:(NSEvent *)theEvent {
+//    COCRResult *result = nil;
+//    NSPoint point = NSZeroPoint;
+//    CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
+//
+//    for (NSInteger i = 0;i<self.results.count;i++) {
+//        COCRResult *tResult = self.results[i];
+//        if(CGRectContainsPoint(tResult.textBounds, point)){
+//            result = tResult;
+//            self.activeResultIndex = i;
+//            break;
+//        }
+//    }
+//    if(result) {
+//        self.activeResult = result;
+//        self.activeResultPage = page;
+//    } else {
+//        self.activeResult = nil;
+//        self.activeResultPage = nil;
+//        self.activeResultIndex = -1;
+//    }
+//
+//    return result;
+//}
 
 - (void)mouseMoved:(NSEvent *)event {
 }
@@ -300,128 +300,128 @@
     return page;
 }
 
-- (void)updateResult:(NSArray<COCRResult *> *)results recognitionRect:(CGRect)recognitionRect {
-    self.results = [NSMutableArray arrayWithArray:results];
-    self.drawRecognitionEreaRect = recognitionRect;
-    [self setNeedsDisplayAnnotationViewForPage:self.currentPage];
-}
-
-- (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context {
-    if(self.resultDics.count > 0) {
-        NSInteger currentIndex = [self.document indexForPage:page];
-        NSArray<COCRResult *> *currentResults = @[];
-        for (NSDictionary *dic in self.resultDics) {
-            if(dic[@"page"] && [dic[@"page"] integerValue] == currentIndex) {
-                if(dic[@"results"]) {
-                    currentResults = dic[@"results"];
-                    break;
-                }
-            }
-        }
-        if (currentResults.count>0) {
-            [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:context flipped:NO]];
-            
-            CGContextSaveGState(context);
-            CGContextAddRect(context, self.drawRecognitionEreaRect);
-            CGContextSetRGBFillColor(context, 1, 1, 1, 0.7);
-            CGContextFillPath(context);
-            CGContextRestoreGState(context);
-            
-            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-            [dic setValue:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
-
-            for (COCRResult * cOcrResult in currentResults) {
-                CGContextSaveGState(context);
-
-                CGRect rect =  cOcrResult.textBounds;
-                
-                NSString *strChar = cOcrResult.text;
-                CGFloat fontsize = 1.0;
-                NSFont *font = [NSFont systemFontOfSize:fontsize];
-                CGSize strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
-                while ((fontsize<127) && !(strSize.width>=cOcrResult.textBounds.size.width || strSize.height>=cOcrResult.textBounds.size.height)) {
-                    fontsize += 1.0;
-                    font = [NSFont systemFontOfSize:fontsize];
-                    strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
-                }
-                NSFont *drawFont = [NSFont systemFontOfSize:fontsize-1];
-                
-                strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:drawFont}];
-                CGFloat k =  (cOcrResult.textBounds.size.width - strSize.width)/(strChar.length);
-                
-                NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
-
-                NSDictionary *attriDict = @{NSParagraphStyleAttributeName:style,NSKernAttributeName:@(k),NSFontAttributeName:drawFont};
-                
-                NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:strChar attributes:attriDict];
-                [attributeString drawInRect:rect];
-                
-                CGContextAddRect(context, rect);
-                CGContextSetLineWidth(context, 1.0);
-                CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0].CGColor);
-                CGContextStrokePath(context);
-
-                CGContextRestoreGState(context);
-            }
-        }
-        
-    }
-
-    if(!CGRectEqualToRect(self.recognitionEreaRect, CGRectZero)) {
-        @synchronized (self) {
-            CGContextSaveGState(context);
-
-            CGFloat size = DOCUMENT_SIZE;
-            CGContextSetLineWidth(context, 5.0);
-            CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
-
-            CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
-
-            CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
-
-            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
-            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
-
-            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
-            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
-
-            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
-
-            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
-
-            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
-
-            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
-            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
-
-            CGContextStrokePath(context);
-
-            CGContextSetLineCap(context, kCGLineCapRound);
-            CGContextSetLineWidth(context, 2.0);
-            CGContextRestoreGState(context);
-
-            CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
-            CGContextBeginPath(context);
-            CGContextMoveToPoint(context, self.recognitionEreaRect.origin.x, self.recognitionEreaRect.origin.y);
-            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x+ self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y);
-            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x + self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
-            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
-            CGContextClosePath(context);
-            CGFloat lengths[] = {10,5};
-            CGContextSetLineDash(context, 0, lengths,2);
-            CGContextStrokePath(context);
-        }
-    }
-}
+//- (void)updateResult:(NSArray<COCRResult *> *)results recognitionRect:(CGRect)recognitionRect {
+//    self.results = [NSMutableArray arrayWithArray:results];
+//    self.drawRecognitionEreaRect = recognitionRect;
+//    [self setNeedsDisplayAnnotationViewForPage:self.currentPage];
+//}
+//
+//- (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context {
+//    if(self.resultDics.count > 0) {
+//        NSInteger currentIndex = [self.document indexForPage:page];
+//        NSArray<COCRResult *> *currentResults = @[];
+//        for (NSDictionary *dic in self.resultDics) {
+//            if(dic[@"page"] && [dic[@"page"] integerValue] == currentIndex) {
+//                if(dic[@"results"]) {
+//                    currentResults = dic[@"results"];
+//                    break;
+//                }
+//            }
+//        }
+//        if (currentResults.count>0) {
+//            [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:context flipped:NO]];
+//
+//            CGContextSaveGState(context);
+//            CGContextAddRect(context, self.drawRecognitionEreaRect);
+//            CGContextSetRGBFillColor(context, 1, 1, 1, 0.7);
+//            CGContextFillPath(context);
+//            CGContextRestoreGState(context);
+//
+//            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+//            [dic setValue:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
+//
+//            for (COCRResult * cOcrResult in currentResults) {
+//                CGContextSaveGState(context);
+//
+//                CGRect rect =  cOcrResult.textBounds;
+//
+//                NSString *strChar = cOcrResult.text;
+//                CGFloat fontsize = 1.0;
+//                NSFont *font = [NSFont systemFontOfSize:fontsize];
+//                CGSize strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
+//                while ((fontsize<127) && !(strSize.width>=cOcrResult.textBounds.size.width || strSize.height>=cOcrResult.textBounds.size.height)) {
+//                    fontsize += 1.0;
+//                    font = [NSFont systemFontOfSize:fontsize];
+//                    strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
+//                }
+//                NSFont *drawFont = [NSFont systemFontOfSize:fontsize-1];
+//
+//                strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:drawFont}];
+//                CGFloat k =  (cOcrResult.textBounds.size.width - strSize.width)/(strChar.length);
+//
+//                NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
+//
+//                NSDictionary *attriDict = @{NSParagraphStyleAttributeName:style,NSKernAttributeName:@(k),NSFontAttributeName:drawFont};
+//
+//                NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:strChar attributes:attriDict];
+//                [attributeString drawInRect:rect];
+//
+//                CGContextAddRect(context, rect);
+//                CGContextSetLineWidth(context, 1.0);
+//                CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0].CGColor);
+//                CGContextStrokePath(context);
+//
+//                CGContextRestoreGState(context);
+//            }
+//        }
+//
+//    }
+//
+//    if(!CGRectEqualToRect(self.recognitionEreaRect, CGRectZero)) {
+//        @synchronized (self) {
+//            CGContextSaveGState(context);
+//
+//            CGFloat size = DOCUMENT_SIZE;
+//            CGContextSetLineWidth(context, 5.0);
+//            CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
+//
+//            CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
+//
+//            CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
+//
+//            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
+//            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
+//
+//            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
+//            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
+//
+//            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
+//
+//            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
+//
+//            CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
+//
+//            CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
+//            CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
+//
+//            CGContextStrokePath(context);
+//
+//            CGContextSetLineCap(context, kCGLineCapRound);
+//            CGContextSetLineWidth(context, 2.0);
+//            CGContextRestoreGState(context);
+//
+//            CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
+//            CGContextBeginPath(context);
+//            CGContextMoveToPoint(context, self.recognitionEreaRect.origin.x, self.recognitionEreaRect.origin.y);
+//            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x+ self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y);
+//            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x + self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
+//            CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
+//            CGContextClosePath(context);
+//            CGFloat lengths[] = {10,5};
+//            CGContextSetLineDash(context, 0, lengths,2);
+//            CGContextStrokePath(context);
+//        }
+//    }
+//}
 
 #pragma Mark - menuForEvent
 

+ 3 - 3
PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIViewController.h

@@ -7,7 +7,7 @@
 
 #import <Cocoa/Cocoa.h>
 #import <ComPDFKit/ComPDFKit.h>
-#import <ComDocumentAIKit/ComDocumentAIKit.h>
+//#import <ComDocumentAIKit/ComDocumentAIKit.h>
 #import "KMDocumentAIPDFView.h"
 
 @class KMDocumentAIViewController;
@@ -35,9 +35,9 @@
 - (void)resetIncreaseAllPage;
 
 // @pageString, Such as "0,3,5-7".
-- (void)recognitionPageString:(NSString *)pageString withModelType:(COCRModelType)modelType;
+//- (void)recognitionPageString:(NSString *)pageString withModelType:(COCRModelType)modelType;
 
-- (void)recognitionPartModelWithModelType:(COCRModelType)modelType;
+//- (void)recognitionPartModelWithModelType:(COCRModelType)modelType;
 
 - (void)creatRecognitionDocument;
 

+ 92 - 92
PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIViewController.m

@@ -64,7 +64,7 @@
 
 @property(nonatomic,assign) IBOutlet KMDocumentAIPDFView *pdfPreView;
 
-@property(nonatomic,assign) COCRModelType modelType;
+//@property(nonatomic,assign) COCRModelType modelType;
 
 @property(nonatomic,retain) CPDFDocument *orgDocument;
 
@@ -181,7 +181,7 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
             [copyPage drawWithBox:CPDFDisplayCropBox toContext:context];
             [image unlockFocus];
             
-            [[KMDocumentAIManager defaultManager] recognitionImages:@[image] withModelType:blockSelf.modelType];
+//            [[KMDocumentAIManager defaultManager] recognitionImages:@[image] withModelType:blockSelf.modelType];
             
         }
     };
@@ -298,7 +298,7 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
                 self.pageRecognitionImageView.image = [NSImage imageNamed:@"KMImageNameOCRPage"];
                 self.areaRecognitionImageView.image = [NSImage imageNamed:@"KMImageNameOCRAreaSelect"];
                 self.languageSetView.hidden = NO;
-                [self recognitionPartModelWithModelType:self.languagePopButton.indexOfSelectedItem+1];
+//                [self recognitionPartModelWithModelType:self.languagePopButton.indexOfSelectedItem+1];
                 self.rangeSetView.hidden = YES;
                 self.OCRButton.enabled = NO;
                 self.ocrTipView.hidden = NO;
@@ -327,7 +327,7 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
 
 - (IBAction)seleclanguageAction:(id)sender {
     if(!self.languageSetView.hidden && self.rangeSetView.hidden) {
-        [self recognitionPartModelWithModelType:self.languagePopButton.indexOfSelectedItem+1];
+//        [self recognitionPartModelWithModelType:self.languagePopButton.indexOfSelectedItem+1];
     }
 }
 
@@ -387,7 +387,7 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
     }
    
     if (self.pagesString) {
-        [self recognitionPageString:self.pagesString withModelType:self.languagePopButton.indexOfSelectedItem+1];
+//        [self recognitionPageString:self.pagesString withModelType:self.languagePopButton.indexOfSelectedItem+1];
     }
     
 }
@@ -415,38 +415,38 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
     self.pdfPreView.isRecognitionErea = NO;
 }
 
-- (void)recognitionPageString:(NSString *)pageString withModelType:(COCRModelType)modelType {
-    self.pdfPreView.isRecognitionErea = NO;
-
-    KMFileAttribute *fileAttribute = [[KMFileAttribute alloc] init];
-    fileAttribute.pdfDocument = self.orgDocument;
-    fileAttribute.bAllPage = NO;
-    fileAttribute.filePath = self.orgDocument.documentURL.path;
-    fileAttribute.pagesString = pageString;
-    fileAttribute.password = self.orgDocument.password;
-    NSMutableArray *images = [NSMutableArray array];
-    self.datas = [NSMutableArray array];
-    self.resultDics = [NSMutableArray array];
-    for (NSNumber * num in fileAttribute.selectPages) {
-        CPDFPage *page = [self.preDocument pageAtIndex:num.integerValue-1];
-        NSImage *image = [page thumbnailOfSize:page.bounds.size];
-        if(image) {
-            [images addObject:image];
-            [self.datas addObject:page];
-        }else {
-            NSLog(@"111");
-        }
-    }
-
-    [KMDocumentAIManager defaultManager].delegate = self;
-    [[KMDocumentAIManager defaultManager] recognitionImages:images withModelType:modelType];
-    self.modelType = modelType;
-}
-
-- (void)recognitionPartModelWithModelType:(COCRModelType)modelType {
-    self.pdfPreView.isRecognitionErea = YES;
-    self.modelType = modelType;
-}
+//- (void)recognitionPageString:(NSString *)pageString withModelType:(COCRModelType)modelType {
+//    self.pdfPreView.isRecognitionErea = NO;
+//
+//    KMFileAttribute *fileAttribute = [[KMFileAttribute alloc] init];
+//    fileAttribute.pdfDocument = self.orgDocument;
+//    fileAttribute.bAllPage = NO;
+//    fileAttribute.filePath = self.orgDocument.documentURL.path;
+//    fileAttribute.pagesString = pageString;
+//    fileAttribute.password = self.orgDocument.password;
+//    NSMutableArray *images = [NSMutableArray array];
+//    self.datas = [NSMutableArray array];
+//    self.resultDics = [NSMutableArray array];
+//    for (NSNumber * num in fileAttribute.selectPages) {
+//        CPDFPage *page = [self.preDocument pageAtIndex:num.integerValue-1];
+//        NSImage *image = [page thumbnailOfSize:page.bounds.size];
+//        if(image) {
+//            [images addObject:image];
+//            [self.datas addObject:page];
+//        }else {
+//            NSLog(@"111");
+//        }
+//    }
+//
+//    [KMDocumentAIManager defaultManager].delegate = self;
+//    [[KMDocumentAIManager defaultManager] recognitionImages:images withModelType:modelType];
+//    self.modelType = modelType;
+//}
+//
+//- (void)recognitionPartModelWithModelType:(COCRModelType)modelType {
+//    self.pdfPreView.isRecognitionErea = YES;
+//    self.modelType = modelType;
+//}
 
 - (void)creatRecognitionDocument {
     for (NSDictionary *dic in self.resultDics) {
@@ -455,25 +455,25 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
             CPDFPage *page = [self.orgDocument pageAtIndex:num.integerValue];
             
             NSArray *results = [dic objectForKey:@"results"];
-            for (COCRResult *result in results) {
-                CGRect rect =  result.textBounds;
-
-                NSString *strChar = result.text;
-                CGFloat fontsize = 1.0;
-
-                NSFont *font = [NSFont systemFontOfSize:fontsize];
-                CGSize strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
-                while ((fontsize<127) && !(strSize.width>=result.textBounds.size.width || strSize.height>=result.textBounds.size.height)) {
-                    fontsize += 1.0;
-                    font = [NSFont systemFontOfSize:fontsize];
-                    strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
-                }
-                NSFont *drawFont = [NSFont systemFontOfSize:fontsize-1];
-
-                NSDictionary *dic = @{NSFontAttributeName:drawFont};
-
-                [page addStringBounds:result.textBounds withString:result.text withAttributes:dic];
-            }
+//            for (COCRResult *result in results) {
+//                CGRect rect =  result.textBounds;
+//
+//                NSString *strChar = result.text;
+//                CGFloat fontsize = 1.0;
+//
+//                NSFont *font = [NSFont systemFontOfSize:fontsize];
+//                CGSize strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
+//                while ((fontsize<127) && !(strSize.width>=result.textBounds.size.width || strSize.height>=result.textBounds.size.height)) {
+//                    fontsize += 1.0;
+//                    font = [NSFont systemFontOfSize:fontsize];
+//                    strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
+//                }
+//                NSFont *drawFont = [NSFont systemFontOfSize:fontsize-1];
+//
+//                NSDictionary *dic = @{NSFontAttributeName:drawFont};
+//
+//                [page addStringBounds:result.textBounds withString:result.text withAttributes:dic];
+//            }
 
         }
     }
@@ -547,41 +547,41 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
     
 }
 
-- (void)documentAIManager:(KMDocumentAIManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray<COCRResult *> *)results {
-    CPDFPage *page = self.datas[index];
-    NSInteger pageIndex = [self.preDocument indexForPage:page];
-
-    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-    [dic setValue:@(pageIndex) forKey:@"page"];
-    NSMutableDictionary *recognitionDic = [NSMutableDictionary dictionary];
-
-    CGRect recognitionRect = page.bounds;
-    if(self.pdfPreView.isRecognitionErea) {
-        NSMutableArray *tResults = [NSMutableArray array];
-        for (COCRResult * result  in results) {
-            CGRect rect = result.textBounds;
-            rect.origin.x += self.recognitionRect.origin.x;
-            rect.origin.y += self.recognitionRect.origin.y;
-            result.textBounds = rect;
-            [tResults addObject:result];
-        }
-        recognitionRect = self.recognitionRect;
-        results = tResults;
-    }
-
-    NSValue *value = [NSValue valueWithRect:recognitionRect];
-    [dic setValue:value forKey:@"recognitionRect"];
-    [dic setValue:results forKey:@"results"];
-
-    [self.resultDics addObject:dic];
-    self.pdfPreView.resultDics = self.resultDics;
-    if(pageIndex == self.pdfPreView.currentPageIndex) {
-        [self.pdfPreView updateResult:results recognitionRect:recognitionRect];
-    }
-    float allPages = [[NSString stringWithFormat:@"%lu",(unsigned long)self.datas.count] floatValue];
-    self.progressIndicator.doubleValue = (index / allPages) * 100 ;
-    [self hideWaitting];
-}
+//- (void)documentAIManager:(KMDocumentAIManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray<COCRResult *> *)results {
+//    CPDFPage *page = self.datas[index];
+//    NSInteger pageIndex = [self.preDocument indexForPage:page];
+//
+//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
+//    [dic setValue:@(pageIndex) forKey:@"page"];
+//    NSMutableDictionary *recognitionDic = [NSMutableDictionary dictionary];
+//
+//    CGRect recognitionRect = page.bounds;
+//    if(self.pdfPreView.isRecognitionErea) {
+//        NSMutableArray *tResults = [NSMutableArray array];
+//        for (COCRResult * result  in results) {
+//            CGRect rect = result.textBounds;
+//            rect.origin.x += self.recognitionRect.origin.x;
+//            rect.origin.y += self.recognitionRect.origin.y;
+//            result.textBounds = rect;
+//            [tResults addObject:result];
+//        }
+//        recognitionRect = self.recognitionRect;
+//        results = tResults;
+//    }
+//
+//    NSValue *value = [NSValue valueWithRect:recognitionRect];
+//    [dic setValue:value forKey:@"recognitionRect"];
+//    [dic setValue:results forKey:@"results"];
+//
+//    [self.resultDics addObject:dic];
+//    self.pdfPreView.resultDics = self.resultDics;
+//    if(pageIndex == self.pdfPreView.currentPageIndex) {
+//        [self.pdfPreView updateResult:results recognitionRect:recognitionRect];
+//    }
+//    float allPages = [[NSString stringWithFormat:@"%lu",(unsigned long)self.datas.count] floatValue];
+//    self.progressIndicator.doubleValue = (index / allPages) * 100 ;
+//    [self hideWaitting];
+//}
 
 - (void)imageEngineManager:(KMDocumentAIManager *)manager didFinishCIImageAtIndex:(NSInteger)index outImage:(NSString *)filePath {
     NSImage *image = [[NSImage alloc]initWithContentsOfURL:[NSURL fileURLWithPath:filePath]];
@@ -611,7 +611,7 @@ static inline NSFont * FontWithSize(NSString *strChar, CGSize size) {
         NSNumber *num = [dic objectForKey:@"page"];
         if(num.integerValue == self.pdfPreView.currentPageIndex) {
             NSValue *value = [dic objectForKey:@"recognitionRect"];
-            [self.pdfPreView updateResult:[dic objectForKey:@"results"] recognitionRect:value.rectValue];
+//            [self.pdfPreView updateResult:[dic objectForKey:@"results"] recognitionRect:value.rectValue];
         }
     }
 }

+ 3 - 3
PDF Office/PDF Office/Class/PDFTools/OCR/Manager/KMDocumentAIManager.h

@@ -6,7 +6,7 @@
 //
 
 #import <Foundation/Foundation.h>
-#import <ComDocumentAIKit/ComDocumentAIKit.h>
+//#import <ComDocumentAIKit/ComDocumentAIKit.h>
 
 typedef NS_ENUM(NSInteger,CDocumentAIType) {
     CDocumentAITypeOCR,
@@ -23,7 +23,7 @@ typedef NS_ENUM(NSInteger,CDocumentAIType) {
 
 - (void)documentAIManager:(KMDocumentAIManager *)manager didStartImageAtIndex:(NSInteger)index;
 
-- (void)documentAIManager:(KMDocumentAIManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray<COCRResult *> *)results;
+//- (void)documentAIManager:(KMDocumentAIManager *)manager didFinishOCRImageAtIndex:(NSInteger)index results:(NSArray<COCRResult *> *)results;
 
 - (void)imageEngineManager:(KMDocumentAIManager *)manager didFinishCIImageAtIndex:(NSInteger)index outImage:(NSString *)filePath;
 
@@ -41,7 +41,7 @@ typedef NS_ENUM(NSInteger,CDocumentAIType) {
 
 + (KMDocumentAIManager *)defaultManager;
 
-- (void)recognitionImages:(NSArray *)images withModelType:(COCRModelType)modelType;
+//- (void)recognitionImages:(NSArray *)images withModelType:(COCRModelType)modelType;
 
 - (void)increaseImages:(NSArray *)images;
 

+ 104 - 104
PDF Office/PDF Office/Class/PDFTools/OCR/Manager/KMDocumentAIManager.m

@@ -9,15 +9,15 @@
 
 @interface KMDocumentAIManager ()
 
-@property (nonatomic, assign) COCRModelType modelType;
+//@property (nonatomic, assign) COCRModelType modelType;
 
 @property (nonatomic, assign) NSUInteger finishIndex;
 
 @property (nonatomic, retain) NSMutableArray *images;
 
-@property (nonatomic, retain) COCREngine * ocrEngine;
+//@property (nonatomic, retain) COCREngine * ocrEngine;
 
-@property (nonatomic, retain) CIMEngine * imEngine;
+//@property (nonatomic, retain) CIMEngine * imEngine;
 
 @end
 
@@ -39,95 +39,95 @@
     return singleton;
 }
 
-- (void)recognitionImages:(NSArray *)images withModelType:(COCRModelType)modelType {
-    self.finishIndex = 0;
-    [self.images removeAllObjects];;
-    [self.images addObjectsFromArray:images];
-
-    self.ocrEngine = [[COCREngine alloc] init];
-    [self.ocrEngine setModelWithType:modelType];
-    if(!self.ocrEngine) {
-        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:-1 userInfo:nil];
-        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
-            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
-        }
-
-        if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
-            [self.delegate documentAIDidFinish:self];
-        }
-    } else {
-
-        if(self.finishIndex < self.images.count) {
-            if([self.delegate respondsToSelector:@selector(documentAIManagerDidStart:)]) {
-                [self.delegate documentAIManagerDidStart:self];
-            }
-            [self recognitionImage:self.images[self.finishIndex]];
-        }
-    }
-}
+//- (void)recognitionImages:(NSArray *)images withModelType:(COCRModelType)modelType {
+//    self.finishIndex = 0;
+//    [self.images removeAllObjects];;
+//    [self.images addObjectsFromArray:images];
+//
+//    self.ocrEngine = [[COCREngine alloc] init];
+//    [self.ocrEngine setModelWithType:modelType];
+//    if(!self.ocrEngine) {
+//        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:-1 userInfo:nil];
+//        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
+//            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
+//        }
+//
+//        if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
+//            [self.delegate documentAIDidFinish:self];
+//        }
+//    } else {
+//
+//        if(self.finishIndex < self.images.count) {
+//            if([self.delegate respondsToSelector:@selector(documentAIManagerDidStart:)]) {
+//                [self.delegate documentAIManagerDidStart:self];
+//            }
+//            [self recognitionImage:self.images[self.finishIndex]];
+//        }
+//    }
+//}
 
 - (void)recognitionImage:(NSImage *)image {
-    NSString *fileName = [NSString stringWithFormat:@"%@.png", @"recognitionImage"];
-    NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
-    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
-        [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
-    }
-
-    [image.TIFFRepresentation writeToURL:[NSURL fileURLWithPath:filePath] atomically:YES];
-    NSMutableArray * tResults = [[NSMutableArray alloc] init];
-
-    COCRErrorType errorType = [self.ocrEngine processWithOCRImageInputPath:filePath andResult:tResults];
-    NSMutableArray * results = [[NSMutableArray alloc] init];
-    for (COCRResult * cOcrResult in tResults) {
-        CGRect rect = cOcrResult.textBounds;
-
-        rect.origin.y = image.size.height - cOcrResult.textBounds.origin.y;
-        cOcrResult.textBounds = rect;
-        [results addObject:cOcrResult];
-    }
-
-    if(CIMGErrorTypeNone == errorType) {
-        if([self.delegate respondsToSelector:@selector(documentAIManager:didFinishOCRImageAtIndex:results:)]) {
-            [self.delegate documentAIManager:self didFinishOCRImageAtIndex:self.finishIndex results:results];
-        }
-        self.finishIndex++;
-        if(self.finishIndex < self.images.count) {
-            [self recognitionImage:self.images[self.finishIndex]];
-        } else {
-            if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
-                [self.delegate documentAIDidFinish:self];
-            }
-        }
-    } else {
-        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:errorType userInfo:nil];
-        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
-            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
-        }
-    }
+//    NSString *fileName = [NSString stringWithFormat:@"%@.png", @"recognitionImage"];
+//    NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
+//    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+//        [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
+//    }
+//
+//    [image.TIFFRepresentation writeToURL:[NSURL fileURLWithPath:filePath] atomically:YES];
+//    NSMutableArray * tResults = [[NSMutableArray alloc] init];
+//
+//    COCRErrorType errorType = [self.ocrEngine processWithOCRImageInputPath:filePath andResult:tResults];
+//    NSMutableArray * results = [[NSMutableArray alloc] init];
+//    for (COCRResult * cOcrResult in tResults) {
+//        CGRect rect = cOcrResult.textBounds;
+//
+//        rect.origin.y = image.size.height - cOcrResult.textBounds.origin.y;
+//        cOcrResult.textBounds = rect;
+//        [results addObject:cOcrResult];
+//    }
+//
+//    if(CIMGErrorTypeNone == errorType) {
+//        if([self.delegate respondsToSelector:@selector(documentAIManager:didFinishOCRImageAtIndex:results:)]) {
+//            [self.delegate documentAIManager:self didFinishOCRImageAtIndex:self.finishIndex results:results];
+//        }
+//        self.finishIndex++;
+//        if(self.finishIndex < self.images.count) {
+//            [self recognitionImage:self.images[self.finishIndex]];
+//        } else {
+//            if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
+//                [self.delegate documentAIDidFinish:self];
+//            }
+//        }
+//    } else {
+//        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:errorType userInfo:nil];
+//        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
+//            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
+//        }
+//    }
 }
 
 - (void)increaseImages:(NSArray *)images {
     self.finishIndex = 0;
     [self.images removeAllObjects];;
     [self.images addObjectsFromArray:images];
-    self.imEngine = [[CIMEngine alloc] init];
-    if(!self.imEngine) {
-        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:-1 userInfo:nil];
-        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
-            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
-        }
-        
-        if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
-            [self.delegate documentAIDidFinish:self];
-        }
-    } else {
-        if(self.finishIndex < self.images.count) {
-            if([self.delegate respondsToSelector:@selector(documentAIManagerDidStart:)]) {
-                [self.delegate documentAIManagerDidStart:self];
-            }
-            [self increaseImage:self.images[self.finishIndex]];
-        }
-    }
+//    self.imEngine = [[CIMEngine alloc] init];
+//    if(!self.imEngine) {
+//        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:-1 userInfo:nil];
+//        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
+//            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
+//        }
+//
+//        if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
+//            [self.delegate documentAIDidFinish:self];
+//        }
+//    } else {
+//        if(self.finishIndex < self.images.count) {
+//            if([self.delegate respondsToSelector:@selector(documentAIManagerDidStart:)]) {
+//                [self.delegate documentAIManagerDidStart:self];
+//            }
+//            [self increaseImage:self.images[self.finishIndex]];
+//        }
+//    }
 }
 
 - (void)increaseImage:(NSImage *)image {
@@ -146,26 +146,26 @@
         [[NSFileManager defaultManager] removeItemAtPath:fileOutPath error:nil];
     }
     
-    [image.TIFFRepresentation writeToURL:[NSURL fileURLWithPath:filePath] atomically:YES];
-    CIMGErrorType errorType = [self.imEngine processWithInputPath:filePath andOutputPath:fileOutPath];
-    if(CIMGErrorTypeNone == errorType) {
-        if([self.delegate respondsToSelector:@selector(imageEngineManager:didFinishCIImageAtIndex:outImage:)]) {
-            [self.delegate imageEngineManager:self didFinishCIImageAtIndex:self.finishIndex outImage:fileOutPath];
-        }
-        self.finishIndex++;
-        if(self.finishIndex < self.images.count) {
-            [self increaseImage:self.images[self.finishIndex]];
-        } else {
-            if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
-                [self.delegate documentAIDidFinish:self];
-            }
-        }
-    } else {
-        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:errorType userInfo:nil];
-        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
-            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
-        }
-    }
+//    [image.TIFFRepresentation writeToURL:[NSURL fileURLWithPath:filePath] atomically:YES];
+//    CIMGErrorType errorType = [self.imEngine processWithInputPath:filePath andOutputPath:fileOutPath];
+//    if(CIMGErrorTypeNone == errorType) {
+//        if([self.delegate respondsToSelector:@selector(imageEngineManager:didFinishCIImageAtIndex:outImage:)]) {
+//            [self.delegate imageEngineManager:self didFinishCIImageAtIndex:self.finishIndex outImage:fileOutPath];
+//        }
+//        self.finishIndex++;
+//        if(self.finishIndex < self.images.count) {
+//            [self increaseImage:self.images[self.finishIndex]];
+//        } else {
+//            if([self.delegate respondsToSelector:@selector(documentAIDidFinish:)]) {
+//                [self.delegate documentAIDidFinish:self];
+//            }
+//        }
+//    } else {
+//        NSError *error = [NSError errorWithDomain:@"PDFReaderBatchErrorDomain" code:errorType userInfo:nil];
+//        if([self.delegate respondsToSelector:@selector(documentAIManager:didFailureImageAtIndex:error:)]) {
+//            [self.delegate documentAIManager:self didFailureImageAtIndex:self.finishIndex error:error];
+//        }
+//    }
 }
 
 @end

+ 2 - 2
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1417,8 +1417,8 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             self.documentAIViewController?.updateToolState(false)
         } else {
 //            self.documentAIViewController?.recognitionPageString("1", with: .english)
-            self.documentAIViewController?.recognitionPartModel(with: .english)
-            self.documentAIViewController?.updateToolState(true)
+//            self.documentAIViewController?.recognitionPartModel(with: .english)
+//            self.documentAIViewController?.updateToolState(true)
         }
         // 0 : Scan  1:OCR Text
     }

+ 1 - 1
PDF Office/PDF Office/PDF Office DMG-Bridging-Header.h

@@ -13,7 +13,7 @@
 #import "NSMenu+Category.h"
 #import "KMToolbar.h"
 #import <ComPDFKit_Conversion/ComPDFKit_Conversion.h>
-#import <ComDocumentAIKit/ComDocumentAIKit.h>
+//#import <ComDocumentAIKit/ComDocumentAIKit.h>
 
 #import "CPDFListView+Tool.h"
 #import "NSBitmapImageRep_SKExtensions.h"

+ 1 - 1
PDF Office/PDF Office/PDF Office Pro-Bridging-Header.h

@@ -13,7 +13,7 @@
 #import "NSMenu+Category.h"
 #import "KMToolbar.h"
 #import <ComPDFKit_Conversion/ComPDFKit_Conversion.h>
-#import <ComDocumentAIKit/ComDocumentAIKit.h>
+//#import <ComDocumentAIKit/ComDocumentAIKit.h>
 
 #import "CPDFListView+Tool.h"
 #import "NSBitmapImageRep_SKExtensions.h"

+ 1 - 1
PDF Office/PDF Office/PDF Office-Bridging-Header.h

@@ -14,7 +14,7 @@
 #import "NSMenu+Category.h"
 #import "KMToolbar.h"
 #import <ComPDFKit_Conversion/ComPDFKit_Conversion.h>
-#import <ComDocumentAIKit/ComDocumentAIKit.h>
+//#import <ComDocumentAIKit/ComDocumentAIKit.h>
 #import "CTTabContents.h"
 #import "CTBrowser.h"
 #import "CTBrowserWindowController.h"