CPDFViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. //
  2. // CPDFViewController.m
  3. // ContentEditor
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFViewController.h"
  13. #import <ComPDFKit/ComPDFKit.h>
  14. #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
  15. #import <AVFAudio/AVFAudio.h>
  16. #import <AVFoundation/AVFoundation.h>
  17. @interface CPDFViewController () <CPDFSoundPlayBarDelegate,CPDFAnnotationBarDelegate,CPDFToolsViewControllerDelegate,CPDFNoteOpenViewControllerDelegate,CPDFBOTAViewControllerDelegate,CPDFKeyboardToolbarDelegate>
  18. @property(nonatomic, strong) CPDFAnnotationToolBar *annotationBar;
  19. @property(nonatomic, strong) CPDFSoundPlayBar *soundPlayBar;
  20. @property(nonatomic, strong) CAnnotationManage *annotationManage;
  21. @end
  22. @implementation CPDFViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.pdfListView.toolModel = CToolModelAnnotation;
  26. self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
  27. [self initAnnotationBar];
  28. [self enterAnnotationMode];
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PDFPageDidRemoveAnnotationNotification:) name:CPDFPageDidRemoveAnnotationNotification object:nil];
  30. }
  31. - (void)initAnnotationBar {
  32. self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:self.pdfListView];
  33. self.annotationBar = [[CPDFAnnotationToolBar alloc] initAnnotationManage:self.annotationManage];
  34. CGFloat height = 44.0;
  35. if (@available(iOS 11.0, *))
  36. height += self.view.safeAreaInsets.bottom;
  37. self.annotationBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
  38. self.annotationBar.delegate = self;
  39. [self.annotationBar setParentVC:self];
  40. [self.view addSubview:self.annotationBar];
  41. }
  42. - (void)initWitNavigationTitle {
  43. //titleButton
  44. CNavigationBarTitleButton * navTitleButton = [[CNavigationBarTitleButton alloc] init];
  45. self.titleButton = navTitleButton;
  46. self.navigationTitle = NSLocalizedString(@"Annotation", nil);
  47. [navTitleButton setImage:[UIImage imageNamed:@"syasarrow"] forState:UIControlStateNormal];
  48. [navTitleButton addTarget:self action:@selector(titleButtonClickd:) forControlEvents:UIControlEventTouchUpInside];
  49. [navTitleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
  50. [navTitleButton setTitleColor:[CPDFColorUtils CAnyReverseBackgooundColor] forState:UIControlStateNormal];
  51. self.titleButton.frame = CGRectMake(0, 0, 50, 30);
  52. self.navigationItem.titleView = self.titleButton;
  53. }
  54. - (void)viewWillLayoutSubviews {
  55. [super viewWillLayoutSubviews];
  56. if([self.popMenu superview]) {
  57. if (@available(iOS 11.0, *)) {
  58. [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 250)];
  59. } else {
  60. // Fallback on earlier versions
  61. [self.popMenu showMenuInRect:CGRectMake(self.view.frame.size.width - 250, CGRectGetMaxY(self.navigationController.navigationBar.frame), 250, 250)];
  62. }
  63. }
  64. CGFloat height = 44.0;
  65. if (@available(iOS 11.0, *))
  66. height += self.view.safeAreaInsets.bottom;
  67. if(CToolModelAnnotation == self.pdfListView.toolModel) {
  68. if (@available(iOS 11.0, *)) {
  69. self.annotationBar.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.frame.size.height - height, self.view.frame.size.width- self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, height);
  70. } else {
  71. self.annotationBar.frame = CGRectMake(0, self.view.frame.size.height - height, self.view.frame.size.width, height);
  72. }
  73. } else {
  74. self.annotationBar.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width, height);
  75. }
  76. CGFloat tPosY = 0;
  77. CGFloat tBottomY = 0;
  78. if(CToolModelAnnotation == self.pdfListView.toolModel) {
  79. if (!self.navigationController.navigationBarHidden) {
  80. [UIView animateWithDuration:0.3 animations:^{
  81. CGRect frame = self.annotationBar.frame;
  82. frame.origin.y = self.view.bounds.size.height-frame.size.height;
  83. self.annotationBar.frame = frame;
  84. }];
  85. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  86. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  87. tBottomY = self.annotationBar.frame.size.height;
  88. } else {
  89. [UIView animateWithDuration:0.3 animations:^{
  90. CGRect frame = self.annotationBar.frame;
  91. frame.origin.y = self.view.bounds.size.height;
  92. self.annotationBar.frame = frame;
  93. }];
  94. }
  95. } else {
  96. tPosY = 0;
  97. if (!self.navigationController.navigationBarHidden) {
  98. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  99. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  100. }
  101. }
  102. if (CPDFDisplayDirectionVertical == [CPDFKitConfig sharedInstance].displayDirection) {
  103. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  104. inset.bottom = 10 + self.annotationBar.frame.size.height;
  105. self.pdfListView.documentView.contentInset = inset;
  106. } else{
  107. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  108. inset.bottom = 0;
  109. self.pdfListView.documentView.contentInset = inset;
  110. }
  111. }
  112. #pragma mark - Public Methods
  113. - (void)selectDocumentRefresh {
  114. self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
  115. [self.annotationBar updatePropertiesButtonState];
  116. [self.annotationBar reloadData];
  117. [self.annotationBar updateUndoRedoState];
  118. }
  119. #pragma mark - Private Methods
  120. - (void)enterAnnotationMode {
  121. self.pdfListView.toolModel = CToolModelAnnotation;
  122. self.navigationTitle = NSLocalizedString(@"Annotation", nil);
  123. [self.titleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
  124. CGFloat tPosY = 0;
  125. CGFloat tBottomY = 0;
  126. CGRect frame = self.annotationBar.frame;
  127. frame.origin.y = self.view.bounds.size.height-frame.size.height;
  128. self.annotationBar.frame = frame;
  129. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  130. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  131. tBottomY = self.annotationBar.frame.size.height;
  132. if (CPDFDisplayDirectionVertical == [CPDFKitConfig sharedInstance].displayDirection) {
  133. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  134. inset.bottom = 10 + self.annotationBar.frame.size.height;
  135. self.pdfListView.documentView.contentInset = inset;
  136. } else{
  137. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  138. inset.bottom = 0;
  139. self.pdfListView.documentView.contentInset = inset;
  140. }
  141. }
  142. - (void)enterViewerMode {
  143. if (self.pdfListView.isEdited) {
  144. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  145. [self.pdfListView commitEditing];
  146. dispatch_async(dispatch_get_main_queue(), ^{
  147. [self.pdfListView endOfEditing];
  148. });
  149. });
  150. } else {
  151. [self.pdfListView endOfEditing];
  152. }
  153. self.pdfListView.toolModel = CToolModelViewer;
  154. self.navigationTitle = NSLocalizedString(@"Viewer", nil);
  155. [self.titleButton setTitle:self.navigationTitle forState:UIControlStateNormal];
  156. CGRect frame = self.annotationBar.frame;
  157. frame.origin.y = self.view.bounds.size.height;
  158. self.annotationBar.frame = frame;
  159. if (CPDFDisplayDirectionVertical == [CPDFKitConfig sharedInstance].displayDirection) {
  160. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  161. inset.bottom = 10 + self.annotationBar.frame.size.height;
  162. self.pdfListView.documentView.contentInset = inset;
  163. } else{
  164. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  165. inset.bottom = 0;
  166. self.pdfListView.documentView.contentInset = inset;
  167. }
  168. }
  169. - (void)titleButtonClickd:(UIButton *) button {
  170. CPDFToolsViewController * toolsVc = [[CPDFToolsViewController alloc] initCustomizeWithToolArrays:@[@(CToolModelViewer),@(CToolModelAnnotation)]];
  171. toolsVc.delegate = self;
  172. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  173. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:toolsVc presentingViewController:self];
  174. toolsVc.transitioningDelegate = presentationController;
  175. [self presentViewController:toolsVc animated:YES completion:nil];
  176. }
  177. - (void)navigationRightItemBota {
  178. CPDFBOTAViewController *botaViewController = [[CPDFBOTAViewController alloc] initCustomizeWithPDFView:self.pdfListView navArrays:@[@(CPDFBOTATypeStateOutline),@(CPDFBOTATypeStateBookmark),@(CPDFBOTATypeStateAnnotation)]];
  179. botaViewController.delegate = self;
  180. AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  181. presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:botaViewController presentingViewController:self];
  182. botaViewController.transitioningDelegate = presentationController;
  183. [self presentViewController:botaViewController animated:YES completion:nil];
  184. }
  185. - (void)setTitleRefresh {
  186. if (CToolModelAnnotation == self.pdfListView.toolModel) {
  187. [self enterAnnotationMode];
  188. } else if (CToolModelViewer == self.pdfListView.toolModel) {
  189. [self enterViewerMode];
  190. }
  191. }
  192. #pragma mark - CPDFViewDelegate
  193. - (void)PDFViewShouldBeginEditing:(CPDFView *)pdfView textView:(UITextView *)textView forAnnotation:(CPDFFreeTextAnnotation *)annotation {
  194. CPDFKeyboardToolbar *keyBoadrdToolbar = [[CPDFKeyboardToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
  195. keyBoadrdToolbar.delegate = self;
  196. [keyBoadrdToolbar bindToTextView:textView];
  197. }
  198. #pragma mark - CPDFListViewDelegate
  199. - (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfView {
  200. CGFloat tPosY = 0;
  201. CGFloat tBottomY = 0;
  202. if(CToolModelAnnotation == self.pdfListView.toolModel) {
  203. if (self.navigationController.navigationBarHidden) {
  204. [self.navigationController setNavigationBarHidden:NO animated:YES];
  205. [UIView animateWithDuration:0.3 animations:^{
  206. CGRect frame = self.annotationBar.frame;
  207. frame.origin.y = self.view.bounds.size.height-frame.size.height;
  208. self.annotationBar.frame = frame;
  209. self.pdfListView.pageSliderView.alpha = 1.0;
  210. self.annotationBar.topToolBar.alpha = 1.0;
  211. self.annotationBar.drawPencilFuncView.alpha = 1.0;
  212. }];
  213. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  214. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  215. tBottomY = self.annotationBar.frame.size.height;
  216. } else {
  217. [self.navigationController setNavigationBarHidden:YES animated:YES];
  218. [UIView animateWithDuration:0.3 animations:^{
  219. CGRect frame = self.annotationBar.frame;
  220. frame.origin.y = self.view.bounds.size.height;
  221. self.annotationBar.frame = frame;
  222. self.pdfListView.pageSliderView.alpha = 0.0;
  223. self.annotationBar.topToolBar.alpha = 0.0;
  224. self.annotationBar.drawPencilFuncView.alpha = 0.0;
  225. }];
  226. }
  227. } else {
  228. CGFloat tPosY = 0;
  229. if (self.navigationController.navigationBarHidden) {
  230. [self.navigationController setNavigationBarHidden:NO animated:YES];
  231. [UIView animateWithDuration:0.3 animations:^{
  232. self.pdfListView.pageSliderView.alpha = 1.0;
  233. }];
  234. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  235. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  236. } else {
  237. [self.navigationController setNavigationBarHidden:YES animated:YES];
  238. [UIView animateWithDuration:0.3 animations:^{
  239. self.pdfListView.pageSliderView.alpha = 0.0;
  240. }];
  241. }
  242. }
  243. if (CPDFDisplayDirectionVertical == [CPDFKitConfig sharedInstance].displayDirection) {
  244. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  245. inset.bottom = 10 + self.annotationBar.frame.size.height;
  246. self.pdfListView.documentView.contentInset = inset;
  247. } else{
  248. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  249. inset.bottom = 0;
  250. self.pdfListView.documentView.contentInset = inset;
  251. }
  252. }
  253. - (void)PDFListViewEditNote:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
  254. if([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  255. [self.annotationBar buttonItemClicked_openAnnotation:self.titleButton];
  256. } else {
  257. CGRect rect = [self.pdfListView convertRect:annotation.bounds fromPage:annotation.page];
  258. CPDFNoteOpenViewController *noteVC = [[CPDFNoteOpenViewController alloc]initWithAnnotation:annotation];
  259. noteVC.delegate = self;
  260. [noteVC showViewController:self inRect:rect];
  261. }
  262. }
  263. - (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
  264. [self.annotationBar reloadData];
  265. }
  266. - (void)PDFListViewPerformAddStamp:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
  267. [self.annotationBar addStampAnnotationWithPage:page point:point];
  268. }
  269. - (void)PDFListViewPerformAddImage:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
  270. [self.annotationBar addImageAnnotationWithPage:page point:point];
  271. }
  272. - (BOOL)PDFListViewerTouchEndedIsAudioRecordMedia:(CPDFListView *)pdfListView {
  273. if (CPDFMediaStateAudioRecord == [CPDFMediaManager shareManager].mediaState) {
  274. [self PDFListViewPerformTouchEnded:self.pdfListView];
  275. return YES;
  276. }
  277. return NO;
  278. }
  279. - (void)PDFListViewPerformCancelMedia:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
  280. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateStop;
  281. }
  282. - (void)PDFListViewPerformRecordMedia:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
  283. if([self.soundPlayBar superview]) {
  284. if(self.soundPlayBar.soundState == CPDFSoundStatePlay) {
  285. [self.soundPlayBar stopAudioPlay];
  286. [self.soundPlayBar removeFromSuperview];
  287. } else if (self.soundPlayBar.soundState == CPDFSoundStateRecord) {
  288. [self.soundPlayBar stopRecord];
  289. [self.soundPlayBar removeFromSuperview];
  290. }
  291. }
  292. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
  293. if (authStatus == AVAuthorizationStatusNotDetermined || authStatus == AVAuthorizationStatusDenied) {
  294. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
  295. if (granted) {
  296. } else {
  297. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  298. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  299. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  300. }
  301. }
  302. }];
  303. }
  304. if (authStatus == AVAuthorizationStatusAuthorized) {
  305. NSInteger pageindex = [self.pdfListView.document indexForPage:page];
  306. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateAudioRecord;
  307. [CPDFMediaManager shareManager].pageNum = pageindex;
  308. [CPDFMediaManager shareManager].ptInPdf = point;
  309. _soundPlayBar = [[CPDFSoundPlayBar alloc] initWithStyle:self.annotationManage.annotStyle];
  310. _soundPlayBar.delegate = self;
  311. [_soundPlayBar showInView:self.pdfListView soundState:CPDFSoundStateRecord];
  312. [_soundPlayBar startAudioRecord];
  313. } else {
  314. return;
  315. }
  316. }
  317. - (void)PDFListViewPerformPlay:(CPDFListView *)pdfView forAnnotation:(CPDFSoundAnnotation *)annotation {
  318. NSString *filePath = [annotation mediaPath];
  319. if (filePath) {
  320. NSURL *URL = [NSURL fileURLWithPath:filePath];
  321. _soundPlayBar = [[CPDFSoundPlayBar alloc] initWithStyle:self.annotationManage.annotStyle];
  322. _soundPlayBar.delegate = self;
  323. [_soundPlayBar showInView:self.pdfListView soundState:CPDFSoundStatePlay];
  324. [_soundPlayBar setURL:URL];
  325. [_soundPlayBar startAudioPlay];
  326. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateVedioPlaying;
  327. }
  328. }
  329. - (void)PDFListViewPerformSignatureWidget:(CPDFListView *)pdfView forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation {
  330. [self.annotationBar openSignatureAnnotation:annotation];
  331. }
  332. - (void)PDFListViewEditProperties:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
  333. [self.annotationBar buttonItemClicked_openAnnotation:self.titleButton];
  334. }
  335. #pragma mark - CPDFKeyboardToolbarDelegate
  336. - (void)keyboardShouldDissmiss:(CPDFKeyboardToolbar *)toolbar {
  337. [self.pdfListView commitEditAnnotationFreeText];
  338. self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
  339. [self.annotationBar reloadData];
  340. }
  341. #pragma mark - CPDFBOTAViewControllerDelegate
  342. - (void)botaViewControllerDismiss:(CPDFBOTAViewController *)botaViewController {
  343. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  344. }
  345. #pragma mark - CPDFAnnotationBarDelegate
  346. - (void)annotationBarClick:(CPDFAnnotationToolBar *)annotationBar clickAnnotationMode:(CPDFViewAnnotationMode)annotationMode forSelected:(BOOL)isSelected forButton:(UIButton *)button {
  347. if(CPDFViewAnnotationModeInk == annotationMode || CPDFViewAnnotationModePencilDrawing == annotationMode) {
  348. CGFloat tPosY = 0;
  349. if(isSelected) {
  350. [self.navigationController setNavigationBarHidden:YES animated:YES];
  351. [UIView animateWithDuration:0.3 animations:^{
  352. CGRect frame = self.annotationBar.frame;
  353. frame.origin.y = self.view.bounds.size.height;
  354. self.annotationBar.frame = frame;
  355. self.pdfListView.pageSliderView.alpha = 0.0;
  356. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  357. inset.bottom = 0;
  358. self.pdfListView.documentView.contentInset = inset;
  359. }];
  360. } else {
  361. [self.navigationController setNavigationBarHidden:NO animated:YES];
  362. [UIView animateWithDuration:0.3 animations:^{
  363. CGRect frame = self.annotationBar.frame;
  364. frame.origin.y = self.view.bounds.size.height-frame.size.height;
  365. self.annotationBar.frame = frame;
  366. self.pdfListView.pageSliderView.alpha = 1.0;
  367. }];
  368. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  369. tPosY = self.navigationController.navigationBar.frame.size.height + rectStatus.size.height;
  370. UIEdgeInsets inset = self.pdfListView.documentView.contentInset;
  371. inset.bottom = self.annotationBar.frame.size.height;
  372. self.pdfListView.documentView.contentInset = inset;
  373. }
  374. } else if (CPDFViewAnnotationModeSound == annotationMode && !isSelected) {
  375. if(CPDFSoundStateRecord == self.soundPlayBar.soundState) {
  376. [self.soundPlayBar stopRecord];
  377. } else if (CPDFSoundStatePlay== self.soundPlayBar.soundState) {
  378. [self.soundPlayBar stopAudioPlay];
  379. }
  380. }
  381. }
  382. #pragma mark - CPDFNoteOpenViewControllerDelegate
  383. - (void)getNoteOpenViewController:(CPDFNoteOpenViewController *)noteOpenVC content:(NSString *)content isDelete:(BOOL)isDelete {
  384. if (isDelete) {
  385. [noteOpenVC.annotation.page removeAnnotation:noteOpenVC.annotation];
  386. [self.pdfListView setNeedsDisplayForPage:noteOpenVC.annotation.page];
  387. if([self.pdfListView.activeAnnotations containsObject:noteOpenVC.annotation]) {
  388. NSMutableArray *activeAnnotations = [NSMutableArray arrayWithArray:self.pdfListView.activeAnnotations];
  389. [activeAnnotations removeObject:noteOpenVC.annotation];
  390. [self.pdfListView updateActiveAnnotations:activeAnnotations];
  391. }
  392. } else {
  393. if([noteOpenVC.annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  394. CPDFMarkupAnnotation *markupAnnotation = (CPDFMarkupAnnotation *)noteOpenVC.annotation;
  395. [markupAnnotation setContents:content?:@""];
  396. } else if(([noteOpenVC.annotation isKindOfClass:[CPDFTextAnnotation class]])){
  397. if(content && content.length > 0) {
  398. noteOpenVC.annotation.contents = content?:@"";
  399. } else {
  400. if([self.pdfListView.activeAnnotations containsObject:noteOpenVC.annotation]) {
  401. [self.pdfListView updateActiveAnnotations:@[]];
  402. }
  403. [noteOpenVC.annotation.page removeAnnotation:noteOpenVC.annotation];
  404. [self.pdfListView setNeedsDisplayForPage:noteOpenVC.annotation.page];
  405. }
  406. } else {
  407. noteOpenVC.annotation.contents = content?:@"";
  408. }
  409. }
  410. }
  411. #pragma mark - CPDFSoundPlayBarDelegate
  412. - (void)soundPlayBarRecordFinished:(CPDFSoundPlayBar *)soundPlayBar withFile:(NSString *)filePath {
  413. CPDFPage *page = [self.pdfListView.document pageAtIndex:[CPDFMediaManager shareManager].pageNum];
  414. CPDFSoundAnnotation *annotation = [[CPDFSoundAnnotation alloc] initWithDocument:self.pdfListView.document];
  415. if ([annotation setMediaPath:filePath]) {
  416. CGRect bounds = annotation.bounds;
  417. bounds.origin.x = [CPDFMediaManager shareManager].ptInPdf.x-bounds.size.width/2.0;
  418. bounds.origin.y = [CPDFMediaManager shareManager].ptInPdf.y-bounds.size.height/2.0;
  419. annotation.bounds = bounds;
  420. [self.pdfListView addAnnotation:annotation forPage:page];
  421. }
  422. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateStop;
  423. [self.pdfListView stopRecord];
  424. }
  425. - (void)soundPlayBarRecordCancel:(CPDFSoundPlayBar *)soundPlayBar {
  426. if(CPDFSoundStateRecord == self.soundPlayBar.soundState) {
  427. [self.pdfListView stopRecord];
  428. }
  429. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateStop;
  430. }
  431. - (void)soundPlayBarPlayClose:(CPDFSoundPlayBar *)soundPlayBar {
  432. [CPDFMediaManager shareManager].mediaState = CPDFMediaStateStop;
  433. }
  434. #pragma mark - Notification
  435. - (void)PDFPageDidRemoveAnnotationNotification:(NSNotification *)notification {
  436. CPDFAnnotation *annotation = [notification object];
  437. if ([annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  438. [self.soundPlayBar stopAudioPlay];
  439. if ([self.soundPlayBar isDescendantOfView:self.view]) {
  440. [self.soundPlayBar removeFromSuperview];
  441. }
  442. }
  443. }
  444. #pragma mark - CPDFToolsViewControllerDelegate
  445. - (void)CPDFToolsViewControllerDismiss:(CPDFToolsViewController *) viewController selectItemAtIndex:(CToolModel)selectIndex {
  446. if(CToolModelViewer == selectIndex) {
  447. //viewwer
  448. [self enterViewerMode];
  449. }else{
  450. //Annotation
  451. [self enterAnnotationMode];
  452. }
  453. }
  454. @end