Ver Fonte

PDFForm(iOS) - 支持创建Form相关

dinglingui há 1 ano atrás
pai
commit
7715e5b416

+ 3 - 3
Form-Ctrl-Demo/Form-Ctrl-Demo/CPDFViewController.m

@@ -260,9 +260,9 @@
 //    }
 //}
 //
-//- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
-//    [self.annotationBar reloadData];
-//}
+- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
+    [self.formBar reloadData];
+}
 //
 //- (void)PDFListViewPerformAddStamp:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
 //    [self.annotationBar addStampAnnotationWithPage:page point:point];

+ 1 - 1
compdfkit-tools/compdfkit-tools.xcodeproj/xcuserdata/dinglingui.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -7,7 +7,7 @@
 		<key>compdfkit-tools.xcscheme_^#shared#^_</key>
 		<dict>
 			<key>orderHint</key>
-			<integer>3</integer>
+			<integer>5</integer>
 		</dict>
 	</dict>
 </dict>

+ 0 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.h

@@ -30,9 +30,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)updateScrollEnabled;
 
-- (void)clea;
-
-
 @end
 
 NS_ASSUME_NONNULL_END

+ 17 - 47
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Annotation.m

@@ -60,36 +60,6 @@
     return [[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObjects:textType, urlType, urlFileType, jpegImageType, pngImageType, rawImageType, nil]];
 }
 
-- (BOOL)doSelectAnnotationWithPoint:(CGPoint)point withPage:(CPDFPage *)page {
-    CPDFAnnotation *newActiveAnnotation = nil;
-    
-    if ([self.activeAnnotation page] == page  && CGRectContainsPoint(self.activeAnnotation.bounds, point)) {
-        newActiveAnnotation = self.activeAnnotation;
-    } else {
-        newActiveAnnotation = [page annotationAtPoint:point];
-    }
-    
-    if(newActiveAnnotation && [newActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
-        if(CPDFViewAnnotationModeLink != self.annotationMode) {
-            newActiveAnnotation = nil;
-        }
-    }
-    
-    if (newActiveAnnotation && ![self.activeAnnotations containsObject:newActiveAnnotation]) {
-        [self updateActiveAnnotations:@[newActiveAnnotation]];
-        [self setNeedsDisplayForPage:page];
-    } else {
-        if(self.activeAnnotations.count > 0) {
-            CPDFPage *previousPage = self.activeAnnotation.page;
-            [self updateActiveAnnotations:@[]];
-            [self setNeedsDisplayForPage:previousPage];
-            [self updateScrollEnabled];
-        }
-    }
-    
-    return newActiveAnnotation != nil;
-}
-
 - (void)showMenuForAnnotation:(CPDFAnnotation *)annotation {
     if (!annotation) {
         [UIMenuController sharedMenuController].menuItems = nil;
@@ -395,8 +365,8 @@
 - (void)annotationTouchBeganAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
     if (self.textSelectionMode) {
     } else {
-        self.addLinkPoint = point;
-        self.addLinkRect = CGRectZero;
+        self.addAnnotationPoint = point;
+        self.addAnnotationRect = CGRectZero;
         
         self.draggingType = CPDFAnnotationDraggingNone;
         if (!self.activeAnnotation || self.activeAnnotation.page != page) {
@@ -440,21 +410,21 @@
         
     } else if (CPDFViewAnnotationModeLink == self.annotationMode) {
         CGRect rect = CGRectZero;
-        if (point.x > self.addLinkPoint.x) {
-            rect.origin.x = self.addLinkPoint.x;
-            rect.size.width = point.x-self.addLinkPoint.x;
+        if (point.x > self.addAnnotationPoint.x) {
+            rect.origin.x = self.addAnnotationPoint.x;
+            rect.size.width = point.x-self.addAnnotationPoint.x;
         } else {
             rect.origin.x = point.x;
-            rect.size.width = self.addLinkPoint.x-point.x;
+            rect.size.width = self.addAnnotationPoint.x-point.x;
         }
-        if (point.y > self.addLinkPoint.y) {
-            rect.origin.y = self.addLinkPoint.y;
-            rect.size.height = point.y-self.addLinkPoint.y;
+        if (point.y > self.addAnnotationPoint.y) {
+            rect.origin.y = self.addAnnotationPoint.y;
+            rect.size.height = point.y-self.addAnnotationPoint.y;
         } else {
             rect.origin.y = point.y;
-            rect.size.height = self.addLinkPoint.y-point.y;
+            rect.size.height = self.addAnnotationPoint.y-point.y;
         }
-        self.addLinkRect = rect;
+        self.addAnnotationRect = rect;
         [self setNeedsDisplayForPage:page];
     }
 }
@@ -489,7 +459,7 @@
             }
         }
     } else if (CPDFAnnotationDraggingNone == self.draggingType) {
-        if (self.activeAnnotation && !(CPDFViewAnnotationModeLink == self.annotationMode && !CGRectIsEmpty(self.addLinkRect))) {
+        if (self.activeAnnotation && !(CPDFViewAnnotationModeLink == self.annotationMode && !CGRectIsEmpty(self.addAnnotationRect))) {
             CPDFPage *previousPage = self.activeAnnotation.page;
             [self updateActiveAnnotations:@[]];
             [self setNeedsDisplayForPage:previousPage];
@@ -548,7 +518,7 @@
                     }
                 }
             } else if (CPDFViewAnnotationModeLink == self.annotationMode) {
-                if (CGRectIsEmpty(self.addLinkRect)) {
+                if (CGRectIsEmpty(self.addAnnotationRect)) {
                     CPDFAnnotation *annotation = [page annotationAtPoint:point];
                     if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
                         if(annotation) {
@@ -624,7 +594,7 @@
         CGContextSetLineWidth(context, 1.0);
         CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:255.0/255.f green:255.0/255.f blue:255.0/255.f alpha:0.8].CGColor);
         CGContextSetFillColorWithColor(context, [UIColor colorWithRed:100.0/255.f green:149.0/255.f blue:237.0/255.f alpha:0.4].CGColor);
-        CGContextAddRect(context, self.addLinkRect);
+        CGContextAddRect(context, self.addAnnotationRect);
         CGContextDrawPath(context, kCGPathFillStroke);
     }
 
@@ -1199,13 +1169,13 @@
 
 - (void)addAnnotationLinkAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
     CPDFLinkAnnotation *annotation = [[CPDFLinkAnnotation alloc] initWithDocument:self.document]    ;
-    annotation.bounds = self.addLinkRect;
+    annotation.bounds = self.addAnnotationRect;
     [annotation setModificationDate:[NSDate date]];
     [annotation setUserName:[self annotationUserName]];
     [page addAnnotation:annotation];
     
-    self.addLinkPoint = CGPointZero;
-    self.addLinkRect = CGRectZero;
+    self.addAnnotationPoint = CGPointZero;
+    self.addAnnotationRect = CGRectZero;
     
     if(annotation) {
         [self updateActiveAnnotations:@[annotation]];

+ 405 - 3
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Form.m

@@ -12,31 +12,433 @@
 
 #import "CPDFListView+Form.h"
 
+#import "CPDFListView+Private.h"
+
 @implementation CPDFListView (Form)
 
 - (void)formTouchBeganAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
-    
+    if (self.textSelectionMode) {
+    } else {
+        self.addAnnotationPoint = point;
+        self.addAnnotationRect = CGRectZero;
+        
+        self.draggingType = CPDFAnnotationDraggingNone;
+        if (!self.activeAnnotation || self.activeAnnotation.page != page) {
+            return;
+        }
+        CGRect topLeftRect = CGRectInset(self.topLeftRect, -5, -5);
+        CGRect bottomLeftRect = CGRectInset(self.bottomLeftRect, -5, -5);
+        CGRect topRightRect = CGRectInset(self.topRightRect, -5, -5);
+        CGRect bottomRightRect = CGRectInset(self.bottomRightRect, -5, -5);
+        CGRect startPointRect = CGRectInset(self.startPointRect, -5, -5);
+        CGRect endPointRect = CGRectInset(self.endPointRect, -5, -5);
+        if (CGRectContainsPoint(topLeftRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingTopLeft;
+        } else if (CGRectContainsPoint(bottomLeftRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingBottomLeft;
+        } else if (CGRectContainsPoint(topRightRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingTopRight;
+        } else if (CGRectContainsPoint(bottomRightRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingBottomRight;
+        } else if (CGRectContainsPoint(startPointRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingStart;
+        } else if (CGRectContainsPoint(endPointRect, point)) {
+            self.draggingType = CPDFAnnotationDraggingEnd;
+        } else if ([page annotation:self.activeAnnotation atPoint:point]) {
+            self.draggingType = CPDFAnnotationDraggingCenter;
+        }
+        self.draggingPoint = point;
+    }
 }
 
 - (void)formTouchMovedAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
-    
+    if (self.textSelectionMode) {
+    } else if (CPDFAnnotationDraggingNone != self.draggingType) {
+        if(!self.undoMove) {
+            [[self undoPDFManager] beginUndoGrouping];
+            self.undoMove = YES;
+        }
+        [self moveFormAnnotation:(CPDFWidgetAnnotation *)self.activeAnnotation fromPoint:self.draggingPoint toPoint:point forType:self.draggingType];
+        [self setNeedsDisplayForPage:page];
+        self.draggingPoint = point;
+        
+    } else if (([self isWidgetFormWithMode:self.annotationMode])) {
+        CGRect rect = CGRectZero;
+        if (point.x > self.addAnnotationPoint.x) {
+            rect.origin.x = self.addAnnotationPoint.x;
+            rect.size.width = point.x-self.addAnnotationPoint.x;
+        } else {
+            rect.origin.x = point.x;
+            rect.size.width = self.addAnnotationPoint.x-point.x;
+        }
+        if (point.y > self.addAnnotationPoint.y) {
+            rect.origin.y = self.addAnnotationPoint.y;
+            rect.size.height = point.y-self.addAnnotationPoint.y;
+        } else {
+            rect.origin.y = point.y;
+            rect.size.height = self.addAnnotationPoint.y-point.y;
+        }
+        self.addAnnotationRect = rect;
+        [self setNeedsDisplayForPage:page];
+    }
 }
 
 - (void)formTouchEndedAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
-    
+    if (self.textSelectionMode) {
+        if (self.currentSelection) {
+        } else {
+            CPDFAnnotation *annotation = [page annotationAtPoint:point];
+            if(annotation && [annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+                if (![self.activeAnnotations containsObject:annotation]) {
+                    [self updateActiveAnnotations:@[annotation]];
+                    [self setNeedsDisplayForPage:page];
+                    [self updateFormScrollEnabled];
+                }
+            } else {
+                if(self.activeAnnotation) {
+                    [self updateActiveAnnotations:@[]];
+                    [self setNeedsDisplayForPage:page];
+                    [self updateFormScrollEnabled];
+                } else {
+                    if(CPDFViewAnnotationModeNone == self.annotationMode) {
+                        if ([self.performDelegate respondsToSelector:@selector(PDFListViewPerformTouchEnded:)]) {
+                            [self.performDelegate PDFListViewPerformTouchEnded:self];
+                        }
+                    }
+                }
+            }
+        }
+    } else if (CPDFAnnotationDraggingNone == self.draggingType) {
+        if (self.activeAnnotation && !([self isWidgetFormWithMode:self.annotationMode] && !CGRectIsEmpty(self.addAnnotationRect))) {
+            CPDFPage *previousPage = self.activeAnnotation.page;
+            [self updateActiveAnnotations:@[]];
+            [self setNeedsDisplayForPage:previousPage];
+            [self updateFormScrollEnabled];
+        } else {
+            if (CPDFViewAnnotationModeNone == self.annotationMode) {
+                CPDFAnnotation *annotation = [page annotationAtPoint:point];
+                if ([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+                    if (![self.activeAnnotations containsObject:annotation]) {
+                        [self updateActiveAnnotations:@[annotation]];
+                        [self setNeedsDisplayForPage:page];
+                        [self updateFormScrollEnabled];
+                    }
+                    [self showMenuForWidgetAnnotation:(CPDFWidgetAnnotation *)annotation];
+                } else {
+                    if ([self.performDelegate respondsToSelector:@selector(PDFListViewPerformTouchEnded:)]) {
+                        [self.performDelegate PDFListViewPerformTouchEnded:self];
+                    }
+                }
+            } else  if ([self isWidgetFormWithMode:self.annotationMode]) {
+                if (CGRectIsEmpty(self.addAnnotationRect)) {
+                    CPDFAnnotation *annotation = [page annotationAtPoint:point];
+                    if ([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+                        if(annotation) {
+                            [self updateActiveAnnotations:@[annotation]];
+                            [self setNeedsDisplayForPage:page];
+                        }
+                        [self updateFormScrollEnabled];
+                        
+                        [self showMenuForWidgetAnnotation:(CPDFWidgetAnnotation *)annotation];
+                    }
+                } else {
+                    [self addWidgetAnnotationAtPoint:point forPage:page];
+                }
+            }
+        }
+    } else {
+        if (CPDFAnnotationDraggingCenter != self.draggingType) {
+            if ([self.activeAnnotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+                [self.activeAnnotation updateAppearanceStream];
+                [self setNeedsDisplayForPage:page];
+            }
+        }
+        
+        if(self.undoMove) {
+            [[self undoPDFManager] endUndoGrouping];
+            self.undoMove = NO;
+        }
+        
+        self.draggingType = CPDFAnnotationDraggingNone;
+        if([self.activeAnnotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+            [self showMenuForWidgetAnnotation:(CPDFWidgetAnnotation *)self.activeAnnotation];
+        }
+    }
 }
 
 - (void)formTouchCancelledAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
+    self.draggingType = CPDFAnnotationDraggingNone;
     
+    if(self.undoMove) {
+        [[self undoPDFManager] endUndoGrouping];
+        self.undoMove = NO;
+    }
 }
 
 - (void)formDrawPage:(CPDFPage *)page toContext:(CGContextRef)context {
+    if ([self isWidgetFormWithMode:self.annotationMode]) {
+        CGContextSetLineWidth(context, 1.0);
+        CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:255.0/255.f green:255.0/255.f blue:255.0/255.f alpha:0.8].CGColor);
+        CGContextSetFillColorWithColor(context, [UIColor colorWithRed:100.0/255.f green:149.0/255.f blue:237.0/255.f alpha:0.4].CGColor);
+        CGContextAddRect(context, self.addAnnotationRect);
+        CGContextDrawPath(context, kCGPathFillStroke);
+    }
+    
+    if (self.activeAnnotation.page != page) {
+        return;
+    }
+    CGSize dragDotSize = CGSizeMake(30, 30);
+    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:72.0/255.0 green:183.0/255.0 blue:247.0/255.0 alpha:1.0].CGColor);
     
+    for (CPDFAnnotation *annotation in self.activeAnnotations) {
+        CGRect rect = CGRectInset(annotation.bounds, -dragDotSize.width/2.0, -dragDotSize.height/2.0);
+        CGContextSetLineWidth(context, 1.0);
+        CGFloat lengths[] = {6, 6};
+        CGContextSetLineDash(context, 0, lengths, 2);
+        CGContextStrokeRect(context, rect);
+        CGContextStrokePath(context);
+        
+        if (![annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+            continue;;
+        }
+        
+        CGRect topLeftRect = CGRectMake(CGRectGetMinX(rect)-dragDotSize.width/2.0,
+                                        CGRectGetMaxY(rect)-dragDotSize.height/2.0,
+                                        dragDotSize.width, dragDotSize.height);
+        CGRect bottomLeftRect = CGRectMake(CGRectGetMinX(rect)-dragDotSize.width/2.0,
+                                           CGRectGetMinY(rect)-dragDotSize.height/2.0,
+                                           dragDotSize.width, dragDotSize.height);
+        CGRect topRightRect = CGRectMake(CGRectGetMaxX(rect)-dragDotSize.width/2.0,
+                                         CGRectGetMaxY(rect)-dragDotSize.height/2.0,
+                                         dragDotSize.width, dragDotSize.height);
+        CGRect bottomRightRect = CGRectMake(CGRectGetMaxX(rect)-dragDotSize.width/2.0,
+                                            CGRectGetMinY(rect)-dragDotSize.height/2.0,
+                                            dragDotSize.width, dragDotSize.height);
+        
+        UIImage *image = [UIImage imageNamed:@"CPDFListViewImageNameAnnotationDragDot" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
+        CGImageRef dragDotImage = image.CGImage;
+        
+        CGContextDrawImage(context, topLeftRect, dragDotImage);
+        CGContextDrawImage(context, bottomLeftRect, dragDotImage);
+        CGContextDrawImage(context, topRightRect, dragDotImage);
+        CGContextDrawImage(context, bottomRightRect, dragDotImage);
+        
+        self.topLeftRect = topLeftRect;
+        self.bottomLeftRect = bottomLeftRect;
+        self.topRightRect = topRightRect;
+        self.bottomRightRect = bottomRightRect;
+    }
 }
 
 - (NSArray<UIMenuItem *> *)formMenuItemsAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
     return [super menuItemsAtPoint:point forPage:page];
 }
 
+#pragma mark - Annotation
+
+- (void)moveFormAnnotation:(CPDFWidgetAnnotation *)annotation fromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint forType:(CPDFAnnotationDraggingType)draggingType {
+    if([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+        CGRect bounds = annotation.bounds;
+        CGPoint offsetPoint =  CGPointMake(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y);
+        CGFloat scale = bounds.size.height/bounds.size.width;
+        switch (draggingType) {
+            case CPDFAnnotationDraggingCenter:
+            {
+                bounds.origin.x += offsetPoint.x;
+                bounds.origin.y += offsetPoint.y;
+            }
+                break;
+            case CPDFAnnotationDraggingTopLeft:
+            {
+                CGFloat x = CGRectGetMaxX(bounds);
+                bounds.size.width -= offsetPoint.x;
+                bounds.size.height += offsetPoint.y;
+                
+                if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
+                    bounds.size.height = bounds.size.width*scale;
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0*scale);
+                } else {
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0);
+                }
+                
+                bounds.origin.x = x - bounds.size.width;
+            }
+                break;
+            case CPDFAnnotationDraggingBottomLeft:
+            {
+                CGFloat x = CGRectGetMaxX(bounds);
+                CGFloat y = CGRectGetMaxY(bounds);
+                bounds.size.width -= offsetPoint.x;
+                bounds.size.height -= offsetPoint.y;
+                
+                if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
+                    bounds.size.height = bounds.size.width*scale;
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0*scale);
+                } else {
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0);
+                }
+                
+                bounds.origin.x = x - bounds.size.width;
+                bounds.origin.y = y - bounds.size.height;
+            }
+                break;
+            case CPDFAnnotationDraggingTopRight:
+            {
+                bounds.size.width += offsetPoint.x;
+                bounds.size.height += offsetPoint.y;
+                
+                if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
+                    bounds.size.height = bounds.size.width*scale;
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0*scale);
+                } else {
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0);
+                }
+            }
+                break;
+            case CPDFAnnotationDraggingBottomRight:
+            {
+                CGFloat y = CGRectGetMaxY(bounds);
+                bounds.size.width += offsetPoint.x;
+                bounds.size.height -= offsetPoint.y;
+                
+                if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
+                    [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
+                    bounds.size.height = bounds.size.width*scale;
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0*scale);
+                } else {
+                    bounds.size.width = MAX(bounds.size.width, 5.0);
+                    bounds.size.height = MAX(bounds.size.height, 5.0);
+                }
+                
+                bounds.origin.y = y - bounds.size.height;
+            }
+                break;
+            default:
+                break;
+        }
+        
+        if (CGRectGetMinX(bounds) < 0) {
+            bounds.origin.x = 0;
+        }
+        if (CGRectGetMaxX(bounds) > CGRectGetWidth(annotation.page.bounds)) {
+            bounds.origin.x = CGRectGetWidth(annotation.page.bounds) - CGRectGetWidth(bounds);
+        }
+        if (CGRectGetMinY(bounds) < 0) {
+            bounds.origin.y = 0;
+        }
+        if (CGRectGetMaxY(bounds) > CGRectGetHeight(annotation.page.bounds)) {
+            bounds.origin.y = CGRectGetHeight(annotation.page.bounds) - CGRectGetHeight(bounds);
+        }
+        annotation.bounds = bounds;
+    }
+}
+
+- (void)addWidgetAnnotationAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
+    CPDFWidgetAnnotation *widgetAnnotation = nil;
+    
+    switch (self.annotationMode) {
+        case CPDFViewFormModeText:
+            widgetAnnotation = [[CPDFTextWidgetAnnotation alloc] initWithDocument:self.document];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Text Field_",[self tagString]]];
+            break;
+        case CPDFViewFormModeCheckBox:
+            widgetAnnotation = [[CPDFButtonWidgetAnnotation alloc] initWithDocument:self.document controlType:CPDFWidgetCheckBoxControl];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Check Button_",[self tagString]]];
+            break;
+        case CPDFViewFormModeRadioButton:
+            widgetAnnotation = [[CPDFButtonWidgetAnnotation alloc] initWithDocument:self.document controlType:CPDFWidgetRadioButtonControl];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Radio Button_",[self tagString]]];
+            break;
+        case CPDFViewFormModeCombox:
+            widgetAnnotation = [[CPDFChoiceWidgetAnnotation alloc] initWithDocument:self.document listChoice:NO];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Combox Choice_",[self tagString]]];
+            break;
+        case CPDFViewFormModeList:
+            widgetAnnotation = [[CPDFChoiceWidgetAnnotation alloc] initWithDocument:self.document listChoice:YES];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"List Choice_",[self tagString]]];
+            break;
+        case CPDFViewFormModeButton:
+            widgetAnnotation = [[CPDFButtonWidgetAnnotation alloc] initWithDocument:self.document controlType:CPDFWidgetPushButtonControl];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Push Button_",[self tagString]]];
+            break;
+        case CPDFViewFormModeSign:
+            widgetAnnotation = [[CPDFSignatureWidgetAnnotation alloc] initWithDocument:self.document];
+            [widgetAnnotation setFieldName:[NSString stringWithFormat:@"%@%@",@"Signature_",[self tagString]]];
+            break;
+        default:
+            break;
+    }
+    widgetAnnotation.bounds = self.addAnnotationRect;
+    [widgetAnnotation setModificationDate:[NSDate date]];
+    [widgetAnnotation setUserName:[self annotationUserName]];
+    [page addAnnotation:widgetAnnotation];
+    
+    self.addAnnotationPoint = CGPointZero;
+    self.addAnnotationRect = CGRectZero;
+    
+    if(widgetAnnotation) {
+        [self updateActiveAnnotations:@[widgetAnnotation]];
+        [self setNeedsDisplayForPage:page];
+    }
+    
+    [self updateFormScrollEnabled];
+    if([widgetAnnotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
+        if ([self.performDelegate respondsToSelector:@selector(PDFListViewEditNote:forAnnotation:)]) {
+            [self.performDelegate PDFListViewEditProperties:self forAnnotation:widgetAnnotation];
+        }
+    }
+}
+
+#pragma mark - Private method
+
+- (void)updateFormScrollEnabled {
+    if (self.activeAnnotation) {
+        self.scrollEnabled = NO;
+    } else {
+        if ([self isWidgetFormWithMode:self.annotationMode]) {
+            self.scrollEnabled = NO;
+        } else {
+            self.scrollEnabled = YES;
+        }
+    }
+}
+
+- (BOOL)isWidgetFormWithMode:(CPDFViewAnnotationMode)annotationMode {
+    if (CPDFViewFormModeText == annotationMode ||
+        CPDFViewFormModeCheckBox == annotationMode ||
+        CPDFViewFormModeRadioButton == annotationMode ||
+        CPDFViewFormModeCombox == annotationMode ||
+        CPDFViewFormModeList == annotationMode ||
+        CPDFViewFormModeButton == annotationMode ||
+        CPDFViewFormModeSign == annotationMode) {
+        return YES;
+    }
+    
+    return NO;
+}
+
+- (NSString *)tagString {
+    NSDateFormatter *formatter = [[NSDateFormatter alloc ] init];
+    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
+    NSString *dateString = [formatter stringFromDate:[NSDate date]];
+    return [NSString stringWithFormat:@"%@ %d ", dateString,rand()%10000];
+}
+
+- (void)showMenuForWidgetAnnotation:(CPDFWidgetAnnotation *)annotation {
+}
 
 @end

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

@@ -39,9 +39,9 @@ typedef NS_ENUM(NSInteger, CPDFAnnotationDraggingType) {
 
 @property (nonatomic, assign) CGRect endPointRect;
 
-@property (nonatomic, assign) CGPoint addLinkPoint;
+@property (nonatomic, assign) CGPoint addAnnotationPoint;
 
-@property (nonatomic, assign) CGRect addLinkRect;
+@property (nonatomic, assign) CGRect addAnnotationRect;
 
 @property (nonatomic, assign) CGPoint draggingPoint;
 

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

@@ -41,8 +41,7 @@ typedef NS_ENUM(NSInteger, CPDFViewAnnotationMode) {
     CPDFViewAnnotationModeLink,
     CPDFViewAnnotationModeSound,
     
-    CPDFViewFormModeNone = 1000,
-    CPDFViewFormModeText,
+    CPDFViewFormModeText = 1000,
     CPDFViewFormModeCheckBox,
     CPDFViewFormModeRadioButton,
     CPDFViewFormModeCombox,

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

@@ -12,6 +12,8 @@
 
 #import "CPDFListView.h"
 #import "CPDFListView+Annotation.h"
+#import "CPDFListView+Form.h"
+
 #import "CPDFListView+UndoManager.h"
 #import "CPDFListView+Private.h"
 
@@ -82,10 +84,19 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     } else {
         self.textSelectionMode = NO;
     }
-    
+        
     if (CPDFViewAnnotationModeLink == annotationMode) {
         self.scrollEnabled = NO;
         [self endDrawing];
+    } else if (CPDFViewFormModeText == annotationMode ||
+               CPDFViewFormModeCheckBox == annotationMode ||
+               CPDFViewFormModeRadioButton == annotationMode ||
+               CPDFViewFormModeCombox == annotationMode ||
+               CPDFViewFormModeList == annotationMode ||
+               CPDFViewFormModeButton == annotationMode ||
+               CPDFViewFormModeSign == annotationMode) {
+        self.scrollEnabled = NO;
+        [self endDrawing];
     } else if (CPDFViewAnnotationModeInk == annotationMode || CPDFViewAnnotationModePencilDrawing == annotationMode) {
         self.scrollEnabled = NO;
         [self beginDrawing];
@@ -120,16 +131,20 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
 -(void)setToolModel:(CToolModel)toolModel {
     if(CToolModelAnnotation == _toolModel && CToolModelAnnotation != toolModel)
         [self stopRecord];
+    if(_toolModel != toolModel) {
+        _toolModel = toolModel;
+        [self updateActiveAnnotations:@[]];
+        self.annotationMode = CPDFViewAnnotationModeNone;
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewToolModeChangeNotification object:self];
+            
+            if([self.performDelegate respondsToSelector:@selector(PDFListViewChangedToolMode:forToolMode:)]) {
+                [self.performDelegate PDFListViewChangedToolMode:self forToolMode:self.toolModel];
+            }
+        });
+
+    }
     
-    _toolModel = toolModel;
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewToolModeChangeNotification object:self];
-        
-        if([self.performDelegate respondsToSelector:@selector(PDFListViewChangedToolMode:forToolMode:)]) {
-            [self.performDelegate PDFListViewChangedToolMode:self forToolMode:self.toolModel];
-        }
-    });
 }
 
 - (NSMutableArray *)activeAnnotations {
@@ -158,7 +173,7 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     if (CToolModelAnnotation == self.toolModel) {
         [self annotationTouchBeganAtPoint:point forPage:page];
     } else if (CToolModelForm == self.toolModel) {
-        
+        [self formTouchBeganAtPoint:point forPage:page];
     } else if (CToolModelEdit == self.toolModel) {
         
     } else {
@@ -169,7 +184,7 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     if (CToolModelAnnotation == self.toolModel) {
         [self annotationTouchMovedAtPoint:point forPage:page];
     } else if (CToolModelForm == self.toolModel) {
-        
+        [self formTouchMovedAtPoint:point forPage:page];
     } else if (CToolModelEdit == self.toolModel) {
         
     } else {
@@ -181,7 +196,7 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     if (CToolModelAnnotation == self.toolModel) {
         [self annotationTouchEndedAtPoint:point forPage:page];
     } else if (CToolModelForm == self.toolModel) {
-        
+        [self formTouchEndedAtPoint:point forPage:page];
     } else if (CToolModelEdit == self.toolModel) {
         
     } else {
@@ -387,7 +402,7 @@ NSNotificationName const CPDFListViewAnnotationsOperationChangeNotification = @"
     if (CToolModelAnnotation == self.toolModel) {
         [self annotationDrawPage:page toContext:context];
     } else if (CToolModelForm == self.toolModel) {
-        
+        [self formDrawPage:page toContext:context];
     } else if (CToolModelEdit == self.toolModel) {
         
     } else {

+ 10 - 16
compdfkit-tools/compdfkit-tools/Form/CPDFFormBar.m

@@ -108,20 +108,14 @@
                                                               @"CPDFFormButton",
                                                               @"CPDFFormSign"]];
     
-    NSMutableArray *types = [NSMutableArray arrayWithArray:@[@(CPDFFormModeText),
-                                                             @(CPDFFormModeCheckBox),
-                                                             @(CPDFFormModeRadioButton),
-                                                             @(CPDFFormModeComboBox),
-                                                             @(CPDFFormModeList),
-                                                             @(CPDFFormModeButton),
-                                                             @(CPDFFormModeSign)]];
-
-    if (@available(iOS 13.0, *)) {
-    } else {
-        [images removeObject:@"CPDFAnnotationBarImagePencilDraw"];
-        [types removeObject:@(CPDFViewAnnotationModePencilDrawing)];
-    }
-    
+
+    NSMutableArray *types = [NSMutableArray arrayWithArray:@[@(CPDFViewFormModeText),
+                                                             @(CPDFViewFormModeCheckBox),
+                                                             @(CPDFViewFormModeRadioButton),
+                                                             @(CPDFViewFormModeCombox),
+                                                             @(CPDFViewFormModeList),
+                                                             @(CPDFViewFormModeButton),
+                                                             @(CPDFViewFormModeSign)]];
     NSMutableArray *annotationBtns = [NSMutableArray array];
     for (int i = 0; i < types.count; i++) {
         CPDFFormMode formMode = (CPDFFormMode)[types[i] integerValue];
@@ -284,7 +278,7 @@
 
     } else {
         self.propertiesBtn.enabled = NO;
-        self.pdfListView.annotationMode = CPDFViewFormModeNone;
+        self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
         self.selectedIndex = -1;
         button.backgroundColor = [UIColor clearColor];
         isSelect = NO;
@@ -312,7 +306,7 @@
 #pragma mark - Public Methods
 
 - (void)reloadData {
-    if(CPDFViewFormModeNone == self.pdfListView.annotationMode) {
+    if(CPDFViewAnnotationModeNone == self.pdfListView.annotationMode) {
         if (self.selectedIndex >0 &&
             self.selectedIndex <= self.formBtns.count) {
             for (NSInteger i = 0; i< self.formBtns.count; i++) {