KMDocumentAIPDFView.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. //
  2. // KMDocumentAIPDFView.m
  3. // PDF Master
  4. //
  5. // Created by 丁林圭 on 2023/2/2.
  6. //
  7. #import "KMDocumentAIPDFView.h"
  8. #import "NSGeometry+PDFListView.h"
  9. #import "KMDocumentAIPopViewController.h"
  10. #import <PDF_Master-Swift.h>
  11. #define DOCUMENT_SIZE 30.0
  12. @interface KMDocumentAIPDFView()<NSPopoverDelegate>
  13. //@property(nonatomic,retain) NSMutableArray<COCRResult *> * results;
  14. @property(nonatomic,assign) CGRect drawRecognitionEreaRect;
  15. @property(nonatomic,assign) CGRect recognitionEreaRect;
  16. @property (nonatomic, assign) NSUInteger selectionPageIndex;
  17. //@property (nonatomic, retain) COCRResult * activeResult;
  18. @property (nonatomic, assign) NSInteger activeResultIndex;
  19. @property (nonatomic, retain) CPDFPage * activeResultPage;
  20. @property (nonatomic, retain) NSPopover *popOver;
  21. @property (nonatomic, retain) KMDocumentAIPopViewController *documentAIPopViewController;
  22. @end
  23. @implementation KMDocumentAIPDFView
  24. - (NSPopover *)popOver {
  25. if(!_popOver) {
  26. _popOver = [[NSPopover alloc] init];
  27. _popOver.delegate = self;
  28. self.documentAIPopViewController = [[KMDocumentAIPopViewController alloc] initWithNibName:@"KMDocumentAIPopViewController" bundle:[NSBundle mainBundle]];
  29. _popOver.contentViewController = self.documentAIPopViewController;
  30. _popOver.animates = YES;
  31. __block typeof(self) blockSelf = self;
  32. self.documentAIPopViewController.callback = ^(NSInteger result) {
  33. if(result == 1) {
  34. // blockSelf.results[blockSelf.activeResultIndex].text = blockSelf.documentAIPopViewController.contentTextView.string?:@"";
  35. [blockSelf setNeedsDisplayAnnotationViewForPage:blockSelf.activeResultPage];
  36. }
  37. if(blockSelf.popOver.isShown)
  38. [blockSelf.popOver performClose:nil];
  39. };
  40. _popOver.behavior = NSPopoverBehaviorTransient;
  41. }
  42. return _popOver;
  43. }
  44. - (void)mouseDown:(NSEvent *)event {
  45. // if ([self doOCRResultWithEvent:event]) {
  46. // if(self.popOver.isShown) {
  47. // [self.popOver performClose:nil];
  48. // } else {
  49. // CGRect rect = [self convertRect:self.activeResult.textBounds fromPage:self.currentPage];
  50. // [self.popOver showRelativeToRect:rect ofView:self preferredEdge:NSRectEdgeMinY];
  51. // self.documentAIPopViewController.contentTextView.string = self.activeResult.text?:@"";
  52. // }
  53. // } else if ([self isRecognitionErea]) {
  54. // [self doSelectWithEvent:event];
  55. // }
  56. }
  57. //- (COCRResult *)doOCRResultWithEvent:(NSEvent *)theEvent {
  58. // COCRResult *result = nil;
  59. // NSPoint point = NSZeroPoint;
  60. // CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
  61. //
  62. // for (NSInteger i = 0;i<self.results.count;i++) {
  63. // COCRResult *tResult = self.results[i];
  64. // if(CGRectContainsPoint(tResult.textBounds, point)){
  65. // result = tResult;
  66. // self.activeResultIndex = i;
  67. // break;
  68. // }
  69. // }
  70. // if(result) {
  71. // self.activeResult = result;
  72. // self.activeResultPage = page;
  73. // } else {
  74. // self.activeResult = nil;
  75. // self.activeResultPage = nil;
  76. // self.activeResultIndex = -1;
  77. // }
  78. //
  79. // return result;
  80. //}
  81. - (void)mouseMoved:(NSEvent *)event {
  82. }
  83. - (void)keyDown:(NSEvent *)event {
  84. }
  85. - (void)mouseExited:(NSEvent *)event {
  86. }
  87. - (NSRect)recognitionRect {
  88. return self.recognitionEreaRect;
  89. }
  90. - (void)clearOCRResult {
  91. self.resultDics = @[].mutableCopy;
  92. [self setNeedsDisplayAnnotationViewForPage:self.currentPage];
  93. }
  94. - (void)doSelectWithEvent:(NSEvent *)theEvent {
  95. NSPoint initialPoint = NSZeroPoint;
  96. CPDFPage *page = [self pageAndPoint:&initialPoint forEvent:theEvent nearest:NO];
  97. CGFloat margin = DOCUMENT_SIZE / [self scaleFactor];
  98. self.selectionPageIndex = [page pageIndex];
  99. BOOL didSelect = (NO == NSIsEmptyRect(self.recognitionEreaRect));
  100. CRectEdges resizeHandle = didSelect ? CPDFListViewResizeHandleForPointFromRect(initialPoint, self.recognitionEreaRect, margin) : 0;
  101. if (resizeHandle == 0 && (didSelect == NO || NSPointInRect(initialPoint, self.recognitionEreaRect) == NO)) {
  102. self.recognitionEreaRect = CGRectMake(initialPoint.x, initialPoint.y, 0, 0);
  103. resizeHandle = CMaxXEdgeMask | CMinYEdgeMask;
  104. if (didSelect)
  105. [self setNeedsDisplay:YES];
  106. }
  107. NSRect initialRect = self.recognitionEreaRect;
  108. NSRect pageBounds = [page boundsForBox:[self displayBox]];
  109. CRectEdges newEffectiveResizeHandle, effectiveResizeHandle = resizeHandle;
  110. [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
  111. CGFloat mouseOffset = NSWidth([self convertRect:NSMakeRect(0.0, 0.0, 1.0, 1.0) toPage:page]);
  112. while (YES) {
  113. theEvent = [[self window] nextEventMatchingMask: NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged];
  114. if ([theEvent type] == NSEventTypeLeftMouseUp) {
  115. if (!NSIsEmptyRect(self.recognitionEreaRect)) {
  116. [NSMenu popUpContextMenu:[self menuForEvent:theEvent] withEvent:theEvent forView:self];
  117. }
  118. break;
  119. }
  120. CGPoint zPoint = initialPoint;
  121. [self pageAndPoint:&zPoint forEvent:theEvent nearest:YES];
  122. CGRect zRect = CGRectMake(initialPoint.x-2*mouseOffset, initialPoint.y-2*mouseOffset, 4*mouseOffset, 4*mouseOffset);
  123. if (CGRectContainsPoint(zRect, zPoint)) {continue;}
  124. NSPoint newPoint = CGPointZero;
  125. NSRect newRect = initialRect;
  126. NSPoint delta = CGPointZero;
  127. newPoint = [self convertPoint:[theEvent locationInPDFListView:self] toPage:page];
  128. delta = CPDFListViewSubstractPoints(newPoint, initialPoint);
  129. if (resizeHandle) {
  130. newEffectiveResizeHandle = 0;
  131. if ((resizeHandle & CMaxXEdgeMask))
  132. newEffectiveResizeHandle |= newPoint.x < NSMinX(initialRect) ? CMinXEdgeMask : CMaxXEdgeMask;
  133. else if ((resizeHandle & CMinXEdgeMask))
  134. newEffectiveResizeHandle |= newPoint.x > NSMaxX(initialRect) ? CMaxXEdgeMask : CMinXEdgeMask;
  135. if ((resizeHandle & CMaxYEdgeMask))
  136. newEffectiveResizeHandle |= newPoint.y < NSMinY(initialRect) ? CMinYEdgeMask : CMaxYEdgeMask;
  137. else if ((resizeHandle & CMinYEdgeMask))
  138. newEffectiveResizeHandle |= newPoint.y > NSMaxY(initialRect) ? CMaxYEdgeMask : CMinYEdgeMask;
  139. if (newEffectiveResizeHandle != effectiveResizeHandle) {
  140. effectiveResizeHandle = newEffectiveResizeHandle;
  141. [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(effectiveResizeHandle, page)];
  142. }
  143. }
  144. if (resizeHandle == CEditInEdgeMask) {
  145. newRect.origin = CPDFListViewAddPoints(newRect.origin, delta);
  146. } else if (([theEvent modifierFlags] & NSEventModifierFlagShift)) {
  147. CGFloat width = NSWidth(newRect);
  148. CGFloat height = NSHeight(newRect);
  149. CGFloat square;
  150. if ((resizeHandle & CMaxXEdgeMask))
  151. width += delta.x;
  152. else if ((resizeHandle & CMinXEdgeMask))
  153. width -= delta.x;
  154. if ((resizeHandle & CMaxYEdgeMask))
  155. height += delta.y;
  156. else if ((resizeHandle & CMinYEdgeMask))
  157. height -= delta.y;
  158. if (0 == (resizeHandle & (CMinXEdgeMask | CMaxXEdgeMask)))
  159. square = fabs(height);
  160. else if (0 == (resizeHandle & (CMinYEdgeMask | CMaxYEdgeMask)))
  161. square = fabs(width);
  162. else
  163. square = fmax(fabs(width), fabs(height));
  164. if ((resizeHandle & CMinXEdgeMask)) {
  165. if (width >= 0.0 && NSMaxX(newRect) - square < NSMinX(pageBounds))
  166. square = NSMaxX(newRect) - NSMinX(pageBounds);
  167. else if (width < 0.0 && NSMaxX(newRect) + square > NSMaxX(pageBounds))
  168. square = NSMaxX(pageBounds) - NSMaxX(newRect);
  169. } else {
  170. if (width >= 0.0 && NSMinX(newRect) + square > NSMaxX(pageBounds))
  171. square = NSMaxX(pageBounds) - NSMinX(newRect);
  172. else if (width < 0.0 && NSMinX(newRect) - square < NSMinX(pageBounds))
  173. square = NSMinX(newRect) - NSMinX(pageBounds);
  174. }
  175. if ((resizeHandle & CMinYEdgeMask)) {
  176. if (height >= 0.0 && NSMaxY(newRect) - square < NSMinY(pageBounds))
  177. square = NSMaxY(newRect) - NSMinY(pageBounds);
  178. else if (height < 0.0 && NSMaxY(newRect) + square > NSMaxY(pageBounds))
  179. square = NSMaxY(pageBounds) - NSMaxY(newRect);
  180. } else {
  181. if (height >= 0.0 && NSMinY(newRect) + square > NSMaxY(pageBounds))
  182. square = NSMaxY(pageBounds) - NSMinY(newRect);
  183. if (height < 0.0 && NSMinY(newRect) - square < NSMinY(pageBounds))
  184. square = NSMinY(newRect) - NSMinY(pageBounds);
  185. }
  186. if ((resizeHandle & CMinXEdgeMask))
  187. newRect.origin.x = width < 0.0 ? NSMaxX(newRect) : NSMaxX(newRect) - square;
  188. else if (width < 0.0 && (resizeHandle & CMaxXEdgeMask))
  189. newRect.origin.x = NSMinX(newRect) - square;
  190. if ((resizeHandle & CMinYEdgeMask))
  191. newRect.origin.y = height < 0.0 ? NSMaxY(newRect) : NSMaxY(newRect) - square;
  192. else if (height < 0.0 && (resizeHandle & CMaxYEdgeMask))
  193. newRect.origin.y = NSMinY(newRect) - square;
  194. newRect.size.width = newRect.size.height = square;
  195. } else {
  196. if ((resizeHandle & CMaxXEdgeMask)) {
  197. newRect.size.width += delta.x;
  198. if (NSWidth(newRect) < 0.0) {
  199. newRect.size.width *= -1.0;
  200. newRect.origin.x -= NSWidth(newRect);
  201. }
  202. } else if ((resizeHandle & CMinXEdgeMask)) {
  203. newRect.origin.x += delta.x;
  204. newRect.size.width -= delta.x;
  205. if (NSWidth(newRect) < 0.0) {
  206. newRect.size.width *= -1.0;
  207. newRect.origin.x -= NSWidth(newRect);
  208. }
  209. }
  210. if ((resizeHandle & CMaxYEdgeMask)) {
  211. newRect.size.height += delta.y;
  212. if (NSHeight(newRect) < 0.0) {
  213. newRect.size.height *= -1.0;
  214. newRect.origin.y -= NSHeight(newRect);
  215. }
  216. } else if ((resizeHandle & CMinYEdgeMask)) {
  217. newRect.origin.y += delta.y;
  218. newRect.size.height -= delta.y;
  219. if (NSHeight(newRect) < 0.0) {
  220. newRect.size.height *= -1.0;
  221. newRect.origin.y -= NSHeight(newRect);
  222. }
  223. }
  224. }
  225. newRect = CPDFListViewIntersectionRect(newRect, pageBounds);
  226. if (didSelect) {
  227. NSRect dirtyRect = NSUnionRect(NSInsetRect(self.recognitionEreaRect, -margin, -margin), NSInsetRect(newRect, -margin, -margin));
  228. [self setNeedsDisplayAnnotationInRect:dirtyRect];
  229. } else {
  230. [self setNeedsDisplayAnnotationViewForVisiblePages];
  231. didSelect = YES;
  232. }
  233. @synchronized (self) {
  234. self.recognitionEreaRect = newRect;
  235. }
  236. }
  237. if (NSIsEmptyRect(self.recognitionEreaRect)) {
  238. @synchronized (self) {
  239. self.recognitionEreaRect = NSZeroRect;
  240. self.selectionPageIndex = NSNotFound;
  241. }
  242. [self setNeedsDisplay:YES];
  243. } else if (resizeHandle) {
  244. [self setNeedsDisplayAnnotationInRect:NSInsetRect(self.recognitionEreaRect, -margin, -margin)];
  245. }
  246. }
  247. - (CPDFPage *)pageAndPoint:(NSPoint *)point forEvent:(NSEvent *)event nearest:(BOOL)nearest {
  248. NSPoint p = [event locationInPDFListView:self];
  249. CPDFPage *page = [self pageForPoint:p nearest:nearest];
  250. if (page && point)
  251. *point = [self convertPoint:p toPage:page];
  252. return page;
  253. }
  254. //- (void)updateResult:(NSArray<COCRResult *> *)results recognitionRect:(CGRect)recognitionRect {
  255. // self.results = [NSMutableArray arrayWithArray:results];
  256. // self.drawRecognitionEreaRect = recognitionRect;
  257. // [self setNeedsDisplayAnnotationViewForPage:self.currentPage];
  258. //}
  259. //
  260. //- (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context {
  261. // if(self.resultDics.count > 0) {
  262. // NSInteger currentIndex = [self.document indexForPage:page];
  263. // NSArray<COCRResult *> *currentResults = @[];
  264. // for (NSDictionary *dic in self.resultDics) {
  265. // if(dic[@"page"] && [dic[@"page"] integerValue] == currentIndex) {
  266. // if(dic[@"results"]) {
  267. // currentResults = dic[@"results"];
  268. // break;
  269. // }
  270. // }
  271. // }
  272. // if (currentResults.count>0) {
  273. // [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:context flipped:NO]];
  274. //
  275. // CGContextSaveGState(context);
  276. // CGContextAddRect(context, self.drawRecognitionEreaRect);
  277. // CGContextSetRGBFillColor(context, 1, 1, 1, 0.7);
  278. // CGContextFillPath(context);
  279. // CGContextRestoreGState(context);
  280. //
  281. // NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  282. // [dic setValue:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
  283. //
  284. // for (COCRResult * cOcrResult in currentResults) {
  285. // CGContextSaveGState(context);
  286. //
  287. // CGRect rect = cOcrResult.textBounds;
  288. //
  289. // NSString *strChar = cOcrResult.text;
  290. // CGFloat fontsize = 1.0;
  291. // NSFont *font = [NSFont systemFontOfSize:fontsize];
  292. // CGSize strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
  293. // while ((fontsize<127) && !(strSize.width>=cOcrResult.textBounds.size.width || strSize.height>=cOcrResult.textBounds.size.height)) {
  294. // fontsize += 1.0;
  295. // font = [NSFont systemFontOfSize:fontsize];
  296. // strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:font}];
  297. // }
  298. // NSFont *drawFont = [NSFont systemFontOfSize:fontsize-1];
  299. //
  300. // strSize = [strChar sizeWithAttributes:@{NSFontAttributeName:drawFont}];
  301. // CGFloat k = (cOcrResult.textBounds.size.width - strSize.width)/(strChar.length);
  302. //
  303. // NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  304. //
  305. // NSDictionary *attriDict = @{NSParagraphStyleAttributeName:style,NSKernAttributeName:@(k),NSFontAttributeName:drawFont};
  306. //
  307. // NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:strChar attributes:attriDict];
  308. // [attributeString drawInRect:rect];
  309. //
  310. // CGContextAddRect(context, rect);
  311. // CGContextSetLineWidth(context, 1.0);
  312. // CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0].CGColor);
  313. // CGContextStrokePath(context);
  314. //
  315. // CGContextRestoreGState(context);
  316. // }
  317. // }
  318. //
  319. // }
  320. //
  321. // if(!CGRectEqualToRect(self.recognitionEreaRect, CGRectZero)) {
  322. // @synchronized (self) {
  323. // CGContextSaveGState(context);
  324. //
  325. // CGFloat size = DOCUMENT_SIZE;
  326. // CGContextSetLineWidth(context, 5.0);
  327. // CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
  328. //
  329. // CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
  330. // CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
  331. //
  332. // CGContextMoveToPoint(context, CGRectGetMidX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
  333. // CGContextAddLineToPoint(context, CGRectGetMidX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
  334. //
  335. // CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
  336. // CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
  337. //
  338. // CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)-size/2);
  339. // CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMidY(self.recognitionEreaRect)+size/2);
  340. //
  341. // CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMinY(self.recognitionEreaRect));
  342. // CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
  343. // CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
  344. //
  345. // CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMinY(self.recognitionEreaRect));
  346. // CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect));
  347. // CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMinY(self.recognitionEreaRect)+ size/2);
  348. //
  349. // CGContextMoveToPoint(context, CGRectGetMinX(self.recognitionEreaRect)+size/2, CGRectGetMaxY(self.recognitionEreaRect));
  350. // CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
  351. // CGContextAddLineToPoint(context, CGRectGetMinX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
  352. //
  353. // CGContextMoveToPoint(context, CGRectGetMaxX(self.recognitionEreaRect)-size/2, CGRectGetMaxY(self.recognitionEreaRect));
  354. // CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect));
  355. // CGContextAddLineToPoint(context, CGRectGetMaxX(self.recognitionEreaRect), CGRectGetMaxY(self.recognitionEreaRect) - size/2);
  356. //
  357. // CGContextStrokePath(context);
  358. //
  359. // CGContextSetLineCap(context, kCGLineCapRound);
  360. // CGContextSetLineWidth(context, 2.0);
  361. // CGContextRestoreGState(context);
  362. //
  363. // CGContextSetStrokeColorWithColor(context, [NSColor colorWithRed:23.0/255.0 green:112.0/255.0 blue:244.0/255.0 alpha:1.0].CGColor);
  364. // CGContextBeginPath(context);
  365. // CGContextMoveToPoint(context, self.recognitionEreaRect.origin.x, self.recognitionEreaRect.origin.y);
  366. // CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x+ self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y);
  367. // CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x + self.recognitionEreaRect.size.width,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
  368. // CGContextAddLineToPoint(context, self.recognitionEreaRect.origin.x,self.recognitionEreaRect.origin.y + + self.recognitionEreaRect.size.height);
  369. // CGContextClosePath(context);
  370. // CGFloat lengths[] = {10,5};
  371. // CGContextSetLineDash(context, 0, lengths,2);
  372. // CGContextStrokePath(context);
  373. // }
  374. // }
  375. //}
  376. #pragma Mark - menuForEvent
  377. -(NSMenu *)menuForEvent:(NSEvent *)event {
  378. NSMenu *menu = [[NSMenu alloc]init];
  379. if(self.isRecognitionErea && !NSEqualRects(NSZeroRect, self.recognitionEreaRect)) {
  380. NSMenuItem * sureMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Start OCR text recognition", nil) action:@selector(menuItemClick_StartOCR:) keyEquivalent:@""];
  381. [menu addItem:sureMenuItem];
  382. }
  383. return menu;
  384. }
  385. -(void)menuItemClick_StartOCR:(NSMenuItem *)item {
  386. if (self.callback) {
  387. self.callback(self.recognitionEreaRect,self.currentPage);
  388. }
  389. self.recognitionEreaRect = CGRectZero;
  390. [self setNeedsDisplayAnnotationViewForPage:self.currentPage];
  391. }
  392. @end