Переглянути джерело

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

tangchao 1 рік тому
батько
коміт
088a77e4a8
16 змінених файлів з 620 додано та 539 видалено
  1. 0 62
      PDF Office/PDF Office.xcodeproj/project.pbxproj
  2. 1 1
      PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIPDFView.h
  3. 160 160
      PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIPDFView.m
  4. 3 3
      PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIViewController.h
  5. 92 92
      PDF Office/PDF Office/Class/PDFTools/OCR/KMDocumentAIViewController.m
  6. 3 3
      PDF Office/PDF Office/Class/PDFTools/OCR/Manager/KMDocumentAIManager.h
  7. 104 104
      PDF Office/PDF Office/Class/PDFTools/OCR/Manager/KMDocumentAIManager.m
  8. 2 2
      PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/BookMarks/KMBookMarkViewController.swift
  9. 72 63
      PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineViewController.swift
  10. 134 35
      PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift
  11. 37 9
      PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMFillSignTextPanel.swift
  12. 6 0
      PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMPropertiesPanelSubViewController.swift
  13. 2 2
      PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift
  14. 1 1
      PDF Office/PDF Office/PDF Office DMG-Bridging-Header.h
  15. 1 1
      PDF Office/PDF Office/PDF Office Pro-Bridging-Header.h
  16. 2 1
      PDF Office/PDF Office/PDF Office-Bridging-Header.h

+ 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/Side/LeftSide/BookMarks/KMBookMarkViewController.swift

@@ -8,7 +8,7 @@
 import Cocoa
 import PDFKit
 
-class KMBookMarkViewController: NSViewController, NSTextFieldDelegate,NSMenuItemValidation {
+class KMBookMarkViewController: NSViewController, NSTextFieldDelegate {
 
     @IBOutlet weak var addBookButton: NSButton!
     @IBOutlet weak var titleTextField: NSTextField!
@@ -398,7 +398,7 @@ extension KMBookMarkViewController {
     }
 }
 
-extension KMBookMarkViewController : NSMenuDelegate {
+extension KMBookMarkViewController: NSMenuDelegate, NSMenuItemValidation {
     func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
         let action = menuItem.action
         if (action == #selector(undo)) {

+ 72 - 63
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineViewController.swift

@@ -7,7 +7,7 @@
 
 import Cocoa
 
-class KMOutlineViewController: NSViewController,NSMenuItemValidation {
+class KMOutlineViewController: NSViewController {
   
     @IBOutlet var contendView: NSView!
     @IBOutlet weak var outlineView: NSOutlineView!
@@ -509,68 +509,6 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
         }
     }
     
-    //MARK: NSMenuItemValidation
-    
-    func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
-        let action = menuItem.action
-        if action == #selector(addItemAction) ||
-            action == #selector(addChildItemAction) ||
-            action == #selector(addHigherItemAction) ||
-            action == #selector(deleteItemAction) ||
-            action == #selector(editItemAction) ||
-            action == #selector(changeItemAction) ||
-            action == #selector(renameItemAction) ||
-            action == #selector(promoteItemAction) ||
-            action == #selector(demoteItemAction) {
-            if self.outlineView.selectedRowIndexes.count > 1 {
-                if action == #selector(deleteItemAction) {
-                    return true
-                }
-                return false
-            } else if self.outlineView.selectedRowIndexes.count > 0 {
-                if action == #selector(addChildItemAction) || action == #selector(changeItemAction) {
-                    return true
-                }
-            }
-            if self.outlineView.clickedRow == -1 {
-                if action == #selector(addItemAction) {
-                    return true
-                } else {
-                    return false
-                }
-            } else {
-                let outline : CPDFOutline = self.outlineView.item(atRow: self.outlineView.clickedRow) as! CPDFOutline
-                if outline.index > 0 {
-                    if action == #selector(demoteItemAction) {
-                        return true
-                    }
-                } else {
-                    if action == #selector(demoteItemAction) {
-                        return false
-                    }
-                }
-                
-                let parentOutline = outline.parent
-                let grandparentOutline = parentOutline?.parent
-                if grandparentOutline != nil {
-                    if action == #selector(addHigherItemAction) {
-                        return true
-                    } else if action == #selector(promoteItemAction) {
-                        return true
-                    }
-                } else {
-                    if action == #selector(addHigherItemAction) {
-                        return false
-                    } else if action == #selector(promoteItemAction) {
-                        return false
-                    }
-                }
-            }
-            return true
-        }
-        return true
-    }
-    
     
     //MARK: Noti
     @objc func KMPDFViewCurrentPageDidChangedNotification(notification: NSNotification) {
@@ -767,6 +705,77 @@ extension KMOutlineViewController : NSPopoverDelegate {
     }
 }
 
+extension KMOutlineViewController: NSMenuDelegate, NSMenuItemValidation {
+    //MARK: NSMenuItemValidation
+    
+    func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
+        let action = menuItem.action
+        if action == #selector(addItemAction) ||
+            action == #selector(addChildItemAction) ||
+            action == #selector(addHigherItemAction) ||
+            action == #selector(deleteItemAction) ||
+            action == #selector(editItemAction) ||
+            action == #selector(changeItemAction) ||
+            action == #selector(renameItemAction) ||
+            action == #selector(promoteItemAction) ||
+            action == #selector(demoteItemAction) {
+            if self.outlineView.selectedRowIndexes.count > 1 {
+                if action == #selector(deleteItemAction) {
+                    return true
+                }
+                return false
+            } else if self.outlineView.selectedRowIndexes.count > 0 {
+                if action == #selector(addChildItemAction) || action == #selector(changeItemAction) {
+                    return true
+                }
+            }
+            if self.outlineView.clickedRow == -1 {
+                if action == #selector(addItemAction) {
+                    return true
+                } else {
+                    return false
+                }
+            } else {
+                let outline : CPDFOutline = self.outlineView.item(atRow: self.outlineView.clickedRow) as! CPDFOutline
+                if outline.index > 0 {
+                    if action == #selector(demoteItemAction) {
+                        return true
+                    }
+                } else {
+                    if action == #selector(demoteItemAction) {
+                        return false
+                    }
+                }
+                
+                let parentOutline = outline.parent
+                let grandparentOutline = parentOutline?.parent
+                if grandparentOutline != nil {
+                    if action == #selector(addHigherItemAction) {
+                        return true
+                    } else if action == #selector(promoteItemAction) {
+                        return true
+                    }
+                } else {
+                    if action == #selector(addHigherItemAction) {
+                        return false
+                    } else if action == #selector(promoteItemAction) {
+                        return false
+                    }
+                }
+            }
+            return true
+        }
+        
+        if (action == #selector(undo)) {
+            return self.undoRedoManager.canUndo
+        }
+        if (action == #selector(redo)) {
+            return self.undoRedoManager.canRedo
+        }
+        return true
+    }
+}
+
 //MARK: undoRedo
 extension KMOutlineViewController {
     func movePDFOutline(outline : CPDFOutline! , toIndex index : NSInteger , atParent parent : CPDFOutline!) {

+ 134 - 35
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift

@@ -145,35 +145,28 @@ class KMThumbnailViewController: NSViewController {
             return
         }
         
-        // 插入位置偏移量
-        var toIndexOffset: Int = 0
-        // 需要移动的页面index数组
-        var newPages: [CPDFPage] = []
+        //获取原有page的下标 和 开始添加的下标
+        var indexTemp: Int = toIndex
+        var pageItems: [KMThumbnailPageItem] = []
         for index in indexs {
             let newPage: CPDFPage = self.listView?.document.page(at: UInt(index)).copy() as! CPDFPage
-            newPages.append(newPage)
-            self.listView?.document.removePage(at: UInt(index))
-            if (index < toIndex) { /// 删除了插入位置前面的页面,需要改变 toIndex
-                toIndexOffset += 1
+            let pageItem = KMThumbnailPageItem(page: newPage, index: index, oldIndex: index)
+            pageItems.append(pageItem)
+            if (toIndex > index) { /// 删除了插入位置前面的页面,需要改变 toIndex
+                indexTemp -= 1
             }
         }
         
-        let insertIndex = max(0, toIndex-toIndexOffset)
-        for (index, page) in newPages.enumerated() {
-            self.listView?.document.insertPageObject(page, at: UInt(insertIndex+index))
+        //建立模型
+        var tPageItems: [KMThumbnailPageItem] = []
+        for index in 0...pageItems.count - 1 {
+            let pageItem: KMThumbnailPageItem = pageItems[index]
+            let tItem = KMThumbnailPageItem(page: pageItem.page, index: indexTemp + index, oldIndex: pageItem.index)
+            tPageItems.append(tItem)
         }
         
-        // 新增 undo
-//        self.undoRedoManager.registerUndo(withTarget: self) { target in
-//            target.dragPages_reversed(indexs, toIndex, newPages)
-//        }
-        
-        // 刷新UI
-        self.listView?.layoutDocumentView()
-//        self.thumbnailView.refreshUI()
-        
-        self.thumbnailView.reloadData()
-        
+        //进行移动
+        self.dragPageItems(pageItems: tPageItems)
     }
     
     //MARK: Noti
@@ -495,10 +488,7 @@ class KMThumbnailViewController: NSViewController {
     @IBAction func deletePageItemAction(menu:NSMenuItem) {
         let indexs = self.thumbnailView.collectionView.selectionIndexes
         if indexs.count > 0 {
-            self.listView.document.removePage(at: indexs)
-            self.listView.layoutDocumentView()
-            self.thumbnailView.reloadData()
-            self.pdfCurrentPageChange()
+            self.deletePageItemWithIndex(indexs: indexs)
         }
     }
     
@@ -546,23 +536,21 @@ class KMThumbnailViewController: NSViewController {
                 let page = self.thumbnailView.document.page(at: UInt(i))
                 self.copysPages.append(page ?? CPDFPage())
             }
-            self.listView.document.removePage(at: indexs)
-            self.listView.layoutDocumentView()
-            self.thumbnailView.reloadData()
+            
+            self.deletePageItemWithIndex(indexs: indexs)
         }
     }
     
     @IBAction func pastePageItemAction(menu:NSMenuItem) {
         var index = (self.thumbnailView.collectionView.selectionIndexes).last ?? -1
         if Int(index) >= 0 && self.copysPages.count > 0 {
+            var pageItems: [KMThumbnailPageItem] = []
             for page in self.copysPages {
-               let result = self.thumbnailView.document.insertPageObject(page, at: UInt(index))
-                if result {
-                    index = index + 1
-                }
+                let pageItem = KMThumbnailPageItem(page: page, index: index, oldIndex: index)
+                index = index + 1
+                pageItems.append(pageItem)
             }
-            self.listView.layoutDocumentView()
-            self.thumbnailView.reloadData()
+            self.addPageItems(pageItems: pageItems)
         }
     }
     
@@ -646,6 +634,13 @@ extension KMThumbnailViewController : NSMenuDelegate,NSMenuItemValidation {
             }
             return false
         }
+        
+        if (action == #selector(undo)) {
+            return self.undoRedoManager.canUndo
+        }
+        if (action == #selector(redo)) {
+            return self.undoRedoManager.canRedo
+        }
         return true
     }
     
@@ -734,3 +729,107 @@ extension KMThumbnailViewController : NSMenuDelegate,NSMenuItemValidation {
         
     }
 }
+
+//MARK: undoRedo
+extension KMThumbnailViewController {
+    func rotatePageItemWithIndex(indexs: IndexSet) {
+        var pageItems: [KMThumbnailPageItem] = []
+        for index in indexs {
+            let page: CPDFPage = self.listView.document.page(at: UInt(index))
+            let pageItem = KMThumbnailPageItem(page: page, index: index, oldIndex: index)
+            pageItems.append(pageItem)
+        }
+        self.deletePageItems(pageItems: pageItems)
+    }
+    
+    func deletePageItemWithIndex(indexs: IndexSet) {
+        var pageItems: [KMThumbnailPageItem] = []
+        for index in indexs {
+            let page: CPDFPage = self.listView.document.page(at: UInt(index))
+            let pageItem = KMThumbnailPageItem(page: page, index: index, oldIndex: index)
+            pageItems.append(pageItem)
+        }
+        self.deletePageItems(pageItems: pageItems)
+    }
+    
+    func deletePageItems(pageItems: [KMThumbnailPageItem]) {
+        //移除现有
+        var tempPageItems = pageItems
+        tempPageItems.sort(){$0.oldIndex > $1.oldIndex}
+        for pageItem in tempPageItems {
+            self.listView?.document.removePage(at: UInt(pageItem.oldIndex))
+        }
+        self.listView.layoutDocumentView()
+        self.thumbnailView.reloadData()
+        self.pdfCurrentPageChange()
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+            self.addPageItems(pageItems: tempPageItems)
+        }
+    }
+    
+    func addPageItems(pageItems: [KMThumbnailPageItem]) {
+        var tempPageItems = pageItems
+        tempPageItems.sort(){$0.oldIndex < $1.oldIndex}
+        for pageItem in tempPageItems {
+            self.listView?.document.insertPageObject(pageItem.page, at: UInt(pageItem.oldIndex))
+        }
+        self.listView.layoutDocumentView()
+        self.thumbnailView.reloadData()
+        self.pdfCurrentPageChange()
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+            self.deletePageItems(pageItems: tempPageItems)
+        }
+    }
+    
+    
+    func dragPageItems(pageItems: [KMThumbnailPageItem]) {
+        var tempPageItems = pageItems
+        //按照原下标顺序
+        tempPageItems.sort(){$0.oldIndex > $1.oldIndex}
+        //移除现有
+        for pageItem in tempPageItems {
+            self.listView?.document.removePage(at: UInt(pageItem.oldIndex))
+        }
+        //在原位置添加
+        tempPageItems.sort(){$0.index < $1.index}
+        for pageItem in tempPageItems {
+            self.listView?.document.insertPageObject(pageItem.page, at: UInt(pageItem.index))
+        }
+        
+        // 刷新UI
+        self.listView?.layoutDocumentView()
+        self.thumbnailView.reloadData()
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+            //替换下标顺序
+            var tempPageItems: [KMThumbnailPageItem] = []
+            for pageItem in pageItems {
+                let item = KMThumbnailPageItem(page: pageItem.page, index: pageItem.oldIndex, oldIndex: pageItem.index)
+                tempPageItems.append(item)
+            }
+            self.dragPageItems(pageItems: tempPageItems)
+        }
+    }
+    
+    @IBAction func undo(_ sender: Any) {
+        if (self.undoRedoManager.canUndo) {
+            self.undoRedoManager.undo()
+        }
+    }
+    
+    @IBAction func redo(_ sender: Any) {
+        if (self.undoRedoManager.canRedo) {
+            self.undoRedoManager.redo()
+        }
+    }
+    
+    struct KMThumbnailPageItem {
+        var page: CPDFPage
+        var index: Int = 0
+        var oldIndex: Int = 0
+        var rotate: Int = 0
+        var oldRotate: Int = 0
+    }
+}

+ 37 - 9
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMFillSignTextPanel.swift

@@ -127,6 +127,28 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
         initLocalization()
         
         refreshUI()
+        
+        customVC1.fillColor = annotationModel.fontColor()
+        colorVC5.fillColor = annotationModel.color() ?? .clear
+
+        if (annotationModel.color() == nil) {
+            colorVC1.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[1]) {
+            colorVC2.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[2]) {
+            colorVC3.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[3]) {
+            colorVC4.state = .Sel
+        }
+        if (annotationModel.alignment() == .left) {
+            leftVC.state = .Sel
+        } else if (annotationModel.alignment() == .center) {
+            centerVC.state = .Sel
+        } else if (annotationModel.alignment() == .right) {
+            rightVC.state = .Sel
+        }
+        self.opacitySlider.floatValue = Float(self.annotationModel.opacity())
+        self.opacityVC.stringValue = String(format: "%f", self.annotationModel.opacity())
     }
     
     func initializeUI() {
@@ -281,14 +303,12 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
     
     func refreshUI() -> Void {
         previewImageView.image = annotationModel.annotationImage
-        customVC1.fillColor = annotationModel.fontColor()
         
         if annotationModel.annotationType == .signDate {
             colorVC1.fillColor = self.colors[0]
             colorVC2.fillColor = self.colors[1]
             colorVC3.fillColor = self.colors[2]
             colorVC4.fillColor = self.colors[3]
-            colorVC5.fillColor = annotationModel.color() ?? .clear
             
             let includeTime = self.annotationModel.includeTime()
             dateTypeVC.addItems(withObjectValues: KMSelfSignAnnotationFreeText.fetchAllDateString(includeTime) as! [String])
@@ -384,21 +404,29 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
         NSColorPanel.shared.setTarget(nil)
         NSColorPanel.shared.setTarget(self)
         NSColorPanel.shared.showsAlpha = true
-        NSColorPanel.shared.setAction(#selector(colorPanelAction(_:)))
-        NSColorPanel.shared.orderFront(nil)
-    }
-    
-    @IBAction func colorPanelAction(_ sender: NSButton) {
         if (sender == customVC2.button) {
-            annotationModel.setFontColor(NSColorPanel.shared.color)
+            NSColorPanel.shared.setAction(#selector(colorPanelAction1(_:)))
         } else if (sender == fillCustomVC.button) {
-            annotationModel.setColor(NSColorPanel.shared.color)
+            NSColorPanel.shared.setAction(#selector(colorPanelAction2(_:)))
         }
+        NSColorPanel.shared.orderFront(nil)
+    }
+    
+    @IBAction func colorPanelAction1(_ sender: NSColorPanel) {
+        annotationModel.setFontColor(sender.color)
+        customVC1.fillColor = annotationModel.fontColor()
 
         refreshUI()
         updateAnnotation()
     }
     
+    @IBAction func colorPanelAction2(_ sender: NSColorPanel) {
+        annotationModel.setColor(sender.color)
+        colorVC5.fillColor = annotationModel.color() ?? .clear
+
+        refreshUI()
+        updateAnnotation()
+    }
     @IBAction func showOpacityView(_ sender: NSButton) {
         if (fillColorSubBox.contentView == self.opacityView) {
             fillColorSubBox.contentView = fillColorSubView

+ 6 - 0
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMPropertiesPanelSubViewController.swift

@@ -28,6 +28,12 @@ import Cocoa
     func updateAnnotation() -> Void {
         let annotation = self.annotationModel.annotation
         if annotation != nil {
+            if (annotation is CSelfSignAnnotationFreeText) {
+                let textNote = annotation as! CSelfSignAnnotationFreeText
+                if self.pdfView.isEdit(withCurrentFreeText: textNote) {
+                    self.pdfView.commitEditAnnotationFreeText(textNote)
+                }
+            }
             for tAnnotation in self.annotationModel.annotations {
 //                if (tAnnotation is CPDFStampAnnotation) {
 //                    (tAnnotation as! KMSelfSignAnnotation).updateAppearanceStream()

+ 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"

+ 2 - 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"
@@ -73,3 +73,4 @@
 #import "SKInfoWindowController.h"
 #import "SKKeychain.h"
 #import "NSColor_SKExtensions.h"
+#import "CSelfSignAnnotationFreeText.h"