|
@@ -183,6 +183,18 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
|
|
|
[self doDrawLinkNoteWithEvent:theEvent];
|
|
|
}
|
|
|
}
|
|
|
+ } else if (self.toolMode == CFormToolMode) {
|
|
|
+ NSPoint p = [theEvent locationInWindow];
|
|
|
+ NSPoint currentPoint = [self convertPoint:p fromView:nil];
|
|
|
+ for (CPDFAnnotation *ann in self.currentPage.annotations) {
|
|
|
+ if (CGRectContainsPoint(ann.bounds, [self convertPoint:currentPoint toPage: self.currentPage])) {
|
|
|
+ if (!ann.shouldDisplay) {
|
|
|
+ [self updateActiveAnnotations:@[ann]];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ [self doFormWithEvent:theEvent];
|
|
|
} else {
|
|
|
[self doDragAddAnnotationWithEvent:theEvent];
|
|
|
}
|
|
@@ -2858,6 +2870,379 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
|
|
|
self.multiplAnnotationObject.drawRect = newBounds;
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Form
|
|
|
+- (void)doFormWithEvent:(NSEvent *)theEvent
|
|
|
+{
|
|
|
+ if (self.annotationType == CAnnotationTypeRadioButton || self.annotationType == CAnnotationTypeCheckBox) {
|
|
|
+ [self updateActiveAnnotations:@[]];
|
|
|
+
|
|
|
+ NSPoint pagePoint = NSZeroPoint;
|
|
|
+ CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:theEvent nearest:YES];
|
|
|
+ NSUInteger eventMask = NSLeftMouseUpMask;
|
|
|
+ theEvent = [[self window] nextEventMatchingMask:eventMask];
|
|
|
+ while (YES) {
|
|
|
+ if ([theEvent type] == NSLeftMouseUp) {
|
|
|
+ CGRect bounds =CGRectMake(pagePoint.x - 10, pagePoint.y - 10, 20, 20);
|
|
|
+ [self addFormAnnotationWithType:self.annotationType selection:nil page:page bounds:bounds];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (self.annotationType == CAnnotationTypeTextField || self.annotationType == CAnnotationTypeListMenu || self.annotationType == CAnnotationTypeComboBox || self.annotationType == CAnnotationTypeActionButton){
|
|
|
+ CPDFAnnotation *annotation = self.activeAnnotation;
|
|
|
+ [self updateActiveAnnotations:@[]];
|
|
|
+ // Old (current) annotation location and click point relative to it
|
|
|
+ NSRect originalBounds = [self.activeAnnotation bounds];
|
|
|
+ NSPoint pagePoint = NSZeroPoint;
|
|
|
+ CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:theEvent nearest:YES];
|
|
|
+ BOOL shouldAddAnnotation = self.activeAnnotation == nil;
|
|
|
+
|
|
|
+ // Hit-test for resize box.
|
|
|
+ CRectEdges resizeHandle = [self.activeAnnotation resizeHandleForPoint:pagePoint scaleFactor:[self scaleFactor]];
|
|
|
+ if (shouldAddAnnotation) {
|
|
|
+ originalBounds = SKRectFromCenterAndSquareSize(NSMakePoint(round(pagePoint.x), round(pagePoint.y)), 0.0);
|
|
|
+ resizeHandle = CMaxXEdgeMask | CMinYEdgeMask;
|
|
|
+ }
|
|
|
+ BOOL draggedAnnotation = NO;
|
|
|
+ NSEvent *lastMouseEvent = theEvent;
|
|
|
+ NSPoint offset = NSMakePoint(pagePoint.x - originalBounds.origin.x, pagePoint.y - originalBounds.origin.y);
|
|
|
+ NSUInteger eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
|
|
+ [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
|
|
|
+ while (YES) {
|
|
|
+ theEvent = [[self window] nextEventMatchingMask:eventMask];
|
|
|
+ if ([theEvent type] == NSLeftMouseUp) {
|
|
|
+ if (!draggedAnnotation) {
|
|
|
+ if (annotation) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (annotation) {
|
|
|
+// [self showEditableFormAnnotationEditor:annotation];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ NSSize defaultSize = CGSizeZero;
|
|
|
+ if (self.annotationType == CAnnotationTypeTextField) {
|
|
|
+ defaultSize = CGSizeMake(100, 20);
|
|
|
+ } else if (self.annotationType == CAnnotationTypeComboBox){
|
|
|
+ defaultSize = CGSizeMake(130, 40);
|
|
|
+ } else if (self.annotationType == CAnnotationTypeListMenu){
|
|
|
+ defaultSize = CGSizeMake(130, 40);
|
|
|
+ } else if (self.annotationType == CAnnotationTypeActionButton){
|
|
|
+ defaultSize = CGSizeMake(130, 40);
|
|
|
+ }
|
|
|
+ defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultSize.width, defaultSize.height) : NSMakeSize(defaultSize.height, defaultSize.width);
|
|
|
+
|
|
|
+ annotation = [self addFormAnnotationWithType:self.annotationType selection:nil page:page bounds:SKRectFromCenterAndSize(NSMakePoint(round(pagePoint.x), round(pagePoint.y)), defaultSize)];
|
|
|
+ break;
|
|
|
+ } else if ([theEvent type] == NSLeftMouseDragged){
|
|
|
+ if (self.activeAnnotation == nil) {
|
|
|
+ annotation = [self addFormAnnotationWithType:self.annotationType selection:nil page:page bounds:SKRectFromCenterAndSquareSize(originalBounds.origin, 0.0)];
|
|
|
+ }
|
|
|
+ lastMouseEvent = theEvent;
|
|
|
+ draggedAnnotation = YES;
|
|
|
+ } else if (self.activeAnnotation == nil){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (resizeHandle == 0) {
|
|
|
+ [self doMoveAnnotation:self.activeAnnotation withEvent:lastMouseEvent offset:offset];
|
|
|
+ } else {
|
|
|
+ [self doResizeAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalBounds:originalBounds resizeHandle:&resizeHandle];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (resizeHandle == 0)
|
|
|
+ [NSEvent stopPeriodicEvents];
|
|
|
+
|
|
|
+ if (self.activeAnnotation) {
|
|
|
+ if (draggedAnnotation)
|
|
|
+ [self.activeAnnotation autoUpdateString];
|
|
|
+// if (shouldAddAnnotation && self.toolMode == CNoteToolMode && (annotationMode == SKAnchoredNote || annotationMode == SKFreeTextNote))
|
|
|
+// [self editActiveAnnotation:self];
|
|
|
+
|
|
|
+ [self setNeedsDisplayAnnotation:self.activeAnnotation];
|
|
|
+ }
|
|
|
+
|
|
|
+ // ??? PDFView's delayed layout seems to reset the cursor to an arrow
|
|
|
+ [self performSelector:@selector(setCursorForMouse:) withObject:theEvent afterDelay:0];
|
|
|
+ }
|
|
|
+ } else if (CAnnotationTypeSignature == self.annotationType) {
|
|
|
+ [self creatFromSignatureWithEvent:theEvent];
|
|
|
+ }
|
|
|
+// else if (KMFormTypeClear == self.annotationType) {
|
|
|
+//
|
|
|
+// }
|
|
|
+ else {
|
|
|
+ [self updateActiveAnnotations:@[]];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)creatFromSignatureWithEvent:(NSEvent *)theEvent
|
|
|
+{
|
|
|
+ CPDFAnnotation *annotation = self.activeAnnotation;
|
|
|
+ [self updateActiveAnnotations:@[]];
|
|
|
+ NSRect originalBounds = [self.activeAnnotation bounds];
|
|
|
+ NSPoint pagePoint = NSZeroPoint;
|
|
|
+ CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:theEvent nearest:YES];
|
|
|
+ BOOL shouldAddAnnotation = self.activeAnnotation == nil;
|
|
|
+
|
|
|
+ CRectEdges resizeHandle = [self.activeAnnotation resizeHandleForPoint:pagePoint scaleFactor:[self scaleFactor]];
|
|
|
+ if (shouldAddAnnotation) {
|
|
|
+ originalBounds = SKRectFromCenterAndSquareSize(NSMakePoint(round(pagePoint.x), round(pagePoint.y)), 0.0);
|
|
|
+ resizeHandle = CMaxXEdgeMask | CMinYEdgeMask;
|
|
|
+ }
|
|
|
+ BOOL draggedAnnotation = NO;
|
|
|
+ NSEvent *lastMouseEvent = theEvent;
|
|
|
+
|
|
|
+ NSPoint offset = NSMakePoint(pagePoint.x - originalBounds.origin.x, pagePoint.y - originalBounds.origin.y);
|
|
|
+ NSUInteger eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
|
|
+ [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
|
|
|
+ while (YES) {
|
|
|
+ theEvent = [[self window] nextEventMatchingMask:eventMask];
|
|
|
+ if ([theEvent type] == NSLeftMouseUp) {
|
|
|
+ if(draggedAnnotation){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ NSSize defaultSize = CGSizeMake(150, 20);
|
|
|
+ defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultSize.width, defaultSize.height) : NSMakeSize(defaultSize.height, defaultSize.width);
|
|
|
+
|
|
|
+ annotation = [self addFormAnnotationWithType:self.annotationType selection:nil page:page bounds:SKRectFromCenterAndSize(NSMakePoint(round(pagePoint.x), round(pagePoint.y)), defaultSize)];
|
|
|
+ break;
|
|
|
+ } else if ([theEvent type] == NSLeftMouseDragged){
|
|
|
+ if (self.activeAnnotation == nil) {
|
|
|
+ annotation = [self addFormAnnotationWithType:self.annotationType selection:nil page:page bounds:SKRectFromCenterAndSquareSize(originalBounds.origin, 0.0)];
|
|
|
+ }
|
|
|
+ lastMouseEvent = theEvent;
|
|
|
+ draggedAnnotation = YES;
|
|
|
+ } else if (self.activeAnnotation == nil){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (resizeHandle == 0) {
|
|
|
+ [self doMoveAnnotation:self.activeAnnotation withEvent:lastMouseEvent offset:offset];
|
|
|
+ } else {
|
|
|
+ [self doResizeAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalBounds:originalBounds resizeHandle:&resizeHandle];
|
|
|
+ }
|
|
|
+ if (resizeHandle == 0)
|
|
|
+ [NSEvent stopPeriodicEvents];
|
|
|
+
|
|
|
+ if (self.activeAnnotation) {
|
|
|
+ if (draggedAnnotation)
|
|
|
+ [self.activeAnnotation autoUpdateString];
|
|
|
+
|
|
|
+// if (shouldAddAnnotation && toolMode == SKNoteToolMode && (annotationMode == SKAnchoredNote || annotationMode == SKFreeTextNote))
|
|
|
+// [self editActiveAnnotation:self];
|
|
|
+
|
|
|
+ [self setNeedsDisplayAnnotation:self.activeAnnotation];
|
|
|
+ }
|
|
|
+
|
|
|
+ // ??? PDFView's delayed layout seems to reset the cursor to an arrow
|
|
|
+ [self performSelector:@selector(setCursorForMouse:) withObject:theEvent afterDelay:0];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (CPDFAnnotation *)addFormAnnotationWithType:(CAnnotationType)type selection:(CPDFSelection *)selection page:(CPDFPage *)page bounds:(NSRect)bounds
|
|
|
+{
|
|
|
+ CPDFAnnotation *newAnnotation = nil;
|
|
|
+ BOOL isButtonAddText = NO;
|
|
|
+ NSFont *addFreeTextFont = nil;
|
|
|
+ NSColor *addFreeTextFontColor = nil;
|
|
|
+
|
|
|
+ BOOL isInitial = NSEqualSizes(bounds.size, NSZeroSize) && selection == nil;
|
|
|
+ if (isInitial) {
|
|
|
+ bounds = SKRectFromCenterAndSize(bounds.origin,[self fetchFormMinSizeValueViaFormType:type]);
|
|
|
+ }
|
|
|
+ NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case CAnnotationTypeRadioButton:
|
|
|
+ {
|
|
|
+ newAnnotation = [[KMPDFAnnotationButtonWidgetSub alloc] initWithDocument:self.document controlType:CPDFWidgetRadioButtonControl];
|
|
|
+ [newAnnotation setBounds:bounds];
|
|
|
+ [self setAnnotationType:CAnnotationTypeRadioButton];
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationRadioButtonWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:[NSColor whiteColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ isButtonAddText = [sud boolForKey:@"SKAnnotationRadioButtonWidgetAddTextKey"];
|
|
|
+ if (isButtonAddText) {
|
|
|
+ addFreeTextFontColor = [sud colorForKey:@"SKAnnotationRadioButtonWidgetFontColorKey"];
|
|
|
+ addFreeTextFont = [NSFont fontWithName:[sud stringForKey:@"SKAnnotationRadioButtonWidgetFontNameKey"] size:[sud floatForKey:@"SKAnnotationRadioButtonWidgetFontSizeKey"]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CAnnotationTypeCheckBox:
|
|
|
+ {
|
|
|
+ newAnnotation = [[KMPDFAnnotationButtonWidgetSub alloc] initWithDocument:self.document controlType:CPDFWidgetCheckBoxControl];
|
|
|
+ [newAnnotation setBounds:bounds];
|
|
|
+ [self setAnnotationType:CAnnotationTypeCheckBox];
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationCheckBoxWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:[NSColor whiteColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ isButtonAddText = [sud boolForKey:@"SKAnnotationCheckBoxWidgetAddTextKey"];
|
|
|
+ if (isButtonAddText) {
|
|
|
+ addFreeTextFontColor = [sud colorForKey:@"SKAnnotationCheckBoxWidgetFontColorKey"];
|
|
|
+ addFreeTextFont = [NSFont fontWithName:[sud stringForKey:@"SKAnnotationCheckBoxWidgetFontNameKey"] size:[sud floatForKey:@"SKAnnotationCheckBoxWidgetFontSizeKey"]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CAnnotationTypeComboBox:
|
|
|
+ {
|
|
|
+ newAnnotation = [[KMPDFAnnotationChoiceWidgetSub alloc] initWithDocument:self.document listChoice:NO];
|
|
|
+ [self setAnnotationType:CAnnotationTypeComboBox];
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationChoiceWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:[NSColor clearColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSColor* fontColor = [sud colorForKey:@"SKAnnotationChoiceWidgetFontColorKey"];
|
|
|
+ if (fontColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFontColor:fontColor];
|
|
|
+ }
|
|
|
+ NSFont *font = [sud fontForNameKey:@"SKAnnotationChoiceWidgetFontNameKey" sizeKey:@"SKAnnotationChoiceWidgetFontSizeKey"];
|
|
|
+ if (font) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFont:font];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case CAnnotationTypeListMenu:
|
|
|
+ {
|
|
|
+ newAnnotation = [[KMPDFAnnotationChoiceWidgetSub alloc] initWithDocument:self.document listChoice:YES];
|
|
|
+ [self setAnnotationType:CAnnotationTypeListMenu];
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationChoiceListWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:[NSColor clearColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSColor* fontColor = [sud colorForKey:@"SKAnnotationChoiceListWidgetFontColorKey"];
|
|
|
+ if (fontColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFontColor:fontColor];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSFont *font = [sud fontForNameKey:@"SKAnnotationChoiceListWidgetFontNameKey" sizeKey:@"SKAnnotationChoiceListWidgetFontSizeKey"];
|
|
|
+ if (font) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFont:font];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case CAnnotationTypeActionButton:
|
|
|
+ {
|
|
|
+ newAnnotation = [[KMPDFAnnotationButtonWidgetSub alloc] initWithDocument:self.document controlType:CPDFWidgetPushButtonControl];
|
|
|
+ [newAnnotation setBounds:bounds];
|
|
|
+ [self setAnnotationType:CAnnotationTypeActionButton];
|
|
|
+
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationActionButtonWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setBackgroundColor:[NSColor whiteColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSColor* fontColor = [sud colorForKey:@"SKAnnotationActionButtonWidgetFontColorKey"];
|
|
|
+ if (fontColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFontColor:fontColor];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSFont *font = [sud fontForNameKey:@"SKAnnotationActionButtonWidgetFontNameKey" sizeKey:@"SKAnnotationActionButtonWidgetFontSizeKey"];
|
|
|
+ if (font) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFont:font];
|
|
|
+ }
|
|
|
+ [(CPDFButtonWidgetAnnotation *)newAnnotation setCaption:NSLocalizedString(@"Submit", nil)];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CAnnotationTypeTextField:{
|
|
|
+ KMPDFAnnotationTextWidgetSub *textWidget = [[KMPDFAnnotationTextWidgetSub alloc] initWithDocument:self.document];
|
|
|
+ textWidget.stringValue = NSLocalizedString(@"", nil);
|
|
|
+ CPDFBorder *border = [[CPDFBorder alloc] initWithStyle:CPDFBorderStyleSolid lineWidth:0 dashPattern:nil];
|
|
|
+ textWidget.border = border;
|
|
|
+ NSColor* backgroundColor = [sud colorForKey:@"SKAnnotationTextWidgetBackgroundColorKey"];
|
|
|
+ if (backgroundColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)textWidget setBackgroundColor:backgroundColor];
|
|
|
+ } else {
|
|
|
+ [(CPDFWidgetAnnotation *)textWidget setBackgroundColor:[NSColor clearColor]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSColor* fontColor = [sud colorForKey:@"SKAnnotationTextWidgetFontColorKey"];
|
|
|
+ if (fontColor) {
|
|
|
+ [(CPDFWidgetAnnotation *)textWidget setFontColor:fontColor];
|
|
|
+ }
|
|
|
+ textWidget.alignment = [sud integerForKey:@"SKAnnotationTextWidgetAlignmenKey"];
|
|
|
+ NSFont *font = [sud fontForNameKey:@"SKAnnotationTextWidgetFontNameKey" sizeKey:@"SKAnnotationTextWidgetFontSizeKey"];
|
|
|
+ if (font) {
|
|
|
+ [(CPDFWidgetAnnotation *)textWidget setFont:font];
|
|
|
+ }
|
|
|
+ textWidget.isMultiline = [sud boolForKey:@"SKAnnotationTextMultilineKey"];
|
|
|
+ newAnnotation = textWidget;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CAnnotationTypeSignature:{
|
|
|
+ if (@available(macOS 10.13, *)) {
|
|
|
+ KMAnnotationFromSignature *signature = [[KMAnnotationFromSignature alloc] initWithDocument:self.document];
|
|
|
+ signature.backgroundColor = [NSColor clearColor];
|
|
|
+ signature.fieldName = @"signature";
|
|
|
+ newAnnotation = signature;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (newAnnotation) {
|
|
|
+ [newAnnotation registerUserName];
|
|
|
+ if (type == CAnnotationTypeRadioButton) {
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFieldName:@"Group1"];
|
|
|
+ [(CPDFButtonWidgetAnnotation *)newAnnotation setOnStateValue:[NSString stringWithFormat:@"Radio Button_%@",[self fetchFieldName]]];
|
|
|
+ } else {
|
|
|
+ NSString *annotationType = @"";
|
|
|
+ if (type == CAnnotationTypeCheckBox) {
|
|
|
+ annotationType = @"Check Box";
|
|
|
+ } else if (type == CAnnotationTypeTextField) {
|
|
|
+ annotationType = @"Text Field";
|
|
|
+ } else if (type == CAnnotationTypeComboBox) {
|
|
|
+ annotationType = @"Combo Box";
|
|
|
+ } else if (type == CAnnotationTypeListMenu) {
|
|
|
+ annotationType = @"List Box";
|
|
|
+ } else if (type == CAnnotationTypeActionButton) {
|
|
|
+ annotationType = @"Button";
|
|
|
+ } else if (type == CAnnotationTypeSignature) {
|
|
|
+ annotationType = @"Signature";
|
|
|
+ }
|
|
|
+ [(CPDFWidgetAnnotation *)newAnnotation setFieldName:[NSString stringWithFormat:@"%@_%@", annotationType,[self fetchFieldName]]];
|
|
|
+ }
|
|
|
+ [self addAnnotation:newAnnotation toPage:page];
|
|
|
+ [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")];
|
|
|
+
|
|
|
+ [self updateActiveAnnotations:@[newAnnotation]];
|
|
|
+ self.lastAddAnnotationPoint = newAnnotation.bounds.origin;
|
|
|
+
|
|
|
+ if (isButtonAddText) {
|
|
|
+ NSString *fieldString = [(CPDFWidgetAnnotation *)newAnnotation fieldName];
|
|
|
+ if ([(CPDFButtonWidgetAnnotation *)newAnnotation controlType] == CPDFWidgetRadioButtonControl) {
|
|
|
+ if (@available(macOS 10.13, *)) {
|
|
|
+ fieldString = newAnnotation.buttonWidgetStateString;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ NSString *annotationField = [NSString stringWithFormat:@"%@_AddText", fieldString];
|
|
|
+// CPDFFreeTextAnnotation *freeText = [self addWidgetRelatedAnnotationFreeText:annotationField];
|
|
|
+// [freeText setFontColor:addFreeTextFontColor];
|
|
|
+// [freeText setFont:addFreeTextFont];
|
|
|
+ }
|
|
|
+ return newAnnotation;
|
|
|
+ } else {
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Operation
|
|
|
|
|
|
-(CGRect)adjustFreetText:(CPDFFreeTextAnnotation *)freeTextAn rect:(CGRect)rect {
|