Преглед изворни кода

Merge branch 'compdfkit_demo_ios' of git.kdan.cc:others/kmpdfkit_demo into compdfkit_demo_ios

# Conflicts:
#	compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Edit.m
chenyu пре 1 година
родитељ
комит
650a4e1c5b
46 измењених фајлова са 1086 додато и 251 уклоњено
  1. 1 1
      Annotation-Ctrl-Demo/Annotation-Ctrl-Demo.xcodeproj/xcuserdata/kdanmobile_2.xcuserdatad/xcschemes/xcschememanagement.plist
  2. 38 9
      Annotation-Ctrl-Demo/Annotation-Ctrl-Demo/CPDFViewController.m
  3. 2 3
      Edit-Ctrl-Demo/Edit-Ctrl-Demo/CPDFViewController.m
  4. 62 2
      compdfkit-tools/compdfkit-tools.xcodeproj/project.pbxproj
  5. 9 5
      compdfkit-tools/compdfkit-tools/Annotation/PDFAnnotationManage/CAnnotationManage.h
  6. 50 42
      compdfkit-tools/compdfkit-tools/Annotation/PDFAnnotationManage/CAnnotationManage.m
  7. 15 6
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFBase/CPDFAnnotationBaseViewController.m
  8. 10 2
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteOpenViewController.h
  9. 19 11
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteOpenViewController.m
  10. 14 6
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteViewController.m
  11. 12 0
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFShape/CPDFShapeCircleViewController.h
  12. 9 1
      compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFShape/CPDFShapeCircleViewController.m
  13. 4 0
      compdfkit-tools/compdfkit-tools/Common/Model/CAnnotStyle.h
  14. 3 1
      compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.h
  15. 77 86
      compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m
  16. 6 3
      compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.h
  17. 11 5
      compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.m
  18. 1 1
      compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFAnnotationSampleView.m
  19. 2 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFColorPickerView.m
  20. 5 3
      compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFColorSelectView.m
  21. 22 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/Contents.json
  22. BIN
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/annotation_drag_dot.png
  23. BIN
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/annotation_drag_dot@2x.png
  24. 20 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/Image.imageset/Contents.json
  25. 17 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+Extensions.h
  26. 19 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+PDFListView.h
  27. 29 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+PDFListView.m
  28. 56 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotationHeader.h
  29. 17 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+Extensions.h
  30. 19 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+PDFListView.h
  31. 29 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+PDFListView.m
  32. 19 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFFreeTextAnnotation+PDFListView.h
  33. 30 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFFreeTextAnnotation+PDFListView.m
  34. 19 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFLineAnnotation+PDFListView.h
  35. 31 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFLineAnnotation+PDFListView.m
  36. 19 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFSquareAnnotation+PDFListView.h
  37. 29 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFSquareAnnotation+PDFListView.m
  38. 115 56
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.m
  39. 1 1
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Edit.m
  40. 13 3
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Private.h
  41. 27 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+UndoManager.h
  42. 190 0
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+UndoManager.m
  43. 2 1
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.h
  44. 10 1
      compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView.m
  45. 2 1
      compdfkit-tools/compdfkit-tools/compdfkit_tools.h
  46. 1 1
      viewer-ctrl-demo/viewer-ctrl-demo/CPDFViewController.m

+ 1 - 1
Annotation-Ctrl-Demo/Annotation-Ctrl-Demo.xcodeproj/xcuserdata/kdanmobile_2.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -7,7 +7,7 @@
 		<key>Annotation-Ctrl-Demo.xcscheme_^#shared#^_</key>
 		<dict>
 			<key>orderHint</key>
-			<integer>3</integer>
+			<integer>1</integer>
 		</dict>
 	</dict>
 </dict>

+ 38 - 9
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;
 
@@ -31,6 +31,8 @@
 
 @property(nonatomic, strong) CPDFAnnotationBar *annotationBar;
 
+@property(nonatomic, strong) CAnnotationManage *annotationManage;
+
 @end
 
 @implementation CPDFViewController
@@ -56,6 +58,8 @@
     self.pdfListView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [self.view addSubview:self.pdfListView];
     
+    self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:self.pdfListView];
+    
     UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"CPDFThunbnailImageEnter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(buttonItemClicked_thumbnail:)];
     self.navigationItem.leftBarButtonItem = leftItem;
     
@@ -80,7 +84,7 @@
     self.searchToolbar = [[CSearchToolbar alloc] initWithPDFView:self.pdfListView];
     self.searchToolbar.delegate = self;
     
-    self.annotationBar = [[CPDFAnnotationBar alloc] initPDFView:self.pdfListView];
+    self.annotationBar = [[CPDFAnnotationBar alloc] initAnnotationManage:self.annotationManage];
     self.annotationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     self.annotationBar.delegate = self;
     [self.annotationBar setParentVC:self];
@@ -96,7 +100,6 @@
     
     if (@available(iOS 11.0, *)) {
         self.pdfListView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - self.view.safeAreaInsets.bottom- self.view.safeAreaInsets.top);
-        
         self.annotationBar.frame = CGRectMake(0, self.view.frame.size.height - self.view.safeAreaInsets.bottom - 44, self.view.frame.size.width, 44);
     } else {
         self.pdfListView.frame = self.view.bounds;
@@ -192,6 +195,19 @@
     
 }
 
+- (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];
+}
+
 #pragma mark - CPDFListViewDelegate
 
 - (NSArray<UIMenuItem *> *)PDFListView:(CPDFListView *)pdfListView customizeMenuForPage:(CPDFPage *)page forPagePoint:(CGPoint)pagePoint {
@@ -203,12 +219,7 @@
     return nil;
 }
 
-- (void)PDFViewPerformTouchEnded:(CPDFListView *)pdfView {
-    if (CPDFViewAnnotationModeNone != self.pdfListView.annotationMode) {
-        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
-        [self.annotationBar reloadData];
-        return;
-    }
+- (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfView {
     if (UIUserInterfaceIdiomPhone == UI_USER_INTERFACE_IDIOM()) {
         if (self.navigationController.navigationBarHidden) {
             [self.navigationController setNavigationBarHidden:NO animated:YES];
@@ -248,6 +259,14 @@
     }
 }
 
+- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
+    [self.annotationBar reloadData];
+}
+
+- (void)PDFListViewChangeatioActiveAnnotations:(CPDFListView *)pdfListView forActiveAnnotations:(NSArray<CPDFAnnotation *> *)annotations {
+    self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:pdfListView];
+}
+
 #pragma mark - CPDFMorelistViewDelegate
 
 - (void)PDFMoreListViewController:(CPDFMoreListViewController *)moreVC didSelectRow:(CPDFMoreListViewType)row {
@@ -325,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

+ 2 - 3
Edit-Ctrl-Demo/Edit-Ctrl-Demo/CPDFViewController.m

@@ -138,13 +138,11 @@
 - (void)PDFViewCurrentPageDidChanged:(CPDFView *)pdfView {
 }
 
-- (void)PDFViewCustomMenuClick:(CPDFListView *)pdfView identifier:(NSString *)menuIdentifier {
-    
+- (void)PDFListViewCustomMenuClick:(CPDFListView *)pdfView identifier:(NSString *)menuIdentifier {
     if([menuIdentifier isEqualToString:@"PropertyItem"]){
         self.editMode = CPDFEditModeText;
         [self showMenuList];
     }
-
 }
 
 - (void)PDFViewEditingSelectStateDidChanged:(CPDFView *)pdfView{
@@ -163,6 +161,7 @@
 }
 
 #pragma mark - CPDFEditToolBarDelegate
+
 - (void)editClickInToolBar:(CPDFEditToolBar *)toolBar editMode:(CPDFEditMode)mode{
     self.editMode = mode;
     switch (mode) {

+ 62 - 2
compdfkit-tools/compdfkit-tools.xcodeproj/project.pbxproj

@@ -32,7 +32,7 @@
 		C918CE8129F621E200D43974 /* CPDFColorPickerView.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CE7F29F621E200D43974 /* CPDFColorPickerView.h */; };
 		C918CE8229F621E200D43974 /* CPDFColorPickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CE8029F621E200D43974 /* CPDFColorPickerView.m */; };
 		C918CE8429F62D6F00D43974 /* Image.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C918CE8329F62D6F00D43974 /* Image.xcassets */; };
-		C918CE9229F7C3FB00D43974 /* CAnnotationManage.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CE9029F7C3FA00D43974 /* CAnnotationManage.h */; };
+		C918CE9229F7C3FB00D43974 /* CAnnotationManage.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CE9029F7C3FA00D43974 /* CAnnotationManage.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		C918CE9329F7C3FB00D43974 /* CAnnotationManage.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CE9129F7C3FA00D43974 /* CAnnotationManage.m */; };
 		C918CE9629F8BA6200D43974 /* CPDFNoteViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C918CE9429F8BA6200D43974 /* CPDFNoteViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		C918CE9729F8BA6200D43974 /* CPDFNoteViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C918CE9529F8BA6200D43974 /* CPDFNoteViewController.m */; };
@@ -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 */; };
@@ -148,6 +148,19 @@
 		F32DA19129ED908800E19ECA /* CPDFMoreListViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = F32DA18F29ED908800E19ECA /* CPDFMoreListViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		F32DA19229ED908800E19ECA /* CPDFMoreListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F32DA19029ED908800E19ECA /* CPDFMoreListViewController.m */; };
 		F335EE4B29E430C800ACC72A /* compdfkit_tools.h in Headers */ = {isa = PBXBuildFile; fileRef = F335EE4A29E430C800ACC72A /* compdfkit_tools.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		F35DD18A2A067E7500B57F5B /* CPDFListView+UndoManager.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1882A067E7500B57F5B /* CPDFListView+UndoManager.h */; };
+		F35DD18B2A067E7500B57F5B /* CPDFListView+UndoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD1892A067E7500B57F5B /* CPDFListView+UndoManager.m */; };
+		F35DD1982A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD18D2A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.m */; };
+		F35DD1992A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD18E2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.m */; };
+		F35DD19A2A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD18F2A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.h */; };
+		F35DD19B2A06850700B57F5B /* CPDFAnnotation+PDFListView.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1902A06850700B57F5B /* CPDFAnnotation+PDFListView.h */; };
+		F35DD19C2A06850700B57F5B /* CPDFAnnotationHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1912A06850700B57F5B /* CPDFAnnotationHeader.h */; };
+		F35DD19D2A06850700B57F5B /* CPDFLineAnnotation+PDFListView.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1922A06850700B57F5B /* CPDFLineAnnotation+PDFListView.h */; };
+		F35DD19E2A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1932A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.h */; };
+		F35DD19F2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h in Headers */ = {isa = PBXBuildFile; fileRef = F35DD1942A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h */; };
+		F35DD1A02A06850700B57F5B /* CPDFAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD1952A06850700B57F5B /* CPDFAnnotation+PDFListView.m */; };
+		F35DD1A12A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD1962A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.m */; };
+		F35DD1A22A06850700B57F5B /* CPDFLineAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F35DD1972A06850700B57F5B /* CPDFLineAnnotation+PDFListView.m */; };
 		F382636829EFD0D9003F1DFD /* CPDFPageIndicatorView.h in Headers */ = {isa = PBXBuildFile; fileRef = F382635F29EFD0D8003F1DFD /* CPDFPageIndicatorView.h */; };
 		F382636929EFD0D9003F1DFD /* CPDFPageIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = F382636029EFD0D8003F1DFD /* CPDFPageIndicatorView.m */; };
 		F382636A29EFD0D9003F1DFD /* CPDFSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = F382636229EFD0D8003F1DFD /* CPDFSlider.m */; };
@@ -326,6 +339,19 @@
 		F32DA19029ED908800E19ECA /* CPDFMoreListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFMoreListViewController.m; sourceTree = "<group>"; };
 		F335EE4729E430C800ACC72A /* compdfkit_tools.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = compdfkit_tools.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		F335EE4A29E430C800ACC72A /* compdfkit_tools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = compdfkit_tools.h; sourceTree = "<group>"; };
+		F35DD1882A067E7500B57F5B /* CPDFListView+UndoManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPDFListView+UndoManager.h"; sourceTree = "<group>"; };
+		F35DD1892A067E7500B57F5B /* CPDFListView+UndoManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CPDFListView+UndoManager.m"; sourceTree = "<group>"; };
+		F35DD18D2A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFFreeTextAnnotation+PDFListView.m"; sourceTree = "<group>"; };
+		F35DD18E2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFCircleAnnotation+PDFListView.m"; sourceTree = "<group>"; };
+		F35DD18F2A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFSquareAnnotation+PDFListView.h"; sourceTree = "<group>"; };
+		F35DD1902A06850700B57F5B /* CPDFAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFAnnotation+PDFListView.h"; sourceTree = "<group>"; };
+		F35DD1912A06850700B57F5B /* CPDFAnnotationHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFAnnotationHeader.h; sourceTree = "<group>"; };
+		F35DD1922A06850700B57F5B /* CPDFLineAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFLineAnnotation+PDFListView.h"; sourceTree = "<group>"; };
+		F35DD1932A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFFreeTextAnnotation+PDFListView.h"; sourceTree = "<group>"; };
+		F35DD1942A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFCircleAnnotation+PDFListView.h"; sourceTree = "<group>"; };
+		F35DD1952A06850700B57F5B /* CPDFAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFAnnotation+PDFListView.m"; sourceTree = "<group>"; };
+		F35DD1962A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFSquareAnnotation+PDFListView.m"; sourceTree = "<group>"; };
+		F35DD1972A06850700B57F5B /* CPDFLineAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFLineAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F382635F29EFD0D8003F1DFD /* CPDFPageIndicatorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFPageIndicatorView.h; sourceTree = "<group>"; };
 		F382636029EFD0D8003F1DFD /* CPDFPageIndicatorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFPageIndicatorView.m; sourceTree = "<group>"; };
 		F382636229EFD0D8003F1DFD /* CPDFSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFSlider.m; sourceTree = "<group>"; };
@@ -822,6 +848,7 @@
 		F32DA15629ED904300E19ECA /* PDFView */ = {
 			isa = PBXGroup;
 			children = (
+				F35DD18C2A06850700B57F5B /* PDFKit Categories */,
 				F38F5B642A03D64C00D0EEFD /* PDFListMagnifierView */,
 				F382636529EFD0D8003F1DFD /* PDFListView */,
 				F382635E29EFD0D8003F1DFD /* PDFPageIndicatorView */,
@@ -864,6 +891,24 @@
 			path = "compdfkit-tools";
 			sourceTree = "<group>";
 		};
+		F35DD18C2A06850700B57F5B /* PDFKit Categories */ = {
+			isa = PBXGroup;
+			children = (
+				F35DD1902A06850700B57F5B /* CPDFAnnotation+PDFListView.h */,
+				F35DD1952A06850700B57F5B /* CPDFAnnotation+PDFListView.m */,
+				F35DD1912A06850700B57F5B /* CPDFAnnotationHeader.h */,
+				F35DD1942A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h */,
+				F35DD18E2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.m */,
+				F35DD1932A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.h */,
+				F35DD18D2A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.m */,
+				F35DD1922A06850700B57F5B /* CPDFLineAnnotation+PDFListView.h */,
+				F35DD1972A06850700B57F5B /* CPDFLineAnnotation+PDFListView.m */,
+				F35DD18F2A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.h */,
+				F35DD1962A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.m */,
+			);
+			path = "PDFKit Categories";
+			sourceTree = "<group>";
+		};
 		F382635E29EFD0D8003F1DFD /* PDFPageIndicatorView */ = {
 			isa = PBXGroup;
 			children = (
@@ -890,6 +935,8 @@
 				F382636629EFD0D8003F1DFD /* CPDFListView.m */,
 				F38F5B5E2A0344EA00D0EEFD /* CPDFListView+Annotation.h */,
 				F38F5B5F2A0344EA00D0EEFD /* CPDFListView+Annotation.m */,
+				F35DD1882A067E7500B57F5B /* CPDFListView+UndoManager.h */,
+				F35DD1892A067E7500B57F5B /* CPDFListView+UndoManager.m */,
 				F38F5B622A038B0400D0EEFD /* CPDFListView+Private.h */,
 				4FF3E1D02A064A8100C14F91 /* CPDFListView+Edit.h */,
 				4FF3E1CF2A064A8100C14F91 /* CPDFListView+Edit.m */,
@@ -934,6 +981,7 @@
 				4F06AB5529F6792E007797E4 /* CPDFEditToolBar.h in Headers */,
 				F32DA17E29ED904300E19ECA /* CPDFBOTAViewController.h in Headers */,
 				F32DA16829ED904300E19ECA /* CPDFOutlineViewCell.h in Headers */,
+				F35DD19B2A06850700B57F5B /* CPDFAnnotation+PDFListView.h in Headers */,
 				C918CEC929FA140C00D43974 /* CPDFInkViewController.h in Headers */,
 				F382636E29EFD0D9003F1DFD /* CPDFListView.h in Headers */,
 				F32DA17529ED904300E19ECA /* CPDFInfoTableCell.h in Headers */,
@@ -949,6 +997,7 @@
 				C91BE7CD2A037A490038F2BC /* CPDFInkTopToolBar.h in Headers */,
 				C918CEA529F8FC1800D43974 /* CPDFUnderlineViewController.h in Headers */,
 				C91BE7E22A048F1A0038F2BC /* CSignatureManager.h in Headers */,
+				F35DD19F2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h in Headers */,
 				C91BE7D82A039D2A0038F2BC /* CPDFSignatureViewCell.h in Headers */,
 				C918CECE29FA43B800D43974 /* CPDFShapeCircleViewController.h in Headers */,
 				C9AF184129F22BBD00EC4979 /* CPDFAnnotationBarButton.h in Headers */,
@@ -959,8 +1008,10 @@
 				F38F5B632A038B0400D0EEFD /* CPDFListView+Private.h in Headers */,
 				F32DA17029ED904300E19ECA /* CPDFThumbnailViewCell.h in Headers */,
 				C9AF189729F4DA6A00EC4979 /* CPDFColorSelectView.h in Headers */,
+				F35DD19C2A06850700B57F5B /* CPDFAnnotationHeader.h in Headers */,
 				C9AF183B29F2198700EC4979 /* CPDFAnnotationBar.h in Headers */,
 				C918CED429FA972300D43974 /* CPDFShapeArrowViewController.h in Headers */,
+				F35DD19A2A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.h in Headers */,
 				F38F5B602A0344EA00D0EEFD /* CPDFListView+Annotation.h in Headers */,
 				F32DA17929ED904300E19ECA /* CPDFDisplayViewController.h in Headers */,
 				C9AF183029EFB23C00EC4979 /* CPDFBookmarkViewController.h in Headers */,
@@ -973,6 +1024,7 @@
 				4F1131AF29F8EEA800950564 /* CPDFEditViewController.h in Headers */,
 				F32DA16529ED904300E19ECA /* CPDFOutlineViewController.h in Headers */,
 				4F06AB5729F6792E007797E4 /* CPDFImageProperty.h in Headers */,
+				F35DD19D2A06850700B57F5B /* CPDFLineAnnotation+PDFListView.h in Headers */,
 				C918CEA029F8F74000D43974 /* CPDFStrikeoutViewController.h in Headers */,
 				C91BE7E62A04AD880038F2BC /* CSignatureTopBar.h in Headers */,
 				F38F60C629EFF0C2008098F8 /* CPDFColorUtils.h in Headers */,
@@ -986,7 +1038,9 @@
 				C91BE7D42A039AC40038F2BC /* CPDFSignatureViewController.h in Headers */,
 				F32DA17129ED904300E19ECA /* CPDFThumbnailViewController.h in Headers */,
 				C9B9EC5929F54E9600C6A5D2 /* CAnnotStyle.h in Headers */,
+				F35DD18A2A067E7500B57F5B /* CPDFListView+UndoManager.h in Headers */,
 				C91BE7DC2A039E900038F2BC /* CPDFSignatureEditViewController.h in Headers */,
+				F35DD19E2A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.h in Headers */,
 				F32DA16229ED904300E19ECA /* CPDFOutlineModel.h in Headers */,
 				4F1131BA29F911A800950564 /* CPDFTextPropertyCell.h in Headers */,
 				C9AF188E29F4C8A900EC4979 /* CPDFAnnotationBaseViewController.h in Headers */,
@@ -1090,6 +1144,7 @@
 				C918CE9729F8BA6200D43974 /* CPDFNoteViewController.m in Sources */,
 				C9B9EC5029F52DCC00C6A5D2 /* AAPLCustomPresentationController.m in Sources */,
 				4F1131BB29F911A800950564 /* CPDFTextPropertyCell.m in Sources */,
+				F35DD1A02A06850700B57F5B /* CPDFAnnotation+PDFListView.m in Sources */,
 				F32DA17F29ED904300E19ECA /* CNavigationController.m in Sources */,
 				F382636D29EFD0D9003F1DFD /* CPDFListView.m in Sources */,
 				F38F5B672A03D68100D0EEFD /* CPDFListMagnifierView.m in Sources */,
@@ -1103,8 +1158,10 @@
 				C918CEE429FBA41A00D43974 /* CPDFDrawArrowView.m in Sources */,
 				F32DA16929ED904300E19ECA /* CPDFSearchResultsViewController.m in Sources */,
 				F32DA16D29ED904300E19ECA /* CPDFSearchViewCell.m in Sources */,
+				F35DD1982A06850700B57F5B /* CPDFFreeTextAnnotation+PDFListView.m in Sources */,
 				4F5986922A03411700F06A1B /* CPDFDropDownMenu.m in Sources */,
 				F32DA16429ED904300E19ECA /* CPDFOutlineViewCell.m in Sources */,
+				F35DD1992A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.m in Sources */,
 				F382636A29EFD0D9003F1DFD /* CPDFSlider.m in Sources */,
 				4F06AB5029F6792E007797E4 /* CPDFTextProperty.m in Sources */,
 				C9AF189C29F4DBF800EC4979 /* CPDFOpacitySliderView.m in Sources */,
@@ -1134,13 +1191,16 @@
 				C91BE7E72A04AD880038F2BC /* CSignatureTopBar.m in Sources */,
 				4F6C796B29FBD532008C9501 /* CPDFEditFontNameSelectView.m in Sources */,
 				F32DA18329ED904300E19ECA /* CNavigationRightView.m in Sources */,
+				F35DD1A12A06850700B57F5B /* CPDFSquareAnnotation+PDFListView.m in Sources */,
 				F32DA17729ED904300E19ECA /* CPDFInfoTableCell.m in Sources */,
 				4F1131B029F8EEA800950564 /* CPDFEditViewController.m in Sources */,
 				C918CED529FA972300D43974 /* CPDFShapeArrowViewController.m in Sources */,
 				F32DA16B29ED904300E19ECA /* CSearchToolbar.m in Sources */,
 				C918CEC429FA0C7700D43974 /* CPDFSquigglyViewController.m in Sources */,
 				C9AF183129EFB23C00EC4979 /* CPDFBookmarkViewController.m in Sources */,
+				F35DD1A22A06850700B57F5B /* CPDFLineAnnotation+PDFListView.m in Sources */,
 				C918CE8229F621E200D43974 /* CPDFColorPickerView.m in Sources */,
+				F35DD18B2A067E7500B57F5B /* CPDFListView+UndoManager.m in Sources */,
 				F32DA17629ED904300E19ECA /* CPDFInfoViewController.m in Sources */,
 				C91BE7CE2A037A490038F2BC /* CPDFInkTopToolBar.m in Sources */,
 				C91BE7D52A039AC40038F2BC /* CPDFSignatureViewController.m in Sources */,

+ 9 - 5
compdfkit-tools/compdfkit-tools/Annotation/PDFAnnotationManage/CAnnotationManage.h

@@ -22,15 +22,19 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, readonly) CPDFListView *pdfListView;
 
-@property (nonatomic, strong) CAnnotStyle *annotStyle;
-
-@property (nonatomic, strong) UIViewController *parentVC;
+@property (nonatomic, readonly) CAnnotStyle *annotStyle;
 
 - (instancetype)initWithPDFView:(CPDFListView *)pdfListView;
 
-- (CAnnotStyle *)getAnnotStyle;
+- (void)setAnnotStyleFromAnnotations:(NSArray<CPDFAnnotation *> *)annotations;
+
+- (void)setAnnotStyleFromMode:(NSInteger)annotationMode;
+
+- (void)refreshAnnotation:(CAnnotStyle *)annotStyle;
+
+- (void)resetAnnotation:(CAnnotStyle *)annotStyle;
 
-- (void)setAnnotStyle:(CAnnotStyle *)annotStyle;
+- (void)setAnnotStyleFromAnnotation:(CPDFAnnotation *)annotation;
 
 @end
 

+ 50 - 42
compdfkit-tools/compdfkit-tools/Annotation/PDFAnnotationManage/CAnnotationManage.m

@@ -17,12 +17,14 @@
 
 #import <ComPDFKit/ComPDFKit.h>
 
-@interface CAnnotationManage () <CPDFListViewDelegate, CPDFNoteOpenViewControllerDelegate>
+@interface CAnnotationManage ()
 
 @property (nonatomic, strong) CPDFListView *pdfListView;
 
 @property (nonatomic, strong) CPDFAnnotation *annotation;
 
+@property (nonatomic, strong) CAnnotStyle *annotStyle;
+
 @end
 
 @implementation CAnnotationManage
@@ -30,74 +32,80 @@
 - (instancetype)initWithPDFView:(CPDFListView *)pdfListView {
     if (self = [super init]) {
         self.pdfListView = pdfListView;
-        self.annotStyle = [[CAnnotStyle alloc] init];
-        self.annotStyle.color = [UIColor yellowColor];
-        self.annotation.opacity = 1.0;
-        self.pdfListView.performDelegate = self;
     }
     return self;
 }
 
 #pragma mark - Publice Methods
 
-- (CAnnotStyle *)getAnnotStyle {
+- (void)setAnnotStyleFromAnnotations:(NSArray<CPDFAnnotation *> *)annotations {
+    self.annotStyle = [[CAnnotStyle alloc] init];
+    self.annotation = annotations.firstObject;
+    self.annotStyle.isSelectAnnot = YES;
     if ([self.annotation isKindOfClass:[CPDFTextAnnotation class]]) {
-        self.annotStyle.bounds = [self.pdfListView convertRect:self.annotation.bounds toPage:self.annotation.page];
-        self.annotStyle.contents = self.annotation.contents;
+        self.annotStyle.annotMode = CPDFViewAnnotationModeNote;
+        self.annotStyle.color = self.annotation.color;
+    } else if ([self.annotation isKindOfClass:[CPDFCircleAnnotation class]]) {
+        self.annotStyle.annotMode = CPDFViewAnnotationModeCircle;
         self.annotStyle.color = self.annotation.color;
     }
-    return self.annotStyle;
 }
 
-- (void)setAnnotStyle:(CAnnotStyle *)annotStyle {
-    if ([self.annotation isKindOfClass:[CPDFTextAnnotation class]]) {
-        self.annotation.color = annotStyle.color;
-        [self.pdfListView setNeedsDisplayForPage:self.annotation.page];
+- (void)setAnnotStyleFromMode:(NSInteger)annotationMode {
+    self.annotStyle = [[CAnnotStyle alloc] init];
+    self.annotStyle.annotMode = annotationMode;
+    self.annotStyle.isSelectAnnot = NO;
+    switch (annotationMode) {
+        case CPDFViewAnnotationModeNote:
+        {
+            self.annotation = [[CPDFTextAnnotation alloc] init];
+            self.annotStyle.color = self.annotation.color;
+        }
+            break;
+            
+        default:
+            break;
     }
 }
 
-#pragma mark - CPDFListViewDelegate
-
-- (void)PDFViewPerformOpenNote:(CPDFListView *)pdfView forAnnotation:(CPDFAnnotation *)annotation {
-    CGRect rect = [pdfView convertRect:annotation.bounds fromPage:annotation.page];
-    CPDFNoteOpenViewController *noteOpenVC = [[CPDFNoteOpenViewController alloc] init];
-    noteOpenVC.delegate = self;
-    [noteOpenVC setContent:annotation.contents];
-    [noteOpenVC showViewController:self.parentVC inRect:rect];
-    
-    self.annotation = annotation;
-}
-
-- (void)PDFListViewChangeatioActiveAnnotations:(CPDFListView *)pdfListView forActiveAnnotations:(NSArray<CPDFAnnotation *> *)annotations {
-    self.annotation = annotations.firstObject;
+- (void)refreshAnnotation:(CAnnotStyle *)annotStyle {
+    switch (annotStyle.annotMode) {
+        case CPDFViewAnnotationModeNote:
+        {
+            self.pdfListView.activeAnnotations.firstObject.color = self.annotStyle.color;
+            [self.pdfListView setNeedsDisplayForPage:self.pdfListView.activeAnnotations.firstObject.page];
+        }
+            break;
+        case CPDFViewAnnotationModeCircle:
+        {
+            self.pdfListView.activeAnnotations.firstObject.color = self.annotStyle.fillColor;
+            [self.pdfListView setNeedsDisplayForPage:self.pdfListView.activeAnnotations.firstObject.page];
+        }
+        default:
+            break;
+    }
 }
 
-- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
-    switch (annotationMode) {
+- (void)resetAnnotation:(CAnnotStyle *)annotStyle {
+    switch (annotStyle.annotMode) {
         case CPDFViewAnnotationModeNote:
         {
             
         }
             break;
-        case CPDFViewAnnotationModeHighlight:
-        {
-            self.annotStyle.color = self.annotation.color;
-            self.annotStyle.opacity = self.annotation.opacity;
-        }
             
         default:
             break;
     }
 }
 
-#pragma mark - CPDFNoteOpenViewControllerDelegate
-
-- (void)getNoteOpenViewController:(CPDFNoteOpenViewController *)noteOpenVC content:(NSString *)content isDelete:(BOOL)isDelete {
-    if (isDelete) {
-        [self.annotation.page removeAnnotation:self.annotation];
-        [self.pdfListView setNeedsDisplayForPage:self.annotation.page];
-    } else {
-        self.annotation.contents = content;
+- (void)setAnnotStyleFromAnnotation:(CPDFAnnotation *)annotation {
+    self.annotStyle = [[CAnnotStyle alloc] init];
+    self.annotation = annotation;
+    self.annotStyle.isSelectAnnot = YES;
+    if ([self.annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+        self.annotStyle.annotMode = CPDFViewAnnotationModeNote;
+        self.annotStyle.color = self.annotation.color;
     }
 }
 

+ 15 - 6
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFBase/CPDFAnnotationBaseViewController.m

@@ -54,7 +54,7 @@
     self.sampleView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
     [self.view addSubview:self.sampleView];
     
-    self.colorView = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(0, 190, self.view.frame.size.width, 90)];
+    self.colorView = [[CPDFColorSelectView alloc] init];
     self.colorView.delegate = self;
     self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
     [self.view addSubview:self.colorView];
@@ -71,11 +71,20 @@
 
 - (void)viewWillLayoutSubviews {
     [super viewWillLayoutSubviews];
-    self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, 50);
-    self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
-    self.sampleView.frame  = CGRectMake((self.view.frame.size.width - 300)/2, 60, 300, 120);
-    self.opacitySliderView.frame = CGRectMake(10, 280, self.view.frame.size.width - 20, 90);
-    self.colorPicker.frame = self.view.frame;
+    self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, ((self.view.frame.size.height)/8));
+    self.sampleView.frame  = CGRectMake((self.view.frame.size.width - 300)/2, ((self.view.frame.size.height)/8), 300, ((self.view.frame.size.height)/8)*3);
+    
+    if (@available(iOS 11.0, *)) {
+        self.colorPicker.frame = CGRectMake(self.view.safeAreaInsets.left, 0, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height);
+        self.colorView.frame = CGRectMake(self.view.safeAreaInsets.left, ((self.view.frame.size.height)/8)*4,self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, ((self.view.frame.size.height)/8)*2);
+        self.opacitySliderView.frame = CGRectMake(self.view.safeAreaInsets.left, ((self.view.frame.size.height)/8)*6, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, ((self.view.frame.size.height)/8)*2);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, ((self.view.frame.size.height)/8));
+    } else {
+        self.colorPicker.frame = self.view.frame;
+        self.colorView.frame = CGRectMake(0, ((self.view.frame.size.height)/8)*4, self.view.frame.size.width, ((self.view.frame.size.height)/8)*2);
+        self.opacitySliderView.frame = CGRectMake(0, ((self.view.frame.size.height)/8)*6, self.view.frame.size.width, ((self.view.frame.size.height)/8)*2);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, ((self.view.frame.size.height)/8));
+    }
 }
 
 - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {

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

+ 14 - 6
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFNote/CPDFNoteViewController.m

@@ -81,11 +81,19 @@
 }
 
 - (void)viewWillLayoutSubviews {
-    self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, ((self.view.frame.size.height)/8)*2 - 10);
-    self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, ((self.view.frame.size.height)/8)*2 -10);
-    self.sampleView.frame  = CGRectMake((self.view.frame.size.width - 300)/2, ((self.view.frame.size.height)/8)*2 -10, 300, ((self.view.frame.size.height)/8)*3);
-    self.colorPicker.frame = self.view.frame;
-    self.colorView.frame = CGRectMake(0, ((self.view.frame.size.height)/7)*4, self.view.frame.size.width, ((self.view.frame.size.height)/7)*3);
+    self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 5, 120, ((self.view.frame.size.height)/7));
+    self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, ((self.view.frame.size.height)/7));
+    self.sampleView.frame  = CGRectMake((self.view.frame.size.width - 300)/2, ((self.view.frame.size.height)/7), 300, ((self.view.frame.size.height)/7)*3);
+    self.colorView.frame = CGRectMake(0, ((self.view.frame.size.height)/7)*4, self.view.frame.size.width, ((self.view.frame.size.height)/7)*2);
+    if (@available(iOS 11.0, *)) {
+        self.colorPicker.frame = CGRectMake(self.view.safeAreaInsets.left, 0, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height);
+        self.colorView.frame = CGRectMake(self.view.safeAreaInsets.left, ((self.view.frame.size.height)/7)*4,self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, ((self.view.frame.size.height)/7)*2);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, ((self.view.frame.size.height)/7));
+    } else {
+        self.colorPicker.frame = self.view.frame;
+        self.colorView.frame = CGRectMake(0, ((self.view.frame.size.height)/7)*4, self.view.frame.size.width, ((self.view.frame.size.height)/7)*2);
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, ((self.view.frame.size.height)/7));
+    }
 }
 
 - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
@@ -97,7 +105,7 @@
 
 - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection
 {
-    self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 270 : 320);
+    self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 200 : 320);
 }
 
 #pragma mark - Action

+ 12 - 0
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFShape/CPDFShapeCircleViewController.h

@@ -14,10 +14,22 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+@class CPDFShapeCircleViewController;
+
+@protocol CPDFShapeCircleViewControllerDelegate <NSObject>
+
+@optional
+
+- (void)circleViewController:(CPDFShapeCircleViewController *)circleViewController annotStyle:(CAnnotStyle *)annotStyle;
+
+@end
+
 @interface CPDFShapeCircleViewController : CPDFAnnotationBaseViewController
 
 - (instancetype)initWithStyle:(CAnnotStyle *)annotStyle selectIndex:(NSInteger)index title:(NSString *)title;
 
+@property (nonatomic, weak) id<CPDFShapeCircleViewControllerDelegate> delegate;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 9 - 1
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFShape/CPDFShapeCircleViewController.m

@@ -65,7 +65,7 @@
 }
 
 - (void)commomInitTitle {
-    self.sampleView.fillColor = [UIColor blueColor];
+    self.sampleView.fillColor = self.annotStyle.color;
     self.sampleView.fillShapeColor = [UIColor whiteColor];
     self.sampleView.thickness = 4.0;
     self.fillColorSelectView.colorLabel.text = NSLocalizedString(@"Fill:", nil);
@@ -113,10 +113,18 @@
 - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
     if (select == self.colorView) {
         self.sampleView.fillColor = color;
+        self.annotStyle.color = color;
         [self.sampleView setNeedsDisplay];
+        if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
+            [self.delegate circleViewController:self annotStyle:self.annotStyle];
+        }
     } else if (select == self.fillColorSelectView) {
         self.sampleView.fillShapeColor = color;
+        self.annotStyle.fillColor = color;
         [self.sampleView setNeedsDisplay];
+        if (self.delegate && [self.delegate respondsToSelector:@selector(circleViewController:annotStyle:)]) {
+            [self.delegate circleViewController:self annotStyle:self.annotStyle];
+        }
     }
 }
 

+ 4 - 0
compdfkit-tools/compdfkit-tools/Common/Model/CAnnotStyle.h

@@ -41,6 +41,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, assign) BOOL isNoRotate;
 
+@property (nonatomic, assign) NSInteger annotMode;
+
+@property (nonatomic, assign) BOOL isSelectAnnot;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 3 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.h

@@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
 @class CPDFAnnotationBar;
 @class CPDFListView;
 @class CPDFInkTopToolBar;
+@class CAnnotationManage;
 
 @protocol CPDFAnnotationBarDelegate <NSObject>
 
@@ -59,9 +60,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, strong) CPDFInkTopToolBar *topToolBar;
 
+- (instancetype)initAnnotationManage:(CAnnotationManage *)annotationManage;
+
 - (void)reloadData;
 
-- (instancetype)initPDFView:(CPDFListView *)pdfListView;
 
 @end
 

+ 77 - 86
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -30,7 +30,7 @@
 
 #import <ComPDFKit/ComPDFKit.h>
 
-@interface CPDFAnnotationBar () <CPDFSignatureViewControllerDelegate, CPDFSignatureEditViewControllerDelegate, CPDFNoteViewControllerDelegate>
+@interface CPDFAnnotationBar () <CPDFSignatureViewControllerDelegate, CPDFSignatureEditViewControllerDelegate, CPDFNoteViewControllerDelegate, CPDFShapeCircleViewControllerDelegate>
 
 @property (nonatomic, strong) UIScrollView *scrollView;
 
@@ -52,14 +52,18 @@
 
 @property (nonatomic, strong) CPDFSignatureViewController *signatureVC;
 
+@property (nonatomic, strong) CPDFShapeCircleViewController *circleVC;
+
 @end
 
 @implementation CPDFAnnotationBar
 
 #pragma mark - Initializers
 
-- (instancetype)initPDFView:(CPDFListView *)pdfListView {
+- (instancetype)initAnnotationManage:(CAnnotationManage *)annotationManage {
     if (self = [super init]) {
+        self.annotManage = annotationManage;
+        
         UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
         UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
         effectView.frame = self.bounds;
@@ -73,9 +77,7 @@
         
         self.selectedIndex = -1;
         
-        self.pdfListView = pdfListView;
-        
-        self.annotManage = [[CAnnotationManage alloc] initWithPDFView:pdfListView];
+        self.pdfListView = annotationManage.pdfListView;
 
         [self initSubview];
     }
@@ -90,12 +92,24 @@
 #pragma mark - Public Methods
 
 - (void)reloadData {
-    if (self.selectedIndex >=0 &&
-        self.selectedIndex < self.annotationBtns.count) {
-        UIButton *selectedButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
-        selectedButton.backgroundColor = [UIColor clearColor];
+    if(CPDFViewAnnotationModeNone == self.pdfListView.annotationMode) {
+        if (self.selectedIndex >=0 &&
+            self.selectedIndex < self.annotationBtns.count) {
+            UIButton *selectedButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
+            selectedButton.backgroundColor = [UIColor clearColor];
+        }
+        self.selectedIndex = -1;
+    } else {
+        for (NSInteger i = 0; i< self.annotationBtns.count; i++) {
+            UIButton *button = [self.annotationBtns objectAtIndex:i];
+            if(button.tag == self.pdfListView.annotationMode) {
+                button.backgroundColor = [UIColor colorWithRed:178.0/255.0 green:239.0/255.0 blue:253.0/255.0 alpha:1.0];
+                self.selectedIndex = button.tag;
+            } else {
+                button.backgroundColor = [UIColor clearColor];
+            }
+        }
     }
-    self.selectedIndex = -1;
 }
 
 #pragma mark - Private Methods
@@ -124,23 +138,39 @@
                         @"CPDFAnnotationBarImageLink",
                         @"CPDFAnnotationBarImageSound"];
     
+    NSArray *types = @[@(CPDFViewAnnotationModeNote),
+                       @(CPDFViewAnnotationModeHighlight),
+                       @(CPDFViewAnnotationModeUnderline),
+                       @(CPDFViewAnnotationModeStrikeout),
+                       @(CPDFViewAnnotationModeSquiggly),
+                       @(CPDFViewAnnotationModeInk),
+                       @(CPDFViewAnnotationModeCircle),
+                       @(CPDFViewAnnotationModeSquare),
+                       @(CPDFViewAnnotationModeArrow),
+                       @(CPDFViewAnnotationModeLine),
+                       @(CPDFViewAnnotationModeFreeText),
+                       @(CPDFViewAnnotationModeSignature),
+                       @(CPDFViewAnnotationModeStamp),
+                       @(CPDFViewAnnotationModeImage),
+                       @(CPDFViewAnnotationModeLink),
+                       @(CPDFViewAnnotationModeSound)];
+    
     NSMutableArray *annotationBtns = [NSMutableArray array];
-    for (int i = 0; i < images.count; i++) {
+    for (int i = 0; i < types.count; i++) {
+        CPDFViewAnnotationMode annotationMode = (CPDFViewAnnotationMode)[types[i] integerValue];
         CPDFAnnotationBarButton *button = [CPDFAnnotationBarButton buttonWithType:UIButtonTypeCustom];
         button.frame = CGRectMake(offsetX, 1, 58, 43);
         [button setImage:[UIImage imageNamed:images[i] inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
-        button.tag = i;
-        button.type = i;
-        if (i == 1) {
+        button.tag = annotationMode;
+        if (CPDFViewAnnotationModeHighlight == annotationMode) {
             button.lineColor = CPDFKitShareConfig.highlightAnnotationColor;
-        } else if (i == 2) {
+        } else if (CPDFViewAnnotationModeUnderline == annotationMode) {
             button.lineColor = CPDFKitShareConfig.underlineAnnotationColor;
-        } else if (i == 3) {
+        } else if (CPDFViewAnnotationModeStrikeout == annotationMode) {
             button.lineColor = CPDFKitShareConfig.strikeoutAnnotationColor;
-        } else if (i == 4) {
+        } else if (CPDFViewAnnotationModeSquiggly == annotationMode) {
             button.lineColor = CPDFKitShareConfig.squigglyAnnotationColor;
-        } else if (i == 5) {
-            button.type = 4;
+        } else if (CPDFViewAnnotationModeInk== annotationMode) {
             button.lineColor = CPDFKitShareConfig.freehandAnnotationColor;
         }
         [button addTarget:self action:@selector(buttonItemClicked_Switch:) forControlEvents:UIControlEventTouchUpInside];
@@ -187,10 +217,9 @@
 #pragma mark - Action
 
 - (void)buttonItemClicked_Switch:(UIButton *)button {
-    self.annotManage.parentVC = self.parentVC;
     self.propertiesBtn.userInteractionEnabled = YES;
     self.propertiesBtn.tag = button.tag;
-    if (self.selectedIndex >= 0 && self.selectedIndex < self.annotationBtns.count) {
+    if (self.selectedIndex >= 0 && self.selectedIndex <= self.annotationBtns.count) {
         UIButton *selectButton = [self.annotationBtns objectAtIndex:self.selectedIndex];
         selectButton.backgroundColor = [UIColor clearColor];
     }
@@ -198,72 +227,19 @@
     if (button.tag != self.selectedIndex) {
         button.backgroundColor = [UIColor colorWithRed:178.0/255.0 green:239.0/255.0 blue:253.0/255.0 alpha:1.0];
         self.selectedIndex = button.tag;
+        self.pdfListView.annotationMode = self.selectedIndex;
+
     } else {
+        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
         self.selectedIndex = -1;
     }
-    
-    switch (self.selectedIndex) {
-        case CPDFToolbarNote:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeNote;
-        }
-            break;
-        case CPDFToolbarHighlight:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeHighlight;
-        }
-            break;
-        case CPDFToolbarUnderline:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeUnderline;
-        }
-            break;
-        case CPDFToolbarStrikeout:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeStrikeout;
-        }
-            break;
-        case CPDFToolbarSquiggly:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeSquiggly;
-        }
-            break;
-        case CPDFToolbarFreehand:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeInk;
-        }
-            break;
-        case CPDFToolbarShapeCircle:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeCircle;
-        }
-            break;
-        case CPDFToolbarShapeRectangle:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeSquare;
-        }
-            break;
-        case CPDFToolbarShapeArrow:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeArrow;
-        }
-            break;
-        case CPDFToolbarShapeLine:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeLine;
-        }
-            break;
-            
-        default:
-        {
-            self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
-        }
-            break;
-    }
 }
 
 - (void)buttonItemClicked_open:(UIButton *)button {
-    CAnnotStyle *annotStytle = [self.annotManage getAnnotStyle];
+    if (self.pdfListView.activeAnnotations.firstObject) {
+        [self.annotManage setAnnotStyleFromAnnotations:self.pdfListView.activeAnnotations];
+    }
+    CAnnotStyle *annotStytle = self.annotManage.annotStyle;
     AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
     switch (button.tag) {
         case CPDFToolbarNote:
@@ -332,10 +308,11 @@
             break;
         case CPDFToolbarShapeCircle:
         {
-            CPDFShapeCircleViewController *circleVC = [[CPDFShapeCircleViewController alloc] initWithStyle:annotStytle selectIndex:CPDFToolbarShapeCircle title:@"Circle"];
-            presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:circleVC presentingViewController:self.parentVC];
-            circleVC.transitioningDelegate = presentationController;
-            [self.parentVC presentViewController:circleVC animated:YES completion:nil];
+            self.circleVC = [[CPDFShapeCircleViewController alloc] initWithStyle:annotStytle selectIndex:CPDFToolbarShapeCircle title:@"Circle"];
+            self.circleVC.delegate = self;
+            presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:self.circleVC presentingViewController:self.parentVC];
+            self.circleVC.transitioningDelegate = presentationController;
+            [self.parentVC presentViewController:self.circleVC animated:YES completion:nil];
         }
             break;
         case CPDFToolbarShapeRectangle:
@@ -415,7 +392,21 @@
 #pragma mark - CPDFNoteViewControllerDelegate
 
 - (void)noteViewController:(CPDFNoteViewController *)noteViewController annotSytle:(CAnnotStyle *)annotStyle {
-    [self.annotManage setAnnotStyle:annotStyle];
+    if (annotStyle.isSelectAnnot) {
+        [self.annotManage refreshAnnotation:annotStyle];
+    } else {
+        [self.annotManage resetAnnotation:annotStyle];
+    }
+}
+
+#pragma mark - CPDFShapeCircleViewControllerDelegate
+
+- (void)circleViewController:(CPDFShapeCircleViewController *)circleViewController annotStyle:(CAnnotStyle *)annotStyle {
+    if (annotStyle.isSelectAnnot) {
+        [self.annotManage refreshAnnotation:annotStyle];
+    } else {
+        [self.annotManage resetAnnotation:annotStyle];
+    }
 }
 
 @end

+ 6 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.h

@@ -2,7 +2,12 @@
 //  CPDFAnnotationBarButton.h
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/21.
+//  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>
@@ -11,8 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface CPDFAnnotationBarButton : UIButton
 
-@property (nonatomic, assign) NSInteger type;
-
 @property (nonatomic, strong) UIColor *lineColor;
 
 @end

+ 11 - 5
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBarButton.m

@@ -2,10 +2,16 @@
 //  CPDFAnnotationBarButton.m
 //  compdfkit-tools
 //
-//  Created by kdanmobile_2 on 2023/4/21.
+//  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 "CPDFAnnotationBarButton.h"
+#import "CPDFListView.h"
 
 @implementation CPDFAnnotationBarButton
 
@@ -14,19 +20,19 @@
     CGRect imageFrame = self.imageView.frame;
     CGContextRef ctx = UIGraphicsGetCurrentContext();
     CGContextSetStrokeColorWithColor(ctx, self.lineColor.CGColor);
-    if (self.type == 1) {
+    if (self.tag == CPDFViewAnnotationModeHighlight) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame)-2, CGRectGetMidY(imageFrame));
         CGContextSetLineWidth(ctx, CGRectGetHeight(imageFrame));
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame)+2, CGRectGetMidY(imageFrame));
-    }else if (self.type == 2) {
+    }else if (self.tag == CPDFViewAnnotationModeUnderline) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMaxY(imageFrame));
-    } else if (self.type == 3) {
+    } else if (self.tag == CPDFViewAnnotationModeStrikeout) {
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMidY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);
         CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMidY(imageFrame));
-    } else if (self.type == 4) {
+    } else if (self.tag == CPDFViewAnnotationModeSquiggly) {
         float tWidth = imageFrame.size.width / 6.0;
         CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
         CGContextSetLineWidth(ctx, 2.0);

+ 1 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFAnnotationSampleView.m

@@ -36,7 +36,7 @@
 - (void)drawRect:(CGRect)rect {
     [super drawRect:rect];
     CGContextRef context = UIGraphicsGetCurrentContext();
-    self.centerRect = CGRectInset(rect, 130, 40);
+    self.centerRect = CGRectInset(rect, 130, self.bounds.size.height/3);
     self.arrowRect = CGRectInset(rect, 100, 20);
     
     [self drawSamples:context];

+ 2 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFColorPickerView.m

@@ -41,12 +41,14 @@
     if (self == [super initWithFrame:frame]) {
         _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - 120)/2, 0, 120, (self.bounds.size.height - 40)/6)];
         _titleLabel.text = NSLocalizedString(@"Custom Color", nil);
+        _titleLabel.adjustsFontSizeToFitWidth = YES;
         _titleLabel.autoresizingMask  = UIViewAutoresizingFlexibleHeight;
         [self addSubview:self.titleLabel];
         
         _backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, (self.bounds.size.height - 40)/6)];
         _backBtn.autoresizingMask = UIViewAutoresizingFlexibleHeight;
         [_backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBarImageUndo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
+        [_backBtn sizeToFit];
         [_backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
         [self addSubview:self.backBtn];
         

+ 5 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFColorSelectView.m

@@ -31,7 +31,7 @@
 
 - (instancetype)initWithFrame:(CGRect)frame {
     if (self = [super initWithFrame:frame]) {
-        self.colorLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 50, 30)];
+        self.colorLabel = [[UILabel alloc] init];
         self.colorLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
         self.colorLabel.text = NSLocalizedString(@"Fill:", nil);
         self.colorLabel.adjustsFontSizeToFitWidth = YES;
@@ -72,8 +72,8 @@
                         [UIColor clearColor]];
     for (int i = 0; i < 6; i++) {
         UIButton *button = (UIButton *)self.colorArray[i];
-        button.frame = CGRectMake((self.bounds.size.width - 300)/7 * (i+1) + 50 * i, 5, 50, 50);
-        [[button layer] setCornerRadius:25];
+        button.frame = CGRectMake((self.bounds.size.width - 300)/7 * (i+1) + 50 * i, 5, self.colorPickerView.bounds.size.height - 10, self.colorPickerView.bounds.size.height - 10);
+        [[button layer] setCornerRadius:(self.colorPickerView.bounds.size.height - 10)/2];
         button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
         button.backgroundColor = colors[i];
         button.tag = i;
@@ -86,6 +86,8 @@
 
 - (void)layoutSubviews {
     [super layoutSubviews];
+    self.colorLabel.frame = CGRectMake(5, 0, 50, self.bounds.size.height/3);
+    self.colorPickerView.frame = CGRectMake(0, self.bounds.size.height/3, self.bounds.size.width, (self.bounds.size.height/3)*2);
     [self pickerBarInit];
 }
 

+ 22 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "filename" : "annotation_drag_dot.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "annotation_drag_dot@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/annotation_drag_dot.png


BIN
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/CPDFListViewImageNameAnnotationDragDot.imageset/annotation_drag_dot@2x.png


+ 20 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/Image.xcassets/Image.imageset/Contents.json

@@ -0,0 +1,20 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 17 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+Extensions.h

@@ -0,0 +1,17 @@
+//
+//  KMPDFAnnotation+KMExtensions.h
+//  PDFReader
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  The PDF Reader Sample applications are licensed with a modified BSD license.
+//  Please see License for details. This notice may not be removed from this file.
+//
+
+#import <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFAnnotation (Extensions)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 19 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+PDFListView.h

@@ -0,0 +1,19 @@
+//
+//  CPDFAnnotation+PDFListView.h
+//  compdfkit-tools
+//
+//  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 <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 29 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotation+PDFListView.m

@@ -0,0 +1,29 @@
+//
+//  CPDFAnnotation+PDFListView.m
+//  compdfkit-tools
+//
+//  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 "CPDFAnnotation+PDFListView.h"
+#import "CPDFAnnotationHeader.h"
+
+@implementation CPDFAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *keys = nil;
+    if (keys == nil)
+        keys = [[NSSet alloc] initWithObjects:CPDFAnnotationBoundsKey,
+                                              CPDFAnnotationborderWidthKey,
+                                              CPDFAnnotationBorderKey,
+                                              CPDFAnnotationOpacityKey,
+                                              CPDFAnnotationColorKey, nil];
+    return keys;
+}
+
+@end

+ 56 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFAnnotationHeader.h

@@ -0,0 +1,56 @@
+//
+//  CPDFAnnotationHeader_h
+//  compdfkit-tools
+//
+//  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.
+//
+
+#ifndef CPDFAnnotationHeader_h
+#define CPDFAnnotationHeader_h
+
+#import "CPDFAnnotation+PDFListView.h"
+
+static NSString *CPDFAnnotationBoundsKey = @"bounds";
+
+static NSString *CPDFAnnotationContentKey = @"contents";
+
+static NSString *CPDFAnnotationborderWidthKey = @"borderWidth";
+
+static NSString *CPDFAnnotationBorderKey = @"border";
+
+static NSString *CPDFAnnotationOpacityKey = @"opacity";
+
+static NSString *CPDFAnnotationColorKey = @"color";
+
+static NSString *CPDFAnnotationModificationDateKey = @"modificationDate";
+
+static NSString *CPDFAnnotationUserNameKey = @"userName";
+
+static NSString *CPDFAnnotationInteriorOpacityKey = @"interiorOpacity";
+
+static NSString *CPDFAnnotationInteriorColorKey = @"interiorColor";
+
+static NSString *CPDFAnnotationBorderColorKey = @"borderColor";
+
+static NSString *CPDFAnnotationBackgroundColorKey = @"backgroundColor";
+
+static NSString *CPDFAnnotationFontKey = @"font";
+
+static NSString *CPDFAnnotationFontColorKey = @"fontColor";
+
+static NSString *CPDFAnnotationStateKey = @"state";
+
+static NSString *CPDFAnnotationSelectItemAtIndexKey = @"selectItemAtIndex";
+
+static NSString *CPDFAnnotationAlignmentKey = @"alignment";
+
+static NSString *CPDFAnnotationStartPointKey = @"startPoint";
+
+static NSString *CPDFAnnotationEndPointKey = @"endPoint";
+
+#endif /* PDFAnnotationHeader_h */

+ 17 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+Extensions.h

@@ -0,0 +1,17 @@
+//
+//  CPDFCircleAnnotation+KMExtensions.h
+//  PDFReader
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  The PDF Reader Sample applications are licensed with a modified BSD license.
+//  Please see License for details. This notice may not be removed from this file.
+//
+
+#import <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFCircleAnnotation (Extensions)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 19 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+PDFListView.h

@@ -0,0 +1,19 @@
+//
+//  CPDFCircleAnnotation+PDFListView.h
+//  compdfkit-tools
+//
+//  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 <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFCircleAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 29 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFCircleAnnotation+PDFListView.m

@@ -0,0 +1,29 @@
+//
+//  CPDFCircleAnnotation+PDFListView.m
+//  compdfkit-tools
+//
+//  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 "CPDFCircleAnnotation+PDFListView.h"
+#import "CPDFAnnotationHeader.h"
+
+@implementation CPDFCircleAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *circleKeys = nil;
+    if (circleKeys == nil) {
+        NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] mutableCopy];
+        [mutableKeys addObject:CPDFAnnotationInteriorColorKey];
+        [mutableKeys addObject:CPDFAnnotationInteriorOpacityKey];
+        circleKeys = [mutableKeys copy];
+    }
+    return circleKeys;
+}
+
+@end

+ 19 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFFreeTextAnnotation+PDFListView.h

@@ -0,0 +1,19 @@
+//
+//  CPDFFreeTextAnnotation+PDFListView.h
+//  compdfkit-tools
+//
+//  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 <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFFreeTextAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 30 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFFreeTextAnnotation+PDFListView.m

@@ -0,0 +1,30 @@
+//
+//  CPDFFreeTextAnnotation+PDFListView.m
+//  compdfkit-tools
+//
+//  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 "CPDFFreeTextAnnotation+PDFListView.h"
+#import "CPDFAnnotationHeader.h"
+
+@implementation CPDFFreeTextAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *freetextKeys = nil;
+    if (freetextKeys == nil) {
+        NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] mutableCopy];
+        [mutableKeys addObjectsFromArray:@[CPDFAnnotationFontKey,
+                                           CPDFAnnotationFontColorKey,
+                                           CPDFAnnotationAlignmentKey]];
+        freetextKeys = [mutableKeys copy];
+    }
+    return freetextKeys;
+}
+
+@end

+ 19 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFLineAnnotation+PDFListView.h

@@ -0,0 +1,19 @@
+//
+//  CPDFLineAnnotation+PDFListView.h
+//  compdfkit-tools
+//
+//  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 <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFLineAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 31 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFLineAnnotation+PDFListView.m

@@ -0,0 +1,31 @@
+//
+//  CPDFLineAnnotation+PDFListView.m
+//  compdfkit-tools
+//
+//  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 "CPDFLineAnnotation+PDFListView.h"
+#import "CPDFAnnotationHeader.h"
+
+@implementation CPDFLineAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *lineKeys = nil;
+    if (lineKeys == nil) {
+        NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] mutableCopy];
+        [mutableKeys addObjectsFromArray:@[CPDFAnnotationStartPointKey,
+                                           CPDFAnnotationEndPointKey,
+                                           CPDFAnnotationInteriorOpacityKey,
+                                           CPDFAnnotationInteriorColorKey]];
+        lineKeys = [mutableKeys copy];
+    }
+    return lineKeys;
+}
+
+@end

+ 19 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFSquareAnnotation+PDFListView.h

@@ -0,0 +1,19 @@
+//
+//  CPDFSquareAnnotation+PDFListView.h
+//  compdfkit-tools
+//
+//  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 <ComPDFKit/ComPDFKit.h>
+
+@interface CPDFSquareAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo;
+
+@end

+ 29 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFKit Categories/CPDFSquareAnnotation+PDFListView.m

@@ -0,0 +1,29 @@
+//
+//  CPDFSquareAnnotation+PDFListView.m
+//  compdfkit-tools
+//
+//  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 "CPDFSquareAnnotation+PDFListView.h"
+#import "CPDFAnnotationHeader.h"
+
+@implementation CPDFSquareAnnotation (PDFListView)
+
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *circleKeys = nil;
+    if (circleKeys == nil) {
+        NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] mutableCopy];
+        [mutableKeys addObject:CPDFAnnotationInteriorColorKey];
+        [mutableKeys addObject:CPDFAnnotationInteriorOpacityKey];
+        circleKeys = [mutableKeys copy];
+    }
+    return circleKeys;
+}
+
+@end

+ 115 - 56
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.m

@@ -45,7 +45,6 @@
 }
 
 - (void)showMenuForAnnotation:(CPDFAnnotation *)annotation {
-    self.menuAnnotation = annotation;
     if (!annotation) {
         [UIMenuController sharedMenuController].menuItems = nil;
         [[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
@@ -201,8 +200,11 @@
 
 - (void)annotationTouchMovedAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
     if (self.textSelectionMode) {
-        
     } else if (CPDFAnnotationDraggingNone != self.draggingType) {
+        if(!self.undoMove) {
+            [[self undoPDFManager] beginUndoGrouping];
+            self.undoMove = YES;
+        }
         [self moveAnnotation:self.activeAnnotation fromPoint:self.draggingPoint toPoint:point forType:self.draggingType];
         [self setNeedsDisplayForPage:page];
         self.draggingPoint = point;
@@ -254,43 +256,33 @@
             if (CPDFViewAnnotationModeNone == self.annotationMode) {
                 CPDFAnnotation *annotation = [page annotationAtPoint:point];
                 if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
-                    if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformOpenNote:forAnnotation:)]) {
-                        [self.performDelegate PDFViewPerformOpenNote:self forAnnotation:annotation];
+                    [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];
-                    } else {
-//                        if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformPopup:forAnnotation:)]) {
-//                            [self.performDelegate PDFViewPerformPopup:self forAnnotation:(CPDFMarkupAnnotation *)annotation];
-//                        }
                     }
                 } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
                     [super touchEndedAtPoint:point forPage:page];
                 } else if ([annotation isKindOfClass:[CPDFMovieAnnotation class]]) {
                     [super touchEndedAtPoint:point forPage:page];
                 } else if ([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
-                    if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
-                        if ([(CPDFSignatureWidgetAnnotation *)annotation isSigned]) {
-                            [self showMenuForAnnotation:annotation];
-                        } else {
-//                            if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformSignatureWidget:forAnnotation:)]) {
-//                                [self.performDelegate PDFViewPerformSignatureWidget:self forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation];
-//                            }
-                        }
-                    } else {
-                        [super touchEndedAtPoint:point forPage:page];
-                    }
+                    [super touchEndedAtPoint:point forPage:page];
                 } else {
                     [self updateActiveAnnotations:@[annotation]];
                     [self setNeedsDisplayForPage:page];
                     [self updateScrollEnabled];
                     
                     [self showMenuForAnnotation:annotation];
-
+                    
                     if (!self.activeAnnotation) {
-                        if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
-                            [self.performDelegate PDFViewPerformTouchEnded:self];
+                        if ([self.performDelegate respondsToSelector:@selector(PDFListViewPerformTouchEnded:)]) {
+                            [self.performDelegate PDFListViewPerformTouchEnded:self];
                         }
                     }
                 }
@@ -301,24 +293,20 @@
                         [self updateActiveAnnotations:@[annotation]];
                         [self setNeedsDisplayForPage:page];
                         [self updateScrollEnabled];
-
+                        
                         [self showMenuForAnnotation:annotation];
                     }
                 } else {
-//                    [self addAnnotationLinkAtPoint:point forPage:page];
+                    [self addAnnotationLinkAtPoint:point forPage:page];
                 }
             } else if (CPDFViewAnnotationModeFreeText == self.annotationMode) {
-//                [self addAnnotationFreeTextAtPoint:point forPage:page];
+                [self addAnnotationFreeTextAtPoint:point forPage:page];
             } else if (CPDFViewAnnotationModeStamp == self.annotationMode) {
-//                [self addAnnotationAtPoint:point forPage:page];
-                if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
-                    [self.performDelegate PDFViewPerformTouchEnded:self];
-                }
+                [self addAnnotationAtPoint:point forPage:page];
+                self.annotationMode = CPDFViewAnnotationModeNone;
             } else if (CPDFViewAnnotationModeImage == self.annotationMode) {
-//                [self addAnnotationAtPoint:point forPage:page];
-                if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
-                    [self.performDelegate PDFViewPerformTouchEnded:self];
-                }
+                [self addAnnotationAtPoint:point forPage:page];
+                self.annotationMode = CPDFViewAnnotationModeNone;
             } else {
                 [self addAnnotation:self.annotationMode atPoint:point forPage:page];
             }
@@ -333,6 +321,11 @@
             }
         }
         
+        if(self.undoMove) {
+            [[self undoPDFManager] endUndoGrouping];
+            self.undoMove = NO;
+        }
+        
         self.draggingType = CPDFAnnotationDraggingNone;
         
         [self showMenuForAnnotation:self.activeAnnotation];
@@ -342,6 +335,12 @@
 
 - (void)annotationTouchCancelledAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
     self.draggingType = CPDFAnnotationDraggingNone;
+    [self removeMagnifier];
+    
+    if(self.undoMove) {
+        [[self undoPDFManager] endUndoGrouping];
+        self.undoMove = NO;
+    }
 }
 
 - (void)annotationDrawPage:(CPDFPage *)page toContext:(CGContextRef)context {
@@ -416,7 +415,7 @@
                                          tEndPoint.y - dragDotSize.height/2.0,
                                          dragDotSize.width, dragDotSize.height);
         
-        UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
+        UIImage *image = [UIImage imageNamed:@"CPDFListViewImageNameAnnotationDragDot" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
         CGImageRef dragDotImage = image.CGImage;
         
         CGContextDrawImage(context, startPointRect, dragDotImage);
@@ -447,7 +446,7 @@
             rightCenterRect = CGRectApplyAffineTransform(rightCenterRect, CGAffineTransformInvert(transform));
         }
         
-        UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
+        UIImage *image = [UIImage imageNamed:@"CPDFListViewImageNameAnnotationDragDot" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
         CGImageRef dragDotImage = image.CGImage;
         
         CGContextDrawImage(context, leftCenterRect, dragDotImage);
@@ -481,7 +480,7 @@
                                             CGRectGetMinY(rect)-dragDotSize.height/2.0,
                                             dragDotSize.width, dragDotSize.height);
         
-        UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
+        UIImage *image = [UIImage imageNamed:@"CPDFListViewImageNameAnnotationDragDot" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
         CGImageRef dragDotImage = image.CGImage;
         
         CGContextDrawImage(context, topLeftRect, dragDotImage);
@@ -694,15 +693,13 @@
 - (void)addAnnotation:(CPDFViewAnnotationMode)mode atPoint:(CGPoint)point forPage:(CPDFPage *)page {
     CPDFAnnotation *annotation = nil;
     switch (mode) {
-        case CPDFViewAnnotationModeNote:
-        {
+        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:
-        {
+        case CPDFViewAnnotationModeHighlight: {
             if (!self.currentSelection) {
                 return;
             }
@@ -720,8 +717,7 @@
             [self clearSelection];
         }
             break;
-        case CPDFViewAnnotationModeUnderline:
-        {
+        case CPDFViewAnnotationModeUnderline: {
             if (!self.currentSelection) {
                 return;
             }
@@ -739,8 +735,7 @@
             [self clearSelection];
         }
             break;
-        case CPDFViewAnnotationModeStrikeout:
-        {
+        case CPDFViewAnnotationModeStrikeout: {
             if (!self.currentSelection) {
                 return;
             }
@@ -758,8 +753,7 @@
             [self clearSelection];
         }
             break;
-        case CPDFViewAnnotationModeSquiggly:
-        {
+        case CPDFViewAnnotationModeSquiggly: {
             if (!self.currentSelection) {
                 return;
             }
@@ -777,28 +771,24 @@
             [self clearSelection];
         }
             break;
-        case CPDFViewAnnotationModeCircle:
-        {
+        case CPDFViewAnnotationModeCircle: {
             annotation = [[CPDFCircleAnnotation alloc] initWithDocument:self.document];
             annotation.bounds = CGRectMake(point.x-50, point.y-50, 100, 100);
         }
             break;
-        case CPDFViewAnnotationModeSquare:
-        {
+        case CPDFViewAnnotationModeSquare: {
             annotation = [[CPDFSquareAnnotation alloc] initWithDocument:self.document];
             annotation.bounds = CGRectMake(point.x-50, point.y-50, 100, 100);
         }
             break;
-        case CPDFViewAnnotationModeArrow:
-        {
+        case CPDFViewAnnotationModeArrow: {
             annotation = [[CPDFLineAnnotation alloc] initWithDocument:self.document];
             [(CPDFLineAnnotation *)annotation setStartPoint:CGPointMake(point.x-50, point.y)];
             [(CPDFLineAnnotation *)annotation setEndPoint:CGPointMake(point.x+50, point.y)];
             [(CPDFLineAnnotation *)annotation setEndLineStyle:CPDFLineStyleClosedArrow];
         }
             break;
-        case CPDFViewAnnotationModeLine:
-        {
+        case CPDFViewAnnotationModeLine: {
             annotation = [[CPDFLineAnnotation alloc] initWithDocument:self.document];
             [(CPDFLineAnnotation *)annotation setStartPoint:CGPointMake(point.x-50, point.y)];
             [(CPDFLineAnnotation *)annotation setEndPoint:CGPointMake(point.x+50, point.y)];
@@ -816,9 +806,10 @@
     [page addAnnotation:annotation];
     
     if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+        [self updateActiveAnnotations:@[annotation]];
         [self setNeedsDisplayForPage:page];
-        if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformOpenNote:forAnnotation:)]) {
-            [self.performDelegate PDFViewPerformOpenNote:self forAnnotation:annotation];
+        if ([self.performDelegate respondsToSelector:@selector(PDFListViewEditNote:forAnnotation:)]) {
+            [self.performDelegate PDFListViewEditNote:self forAnnotation:annotation];
         }
     } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
         [self setNeedsDisplayForPage:page];
@@ -831,6 +822,74 @@
     }
 }
 
+- (void)addAnnotationAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
+    CPDFAnnotation *annotation = self.addAnnotation;
+    if (!annotation) {
+        return;
+    }
+    annotation.bounds = CGRectMake(point.x-annotation.bounds.size.width/2.0,
+                                   point.y-annotation.bounds.size.height/2.0,
+                                   annotation.bounds.size.width, annotation.bounds.size.height);
+    [annotation setModificationDate:[NSDate date]];
+    [annotation setUserName:[self annotationUserName]];
+    [page addAnnotation:annotation];
+    
+    [self updateActiveAnnotations:@[annotation]];
+    [self setNeedsDisplayForPage:page];
+    [self updateScrollEnabled];
+    
+    [self showMenuForAnnotation:annotation];
+    [self updateActiveAnnotations:@[]];
+}
+
+- (void)addAnnotationLinkAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
+    CPDFLinkAnnotation *annotation = [[CPDFLinkAnnotation alloc] initWithDocument:self.document]    ;
+    annotation.bounds = self.addLinkRect;
+    [annotation setModificationDate:[NSDate date]];
+    [annotation setUserName:[self annotationUserName]];
+    [page addAnnotation:annotation];
+    
+    self.addLinkPoint = CGPointZero;
+    self.addLinkRect = CGRectZero;
+    [self setNeedsDisplayForPage:page];
+    
+    if(annotation)
+        [self updateActiveAnnotations:annotation];
+
+    if ([self.performDelegate respondsToSelector:@selector(PDFListViewEditNote:forAnnotation:)]) {
+        [self.performDelegate PDFListViewEditNote:self forAnnotation:annotation];
+    }
+}
+
+- (void)addAnnotationFreeTextAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
+    CPDFFreeTextAnnotation *annotation = [[CPDFFreeTextAnnotation alloc] initWithDocument:self.document];
+    if (CPDFKitShareConfig.enableAnnotationNoRotate) {
+        CGFloat width;
+        CGAffineTransform transform = [page transform];
+        point = CGPointApplyAffineTransform(point, transform);
+        if (page.rotation == 90 ||
+            page.rotation == 270) {
+            width = CGRectGetMaxY(page.bounds) - point.x - 20;
+        } else {
+            width = CGRectGetMaxX(page.bounds) - point.x - 20;
+        }
+        CGRect bounds = CGRectMake(point.x, point.y, width, annotation.font.pointSize);
+        bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformInvert(transform));
+        annotation.bounds = bounds;
+    } else {
+        CGFloat width = CGRectGetMaxX(page.bounds) - point.x - 20;
+        annotation.bounds = CGRectMake(point.x, point.y, width, annotation.font.pointSize);
+    }
+    [annotation setModificationDate:[NSDate date]];
+    [annotation setUserName:[self annotationUserName]];
+    [page addAnnotation:annotation];
+    
+    if(annotation) {
+        [self updateActiveAnnotations:annotation];
+        [self editAnnotationFreeText:annotation];
+    }
+}
+
 - (void)addAnnotation:(CPDFAnnotation *)annotation forPage:(CPDFPage *)page {
     if (!annotation || !page) {
         return;

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

@@ -145,7 +145,7 @@
 
 - (void)propertyEditingItemAction:(UIMenuItem*)menuItem {
     
-    if(self.performDelegate && [self.performDelegate respondsToSelector:@selector(PDFListViewCustomMenuClick:identifier:)]) {
+    if(self.performDelegate && [self.performDelegate respondsToSelector:@selector(PDFListViewCustomMenuClick:identifier:)]){
         [self.performDelegate PDFListViewCustomMenuClick:self identifier:@"PropertyItem"];
     }
 }

+ 13 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Private.h

@@ -47,17 +47,27 @@ typedef NS_ENUM(NSInteger, CPDFAnnotationDraggingType) {
 
 @property (nonatomic, assign) CGPoint draggingPoint;
 
+@property (nonatomic, assign) CGPoint menuPoint;
+
+@property (nonatomic, assign) CPDFPage *menuPage;
+
 @property (nonatomic, strong) CPDFAnnotation *menuAnnotation;
 
 @property (nonatomic, strong) NSMutableArray <CPDFAnnotation *>*activeAnnotations;
 
 @property (nonatomic, readonly) CPDFAnnotation *activeAnnotation;
 
-@property (nonatomic, assign) CGPoint menuPoint;
+@property (nonatomic, strong) CPDFListMagnifierView *magnifierView;
 
-@property (nonatomic, assign) CPDFPage *menuPage;
+@property (nonatomic, strong) NSMutableArray *notes;
 
-@property (nonatomic, strong) CPDFListMagnifierView *magnifierView;
+@property (nonatomic, strong) NSMapTable *undoGroupOldPropertiesPerNote;
+
+@property (nonatomic, strong) NSUndoManager *undoPDFManager;
+
+@property (nonatomic, assign) BOOL undoMove;
+
+@property (nonatomic,retain) CPDFAnnotation *addAnnotation;
 
 - (NSString *)annotationUserName;
 

+ 27 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+UndoManager.h

@@ -0,0 +1,27 @@
+//
+//  CPDFListView+UndoManager.h
+//  compdfkit-tools
+//
+//  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 <compdfkit_tools/compdfkit_tools.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CPDFListView (UndoManager)
+
+- (void)registerAsObserver;
+
+- (BOOL)canUndo;
+
+- (BOOL)canRedo;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 190 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+UndoManager.m

@@ -0,0 +1,190 @@
+//
+//  CPDFListView+UndoManager.m
+//  compdfkit-tools
+//
+//  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 "CPDFListView+UndoManager.h"
+#import "CPDFAnnotationHeader.h"
+#import "CPDFListView+Private.h"
+
+static NSString *CPDFAnnotationPropertiesObservationContext = @"CPDFAnnotationPropertiesObservationContext";
+
+@implementation CPDFListView (UndoManager)
+
+#pragma mark - Public method
+
+- (void)registerAsObserver {
+    self.undoPDFManager = [[NSUndoManager alloc]init];
+    
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PDFPageDidLoadAnnotationNotification:) name:@"CPDFPageDidLoadAnnotationNotification" object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PDFPageDidAddAnnotationNotification:) name:@"CPDFPageDidAddAnnotationNotification" object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PDFPageDidRemoveAnnotationNotification:) name:@"CPDFPageDidRemoveAnnotationNotification" object:nil];
+}
+
+- (BOOL)canUndo {
+    return [[self undoPDFManager] canUndo];
+}
+
+- (BOOL)canRedo {
+    return [[self undoPDFManager] canRedo];
+}
+
+#pragma mark - Private method
+
+- (void)startObservingNotes:(NSArray *)newNotes {
+    if (!self.notes) {
+        self.notes = [NSMutableArray array];
+    }
+    for (CPDFAnnotation *note in newNotes) {
+        if (![self.notes containsObject:note]) {
+            [self.notes addObject:note];
+        }
+        for (NSString *key in [note keysForValuesToObserveForUndo]) {
+            [note addObserver:self forKeyPath:key options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:&CPDFAnnotationPropertiesObservationContext];
+        }
+    }
+}
+
+- (void)stopObservingNotes:(NSArray *)oldNotes {
+    for (CPDFAnnotation *note in oldNotes) {
+        for (NSString *key in [note keysForValuesToObserveForUndo])
+            [note removeObserver:self forKeyPath:key];
+    }
+}
+
+- (void)undoAddAnnotation:(CPDFAnnotation *)annotation {
+    [[[self undoPDFManager] prepareWithInvocationTarget:self] removeAnnotation:annotation];
+}
+
+- (void)removeAnnotation:(CPDFAnnotation *)annotation {
+    CPDFPage *page = annotation.page;
+    
+    if (self.activeAnnotation == annotation)
+        [self updateActiveAnnotations:@[]];
+    
+    [self setNeedsDisplayForPage:page];
+    [page removeAnnotation:annotation];
+}
+
+- (void)undoRemoveAnnotation:(CPDFAnnotation *)annotation {
+    [[[self undoPDFManager] prepareWithInvocationTarget:self] undoAddAnnotation:annotation forPage:annotation.page];
+}
+
+- (void)undoAddAnnotation:(CPDFAnnotation *)annotation forPage:(CPDFPage *)page {
+    if (!annotation || !page) {
+        return;
+    }
+    
+    NSString *annotationUserName = CPDFKitShareConfig.annotationAuthor;
+    if (!annotationUserName || [annotationUserName length] <= 0) {
+        annotationUserName = [[UIDevice currentDevice] name];
+    }
+    
+    [annotation setModificationDate:[NSDate date]];
+    [annotation setUserName:annotationUserName];
+    [page addAnnotation:annotation];
+    
+    [self setNeedsDisplayForPage:page];
+    
+    if (self.activeAnnotation) {
+        self.scrollEnabled = NO;
+    } else {
+        if (CPDFViewAnnotationModeLink == self.annotationMode) {
+            self.scrollEnabled = NO;
+        } else {
+            self.scrollEnabled = YES;
+        }
+    }
+}
+
+- (void)setNoteProperties:(NSMapTable *)propertiesPerNote {
+    for (CPDFAnnotation *note in propertiesPerNote) {
+        NSDictionary *noteProperties = [propertiesPerNote objectForKey:note];
+        [note setValuesForKeysWithDictionary:noteProperties];
+        [self setNeedsDisplayForPage:note.page];
+    }
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
+    if (context == &CPDFAnnotationPropertiesObservationContext) {
+        CPDFAnnotation *note = (CPDFAnnotation *)object;
+        id newValue = [change objectForKey:NSKeyValueChangeNewKey] ?: [NSNull null];
+        id oldValue = [change objectForKey:NSKeyValueChangeOldKey] ?: [NSNull null];
+        if ([newValue isEqual:oldValue] == NO) {
+            NSUndoManager *undoManager = [self undoPDFManager];
+            BOOL isUndoOrRedo = ([undoManager isUndoing] || [undoManager isRedoing]);
+            if ([keyPath isEqual:CPDFAnnotationStateKey] ||
+                [keyPath isEqual:CPDFAnnotationSelectItemAtIndexKey]) {
+                if (isUndoOrRedo == NO)
+                    [undoManager setActionName:NSLocalizedString(@"Edit Note", @"Undo action name")];
+            } else {
+                self.undoGroupOldPropertiesPerNote = [[NSMapTable alloc] initWithKeyOptions:  NSMapTableObjectPointerPersonality valueOptions:NSMapTableStrongMemory | NSMapTableObjectPointerPersonality capacity:0];
+                [undoManager registerUndoWithTarget:self selector:@selector(setNoteProperties:) object:self.undoGroupOldPropertiesPerNote];
+                if (isUndoOrRedo == NO)
+                    [undoManager setActionName:NSLocalizedString(@"Edit Note", @"Undo action name")];
+                
+                NSMutableDictionary *oldNoteProperties = [self.undoGroupOldPropertiesPerNote objectForKey:note];
+                if (oldNoteProperties == nil) {
+                    oldNoteProperties = [[NSMutableDictionary alloc] init];
+                    [self.undoGroupOldPropertiesPerNote setObject:oldNoteProperties forKey:note];
+                    if (isUndoOrRedo == NO && [keyPath isEqualToString:CPDFAnnotationModificationDateKey] == NO)
+                        [note setModificationDate:[NSDate date]];
+                }
+                
+                if ([oldNoteProperties objectForKey:keyPath] == nil)
+                    [oldNoteProperties setObject:oldValue forKey:keyPath];
+            }
+        }
+    } else {
+        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+    }
+}
+
+#pragma mark - NSNotification
+
+- (void)PDFPageDidLoadAnnotationNotification:(NSNotification *)notification
+{
+    CPDFAnnotation *annotation = [notification object];
+    if (annotation.page &&
+        [annotation isKindOfClass:[CPDFAnnotation class]] &&
+        ![annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+        [self startObservingNotes:@[annotation]];
+    }
+}
+
+- (void)PDFPageDidAddAnnotationNotification:(NSNotification *)notification
+{
+    CPDFAnnotation *annotation = [notification object];
+    if (annotation.page &&
+        [annotation isKindOfClass:[CPDFAnnotation class]] &&
+        ![annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+        [self startObservingNotes:@[annotation]];
+        
+        [self undoAddAnnotation:annotation];
+
+    }
+}
+
+- (void)PDFPageDidRemoveAnnotationNotification:(NSNotification *)notification
+{
+    CPDFAnnotation *annotation = [notification object];
+    if (annotation.page &&
+        [annotation isKindOfClass:[CPDFAnnotation class]] &&
+        ![annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+        [self undoRemoveAnnotation:annotation];
+
+        [self stopObservingNotes:@[annotation]];
+        
+        if ([self.notes containsObject:annotation]) {
+            [self.notes removeObject:annotation];
+        }
+    }
+}
+@end

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

@@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, CPDFViewAnnotationMode) {
     CPDFViewAnnotationModeLine,
     CPDFViewAnnotationModeInk,
     CPDFViewAnnotationModeFreeText,
+    CPDFViewAnnotationModeSignature,
     CPDFViewAnnotationModeStamp,
     CPDFViewAnnotationModeImage,
     CPDFViewAnnotationModeLink,
@@ -57,7 +58,7 @@ extern NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification;
 
 - (NSArray<UIMenuItem *> *)PDFListView:(CPDFListView *)pdfListView customizeMenuForPage:(CPDFPage *)page forPagePoint:(CGPoint)pagePoint;
 
-- (void)PDFListViewPerformOpenNote:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation;
+- (void)PDFListViewEditNote:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation;
 
 - (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfListView;
 

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

@@ -12,6 +12,7 @@
 
 #import "CPDFListView.h"
 #import "CPDFListView+Annotation.h"
+#import "CPDFListView+UndoManager.h"
 #import "CPDFListView+Private.h"
 
 #import "CPDFColorUtils.h"
@@ -42,6 +43,8 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
         
         [self addNotification];
         
+        // undo redo
+        [self registerAsObserver];
     }
     return self;
 }
@@ -54,6 +57,9 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
         [self commomInit];
 
         [self addNotification];
+        
+        // undo redo
+        [self registerAsObserver];
     }
     return self;
 }
@@ -95,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];
@@ -159,6 +165,9 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
     } else if (CToolModelEdit == self.toolModel) {
         
     } else {
+        if ([self.performDelegate respondsToSelector:@selector(PDFListViewPerformTouchEnded:)]) {
+            [self.performDelegate PDFListViewPerformTouchEnded:self];
+        }
     }
 }
 

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

@@ -59,7 +59,8 @@
 #import <compdfkit_tools/CPDFStrikeoutViewController.h>
 #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>

+ 1 - 1
viewer-ctrl-demo/viewer-ctrl-demo/CPDFViewController.m

@@ -190,7 +190,7 @@
     return nil;
 }
 
-- (void)PDFViewPerformTouchEnded:(CPDFListView *)pdfView {
+- (void)PDFListViewPerformTouchEnded:(CPDFListView *)pdfView {
     if (CPDFViewAnnotationModeNone != self.pdfListView.annotationMode) {
         self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
         return;