Browse Source

PDFAnnotation(iOS) - 便签注释修改

dinglingui 1 year ago
parent
commit
ccaa610b65

+ 19 - 19
Annotation-Ctrl-Demo/Annotation-Ctrl-Demo/CPDFViewController.m

@@ -15,7 +15,7 @@
 #import <ComPDFKit/ComPDFKit.h>
 #import <compdfkit_tools/compdfkit_tools.h>
 
-@interface CPDFViewController () <UISearchBarDelegate,CPDFViewDelegate,CPDFListViewDelegate, CPDFMoreListViewDelegate,CSearchToolbarDelegate, CPDFDisplayViewDelegate,CPDFBOTAViewControllerDelegate,CPDFSearchResultsDelegate,CPDFThumbnailViewControllerDelegate,CPDFAnnotationBarDelegate>
+@interface CPDFViewController () <UISearchBarDelegate,CPDFViewDelegate,CPDFListViewDelegate, CPDFMoreListViewDelegate,CSearchToolbarDelegate, CPDFDisplayViewDelegate,CPDFBOTAViewControllerDelegate,CPDFSearchResultsDelegate,CPDFThumbnailViewControllerDelegate,CPDFAnnotationBarDelegate,CPDFNoteOpenViewControllerDelegate>
 
 @property(nonatomic, strong) NSString *filePath;
 
@@ -196,6 +196,14 @@
 }
 
 - (void)PDFListViewEditNote:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
+    if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+        CGRect rect = [self.pdfListView convertRect:annotation.bounds fromPage:annotation.page];
+        CPDFNoteOpenViewController *noteVC = [[CPDFNoteOpenViewController alloc]initWithAnnotation:annotation];
+        noteVC.delegate = self;
+        [noteVC showViewController:self inRect:rect];
+    } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+        
+    }
 //    [self.annotationManage setAnnotStyleFromAnnotations:self.pdfListView.activeAnnotations];
     [self.annotationManage setAnnotStyleFromAnnotation:annotation];
 }
@@ -259,24 +267,6 @@
     self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:pdfListView];
 }
 
-- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
-    switch (annotationMode) {
-        case CPDFViewAnnotationModeNote:
-        {
-            
-        }
-            break;
-        case CPDFViewAnnotationModeHighlight:
-        {
-         
-        }
-            
-        default:
-            break;
-    }
-}
-
-
 #pragma mark - CPDFMorelistViewDelegate
 
 - (void)PDFMoreListViewController:(CPDFMoreListViewController *)moreVC didSelectRow:(CPDFMoreListViewType)row {
@@ -354,4 +344,14 @@
     [self.navigationController popViewControllerAnimated:YES];
 }
 
+#pragma mark - CPDFNoteOpenViewControllerDelegate
+
+- (void)getNoteOpenViewController:(CPDFNoteOpenViewController *)noteOpenVC content:(NSString *)content isDelete:(BOOL)isDelete {
+    if (isDelete) {
+        [noteOpenVC.annotation.page removeAnnotation:noteOpenVC.annotation];
+        [self.pdfListView setNeedsDisplayForPage:noteOpenVC.annotation.page];
+    } else {
+        noteOpenVC.annotation.contents = content?:@"";
+    }
+}
 @end

+ 1 - 1
compdfkit-tools/compdfkit-tools.xcodeproj/project.pbxproj

@@ -44,7 +44,7 @@
 		C918CEA629F8FC1800D43974 /* CPDFUnderlineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CEA429F8FC1800D43974 /* CPDFUnderlineViewController.m */; };
 		C918CEAD29F9024600D43974 /* ComPDFKit.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F313657129E4367A00EE6BBB /* ComPDFKit.xcframework */; };
 		C918CEAE29F9024600D43974 /* ComPDFKit.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F313657129E4367A00EE6BBB /* ComPDFKit.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
-		C918CEBF29F9078A00D43974 /* CPDFNoteOpenViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CEBD29F9078A00D43974 /* CPDFNoteOpenViewController.h */; };
+		C918CEBF29F9078A00D43974 /* CPDFNoteOpenViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CEBD29F9078A00D43974 /* CPDFNoteOpenViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		C918CEC029F9078A00D43974 /* CPDFNoteOpenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CEBE29F9078A00D43974 /* CPDFNoteOpenViewController.m */; };
 		C918CEC329FA0C7700D43974 /* CPDFSquigglyViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CEC129FA0C7700D43974 /* CPDFSquigglyViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		C918CEC429FA0C7700D43974 /* CPDFSquigglyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CEC229FA0C7700D43974 /* CPDFSquigglyViewController.m */; };

+ 10 - 2
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteOpenViewController.h

@@ -2,7 +2,12 @@
 //  CPDFNoteOpenViewController.h
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/26.
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 //
 
 #import <UIKit/UIKit.h>
@@ -10,6 +15,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @class CPDFNoteOpenViewController;
+@class CPDFAnnotation;
 
 @protocol CPDFNoteOpenViewControllerDelegate <NSObject>
 
@@ -23,7 +29,9 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, weak) id<CPDFNoteOpenViewControllerDelegate> delegate;
 
-- (void)setContent:(NSString *)content;
+@property (nonatomic, readonly) CPDFAnnotation * annotation;
+
+- (instancetype)initWithAnnotation:(CPDFAnnotation *)annotation;
 
 - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect;
 

+ 19 - 11
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteOpenViewController.m

@@ -2,10 +2,16 @@
 //  CPDFNoteOpenViewController.m
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/26.
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 //
 
 #import "CPDFNoteOpenViewController.h"
+#import <ComPDFKit/ComPDFKit.h>
 
 @interface CPDFNoteOpenViewController () <UIPopoverPresentationControllerDelegate>
 
@@ -13,10 +19,20 @@
 
 @property (nonatomic, strong) NSString *textViewContent;
 
+@property (nonatomic, strong) CPDFAnnotation * annotation;
+
+
 @end
 
 @implementation CPDFNoteOpenViewController
 
+- (instancetype)initWithAnnotation:(id)annotation {
+    if(self = [super init]) {
+        self.annotation = annotation;
+    }
+    return self;
+}
+
 #pragma mark - UIViewController Methods
 
 - (void)viewDidLoad {
@@ -54,6 +70,8 @@
     saveButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin;
     [saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:saveButton];
+    
+    self.noteTextView.text = self.annotation.contents?:@"";
 }
 
 - (void)viewDidAppear:(BOOL)animation {
@@ -70,16 +88,6 @@
     }
 }
 
-#pragma mark - Public Methods
-
-- (void)setContent:(NSString *)content {
-    if (!content) {
-        self.textViewContent = @"";
-    } else {
-        self.textViewContent = content;
-    }
-}
-
 - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect {
     self.preferredContentSize = CGSizeMake(300, 240);
     self.modalPresentationStyle = UIModalPresentationPopover;

+ 5 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.m

@@ -257,11 +257,13 @@
                 CPDFAnnotation *annotation = [page annotationAtPoint:point];
                 if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
                     [self updateActiveAnnotations:@[annotation]];
+                    [self setNeedsDisplayForPage:page];
                     if ([self.performDelegate respondsToSelector:@selector(PDFListViewEditNote:forAnnotation:)]) {
                         [self.performDelegate PDFListViewEditNote:self forAnnotation:annotation];
                     }
                 } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
                     [self updateActiveAnnotations:@[annotation]];
+                    [self setNeedsDisplayForPage:page];
                     if (CGRectContainsPoint(annotation.bounds, point)) {
                         [self showMenuForAnnotation:annotation];
                     }
@@ -693,6 +695,8 @@
     switch (mode) {
         case CPDFViewAnnotationModeNote: {
             CGFloat width = 57.0/1.5;
+            annotation = [[CPDFTextAnnotation alloc] initWithDocument:self.document];
+            annotation.bounds = CGRectMake(point.x-width/2.0, point.y-width/2.0, width, width);
         }
             break;
         case CPDFViewAnnotationModeHighlight: {
@@ -802,6 +806,7 @@
     [page addAnnotation:annotation];
     
     if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+        [self updateActiveAnnotations:@[annotation]];
         [self setNeedsDisplayForPage:page];
         if ([self.performDelegate respondsToSelector:@selector(PDFListViewEditNote:forAnnotation:)]) {
             [self.performDelegate PDFListViewEditNote:self forAnnotation:annotation];

+ 1 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.m

@@ -101,7 +101,7 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
     }
     
     dispatch_async(dispatch_get_main_queue(), ^{
-        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewActiveAnnotationsChangeNotification object:self];
+        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewAnnotationModeChangeNotification object:self];
         
         if([self.performDelegate respondsToSelector:@selector(PDFListViewChangedAnnotationType:forAnnotationMode:)]) {
             [self.performDelegate PDFListViewChangedAnnotationType:self forAnnotationMode:self.annotationMode];

+ 1 - 1
compdfkit-tools/compdfkit-tools/compdfkit_tools.h

@@ -60,7 +60,7 @@
 #import <compdfkit_tools/AAPLCustomPresentationController.h>
 #import <compdfkit_tools/CPDFInkTopToolBar.h>
 #import <compdfkit_tools/CAnnotationManage.h>
-
+#import <compdfkit_tools/CPDFNoteOpenViewController.h>
 //Edit
 #import <compdfkit_tools/CPDFEditToolBar.h>
 #import <compdfkit_tools/CPDFEditViewController.h>