Browse Source

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

chenyu 1 year ago
parent
commit
a112b9077d

+ 8 - 3
Annotation-Ctrl-Demo/Annotation-Ctrl-Demo/CPDFViewController.m

@@ -422,11 +422,11 @@
 }
 
 - (void)PDFListViewPerformAddStamp:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
-    
+    [self.annotationBar addStampAnnotationWithPage:page point:point];
 }
 
 - (void)PDFListViewPerformAddImage:(CPDFListView *)pdfView atPoint:(CGPoint)point forPage:(CPDFPage *)page {
-    
+    [self.annotationBar addImageAnnotationWithPage:page point:point];
 }
 
 - (BOOL)PDFListViewerTouchEndedIsAudioRecordMedia:(CPDFListView *)pdfListView {
@@ -629,7 +629,12 @@
             [self.pdfListView updateActiveAnnotations:activeAnnotations];
         }
     } else {
-        noteOpenVC.annotation.contents = content?:@"";
+        if([noteOpenVC.annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
+            CPDFMarkupAnnotation *markupAnnotation = (CPDFMarkupAnnotation *)noteOpenVC.annotation;
+            [markupAnnotation setMarkupText:content?:@""];
+        } else {
+            noteOpenVC.annotation.contents = content?:@"";
+        }
     }
 }
 

+ 14 - 3
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFFreeText/CPDFFreeTextViewController.m

@@ -300,7 +300,7 @@
         self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     }
 
-    self.sampleView.isBold = self.isBold;
+    self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
     [self.sampleView setNeedsDisplay];
     self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
     if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
@@ -316,9 +316,9 @@
         self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     }
     
-    self.sampleView.isItalic = self.isItalic;
-    [self.sampleView setNeedsDisplay];
     self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
+    self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
+    [self.sampleView setNeedsDisplay];
     
     if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
         [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
@@ -369,6 +369,17 @@
     }
 }
 
+#pragma mark - CPDFOpacitySliderViewDelegate
+
+- (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
+    self.sampleView.opcity = opacity;
+    self.annotStyle.opacity = opacity;
+    if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
+        [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
+    }
+    [self.sampleView setNeedsDisplay];
+}
+
 #pragma mark - CPDFThicknessSliderViewDelegate
 
 - (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {

+ 63 - 28
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureEditViewController.m

@@ -18,7 +18,7 @@
 
 #import <compdfkit_tools/CPDFColorUtils.h>
 
-@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CSignatureDrawViewDelegate>
+@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate,UIGestureRecognizerDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CSignatureDrawViewDelegate>
 
 @property (nonatomic, strong) CPDFColorSelectView *colorSelectView;
 
@@ -50,6 +50,10 @@
 
 @property (nonatomic, strong) UIButton *clearButton;
 
+@property (nonatomic, strong) UILabel *emptyLabel;
+
+@property (nonatomic, strong) UIView *headerView;
+
 @end
 
 @implementation CPDFSignatureEditViewController
@@ -58,15 +62,27 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    // Do any additional setup after loading the view.
-    self.title = NSLocalizedString(@"Add Signature", nil);
+    // Do any additional setup after loading the view
+    
+    self.headerView = [[UIView alloc] init];
+    self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
+    self.headerView.layer.borderWidth = 1.0;
+    self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+    [self.view addSubview:self.headerView];
     
     NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Draw", nil), NSLocalizedString(@"Text", nil), NSLocalizedString(@"Image", nil),nil];
     _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
     _segmentedControl.selectedSegmentIndex = 0;
     _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_singature:) forControlEvents:UIControlEventValueChanged];
-    self.navigationItem.titleView = self.segmentedControl;
+    [self.view addSubview:self.segmentedControl];
+    
+    self.emptyLabel = [[UILabel alloc] init];
+    self.emptyLabel.font = [UIFont systemFontOfSize:27];
+    self.emptyLabel.textColor = [UIColor grayColor];
+    self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
+    self.emptyLabel.textAlignment = NSTextAlignmentCenter;
+    [self.view addSubview:self.emptyLabel];
     
     self.signatureDrawTextView = [[CSignatureDrawView alloc] init];
     self.signatureDrawTextView.delegate = self;
@@ -107,17 +123,16 @@
     
     self.cacelButon = [[UIButton alloc] init];
     [self.cacelButon setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
+    self.cacelButon.titleLabel.adjustsFontSizeToFitWidth = YES;
     [self.cacelButon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     [self.cacelButon addTarget:self action:@selector(buttonItemClicked_Cancel:) forControlEvents:UIControlEventTouchUpInside];
-    UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithCustomView:self.cacelButon];
-    self.navigationItem.leftBarButtonItem = cancelItem;
+    [self.headerView addSubview:self.cacelButon];
     
     self.saveButton = [[UIButton alloc] init];
     [self.saveButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
     [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [self.saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
-    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithCustomView:self.saveButton];
-    self.navigationItem.rightBarButtonItem = doneItem;
+    [self.headerView addSubview:self.saveButton];
     
     self.bottomBorder = [CALayer layer];
     self.bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
@@ -153,30 +168,26 @@
     self.selecIndex = CSignatureTopBarDefault;
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     [self createGestureRecognizer];
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
 }
 
 - (void)viewWillLayoutSubviews {
     [super viewWillLayoutSubviews];
+    self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 150);
     self.colorPicker.frame = CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height/2);
-    self.segmentedControl.frame = CGRectMake(0, 40, 280, 30);
+    self.segmentedControl.frame = CGRectMake((self.view.frame.size.width - 220)/2, 10, 220, 30);
+    self.emptyLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, (self.view.frame.size.height - 50)/2, 200, 50);
    
     if (@available(iOS 11.0, *)) {
-        if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
-            self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
-            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top+90, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
-            self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
-            self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 150, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
-            
-        } else {
-            self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top-15, 380, 60);
-            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left+380, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right-380, 60);
-            self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
-            self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 90, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-90);
-        }
+        self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
+        self.cacelButon.frame = CGRectMake( self.view.safeAreaInsets.left+20, 5, 50, 40);
+        self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, 50, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
+        self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, 140, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
+        self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
+        self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
+        self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, 210, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
         
-        self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
+        self.signatureDrawImageView.frame = CGRectMake(self.view.safeAreaInsets.left, 50, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
         self.createButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
         self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
     } else {
@@ -186,6 +197,8 @@
         self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
         self.createButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
         self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
+        self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 40);
+        self.cacelButon.frame = CGRectMake(20, 5, 50, 40);
     }
     
     self.textField.frame = CGRectMake((self.view.frame.size.width - 300)/2, 200, 300, 100);
@@ -195,8 +208,17 @@
     [self.signatureDrawTextView signatureClear];
 }
 
+- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
+    [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
+    [self updatePreferredContentSizeWithTraitCollection:newCollection];
+}
+
 #pragma mark - Private Methods
 
+- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
+    self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 750);
+}
+
 - (void)createGestureRecognizer {
     [self.createButton setUserInteractionEnabled:YES];
 
@@ -233,6 +255,7 @@
             [self.delegate signatureEditViewController:self image:image];
         }
     } else if (CSignatureTopBarImage == self.selecIndex) {
+        [self.signatureDrawTextView signatureClear];
         UIImage *image = [self.signatureDrawImageView signatureImage];
         if (self.delegate && [self.delegate respondsToSelector:@selector(signatureEditViewController:image:)]) {
             [self.delegate signatureEditViewController:self image:image];
@@ -260,13 +283,17 @@
     if (self.segmentedControl.selectedSegmentIndex == 0) {
         self.colorSelectView.hidden = NO;
         self.signatureDrawTextView.hidden = NO;
-        self.signatureDrawImageView.hidden = YES;
-        self.textField.hidden = YES;
         self.selecIndex = CSignatureTopBarDefault;
         self.colorSelectView.hidden = NO;
-        self.createButton.hidden = YES;
         self.clearButton.hidden = NO;
         self.signatureDrawTextView.selectIndex = CSignatureDrawText;
+        self.emptyLabel.hidden = NO;
+        self.thicknessView.hidden = NO;
+        
+        self.signatureDrawImageView.hidden = YES;
+        self.createButton.hidden = YES;
+        self.textField.hidden = YES;
+        [self.textField resignFirstResponder];
     } else if (self.segmentedControl.selectedSegmentIndex == 1) {
         self.colorSelectView.hidden = NO;
         self.signatureDrawTextView.hidden = YES;
@@ -277,8 +304,10 @@
         self.createButton.hidden = YES;
         self.thicknessView.hidden = YES;
         self.clearButton.hidden = NO;
-        [self.textField resignFirstResponder];
+        self.emptyLabel.hidden = YES;
+        [self.textField becomeFirstResponder];
     } else if (self.segmentedControl.selectedSegmentIndex == 2) {
+        [self.textField resignFirstResponder];
         self.colorSelectView.hidden = YES;
         self.signatureDrawTextView.hidden = YES;
         self.signatureDrawImageView.hidden = NO;
@@ -289,6 +318,7 @@
         self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
         self.thicknessView.hidden = YES;
         self.clearButton.hidden = YES;
+        self.emptyLabel.hidden = NO;
         [self.signatureDrawImageView setNeedsDisplay];
     }
 }
@@ -301,7 +331,11 @@
 - (void)buttonItemClicked_clear:(UIButton *)button {
     if (self.segmentedControl.selectedSegmentIndex == 0) {
         [self.signatureDrawTextView signatureClear];
+        self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
+    } else if (self.segmentedControl.selectedSegmentIndex == 1) {
+        self.textField.text = @"";
     }
+    
 }
 
 #pragma mark - UITextFieldDelegate
@@ -449,6 +483,7 @@
 
 - (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView {
     [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+    self.emptyLabel.text = @"";
 }
 
 @end

+ 23 - 10
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureViewController.m

@@ -17,8 +17,9 @@
 #import "CPDFSignatureEditViewController.h"
 
 #import <compdfkit_tools/CPDFColorUtils.h>
+#import <compdfkit_tools/AAPLCustomPresentationController.h>
 
-@interface CPDFSignatureViewController () <UITableViewDelegate, UITableViewDataSource, CPDFSignatureViewCellDelegate>
+@interface CPDFSignatureViewController () <UITableViewDelegate, UITableViewDataSource, CPDFSignatureViewCellDelegate,CPDFSignatureEditViewControllerDelegate>
 
 @property (nonatomic, strong) UIButton *backBtn;
 
@@ -124,8 +125,6 @@
     [gestureRecognizer setTranslation:CGPointZero inView:self.view];
 }
 
-#pragma mark - Protect Methods
-
 - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
     self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 660);
 }
@@ -133,18 +132,21 @@
 #pragma mark - Action
 
 - (void)buttonItemClicked_back:(id)sender {
-    if([self.delegate performSelector:@selector(signatureViewControllerDismiss:)]) {
+    [self dismissViewControllerAnimated:NO completion:nil];
+    if(self.delegate && [self.delegate respondsToSelector:@selector(signatureViewControllerDismiss:)]) {
         [self.delegate signatureViewControllerDismiss:self];
     }
-    [self dismissViewControllerAnimated:YES completion:^{
-    }];
 }
 
 - (void)buttonItemClicked_create:(id)sender {
-    [self dismissViewControllerAnimated:NO completion:nil];
-    if (self.delegate && [self.delegate respondsToSelector:@selector(signatureViewController:)]) {
-        [self.delegate signatureViewController:self];
-    }
+    AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+    CPDFSignatureEditViewController *editVC = [[CPDFSignatureEditViewController alloc] init];
+    
+    editVC.delegate = self;
+    
+    presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:editVC presentingViewController:self];
+    editVC.transitioningDelegate = presentationController;
+    [self presentViewController:editVC animated:YES completion:nil];
 }
 
 #pragma mark - UITableViewDataSource
@@ -197,4 +199,15 @@
     [self.tableView reloadData];
 }
 
+#pragma mark - CPDFSignatureEditViewControllerDelegate
+
+- (void)signatureEditViewController:(CPDFSignatureEditViewController *)signatureEditViewController image:(UIImage *)image{
+    [[CSignatureManager sharedManager] addImageSignature:image];
+    [self.tableView reloadData];
+    
+//    CPDFSignatureAnnotation *annotation = [[CPDFSignatureAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document];
+//    [annotation setImage:image];
+//    self.annotManage.pdfListView.addAnnotation = annotation;
+}
+
 @end

+ 1 - 13
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CSignatureDrawView.m

@@ -34,7 +34,7 @@ static NSInteger _index;
         self.bezierPath = [[UIBezierPath alloc] init];
         self.lineWidth = 1;
         
-        self.backgroundColor = [UIColor whiteColor];
+        self.backgroundColor = [UIColor clearColor];
     }
     return self;
 }
@@ -64,18 +64,6 @@ static NSInteger _index;
             }
         }
     }
-    
-    NSString *string = @"Sign here";
-    self.textRect = CGRectInset(rect, (rect.size.width/7)*2, (rect.size.height/7)*3);
-    UIFont *font = [UIFont systemFontOfSize:30];
-    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:[UIColor grayColor]}];
-    CGSize textSize = [attributedText boundingRectWithSize:rect.size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil].size;
-
-    CGFloat x = self.textRect.origin.x + (self.textRect.size.width - textSize.width) / 2.0;
-    CGFloat y = self.textRect.origin.y + (self.textRect.size.height - textSize.height) / 2.0;
-    CGPoint center = CGPointMake(x, y);
-
-    [attributedText drawAtPoint:center];
 }
 
 #pragma mark - Draw Methods

+ 2 - 1
compdfkit-tools/compdfkit-tools/Common/Model/CAnnotStyle.m

@@ -360,6 +360,7 @@
                 break;
             case CPDFViewAnnotationModeInk:
                 opacity = [CPDFKitConfig sharedInstance].freehandAnnotationOpacity;
+                opacity/=100;
                 break;
             default:
                 break;
@@ -407,7 +408,7 @@
                 [userDefaults setFloat:opacity forKey:CArrowNoteOpacityKey];
                 break;
             case CPDFViewAnnotationModeInk:
-                [[CPDFKitConfig sharedInstance] setFreehandAnnotationOpacity:opacity];
+                [[CPDFKitConfig sharedInstance] setFreehandAnnotationOpacity:opacity * 100];
 
                 [userDefaults setFloat:opacity forKey:CInkNoteOpacityKey];
                 break;

+ 6 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.h

@@ -70,6 +70,12 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)buttonItemClicked_open:(UIButton *)button;
 
+- (void)openSignatureAnnotation:(CPDFSignatureAnnotation *)signatureAnnotation;
+
+- (void)addStampAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point;
+
+- (void)addImageAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 151 - 64
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -58,6 +58,12 @@
 
 @property (nonatomic, strong) CPDFSignatureViewController *signatureVC;
 
+@property (nonatomic, assign) CGPoint menuPoint;
+
+@property (nonatomic, strong) CPDFPage * menuPage;
+
+@property (nonatomic, assign) BOOL isAddAnnotation;
+
 @end
 
 @implementation CPDFAnnotationBar
@@ -123,6 +129,29 @@
     }
 }
 
+- (void)openSignatureAnnotation:(CPDFSignatureAnnotation *)signatureAnnotation {
+    
+}
+
+- (void)addStampAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point {
+    self.isAddAnnotation = YES;
+    self.menuPage = page;
+    self.menuPoint = point;
+    AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+    CPDFStampViewController *stampVC = [[CPDFStampViewController alloc] init];
+    presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:self.signatureVC presentingViewController:self.parentVC];
+    stampVC.delegate = self;
+    stampVC.transitioningDelegate = presentationController;
+    [self.parentVC presentViewController:stampVC animated:YES completion:nil];
+}
+
+- (void)addImageAnnotationWithPage:(CPDFPage *)page point:(CGPoint)point {
+    self.isAddAnnotation = YES;
+    self.menuPage = page;
+    self.menuPoint = point;
+    [self createImageAnnotaion];
+}
+
 #pragma mark - Private Methods
 
 - (void)initSubview {
@@ -272,8 +301,13 @@
     if (self.pdfListView.annotationMode != self.selectedIndex) {
         self.propertiesBtn.enabled = YES;
         button.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
+        if(CPDFViewAnnotationModeInk == self.selectedIndex) {
+            [CPDFKitConfig sharedInstance].enableFreehandPencilKit = NO;
+        } else if (CPDFViewAnnotationModePencilDrawing == self.selectedIndex) {
+            [CPDFKitConfig sharedInstance].enableFreehandPencilKit = YES;
+        }
         self.pdfListView.annotationMode = self.selectedIndex;
-        
+
         [self.annotManage setAnnotStyleFromMode:self.selectedIndex];
         isSelect = YES;
 
@@ -434,7 +468,6 @@
 
 - (void)createPropertyViewController {
     if (CPDFViewAnnotationModeInk == self.selectedIndex) {
-        [CPDFKitConfig  sharedInstance].enableFreehandPencilKit = NO;
 
         self.propertiesBtn.enabled = NO;
         if (@available(iOS 11.0, *)) {
@@ -474,12 +507,6 @@
     } else if (CPDFViewAnnotationModeSound == self.selectedIndex) {
   
     } else if (CPDFViewAnnotationModePencilDrawing == self.selectedIndex) {
-        if (@available(iOS 13.0, *)) {
-            [CPDFKitConfig  sharedInstance].enableFreehandPencilKit = YES;
-        } else {
-            [CPDFKitConfig  sharedInstance].enableFreehandPencilKit = NO;
-        }
-        
         self.propertiesBtn.enabled = NO;
         if (@available(iOS 13.0, *)) {
             float tWidth  = 412.0;
@@ -559,9 +586,22 @@
         image = [UIImage imageWithCGImage:imageRef];
         CGImageRelease(imageRef);
     }
-    
     CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document image:image];
-    self.annotManage.pdfListView.addAnnotation = annotation;
+
+    if(self.isAddAnnotation) {
+        CGRect bounds = annotation.bounds;
+        bounds.origin.x = self.menuPoint.x-bounds.size.width/2.0;
+        bounds.origin.y = self.menuPoint.y-bounds.size.height/2.0;
+        annotation.bounds = bounds;
+        [self.pdfListView addAnnotation:annotation forPage:self.menuPage];
+        
+        self.isAddAnnotation = NO;
+        self.menuPage = nil;
+        self.menuPoint = CGPointZero;
+
+    } else {
+        self.annotManage.pdfListView.addAnnotation = annotation;
+    }
 }
 
 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
@@ -575,11 +615,7 @@
 }
 
 - (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController {
-    CPDFSignatureEditViewController *editVC = [[CPDFSignatureEditViewController alloc] init];
-    CNavigationController *nav = [[CNavigationController alloc]initWithRootViewController:editVC];
-    editVC.delegate = self;
-    
-    [self.parentVC presentViewController:nav animated:YES completion:nil];
+   
 }
 
 - (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController image:(UIImage *)image {
@@ -589,18 +625,6 @@
     self.annotManage.pdfListView.addAnnotation = annotation;
 }
 
-#pragma mark - CPDFSignatureEditViewControllerDelegate
-
-- (void)signatureEditViewController:(CPDFSignatureEditViewController *)signatureEditViewController image:(UIImage *)image{
-    [[CSignatureManager sharedManager] addImageSignature:image];
-    [self reloadData];
-    [self.signatureVC.tableView reloadData];
-    
-    CPDFSignatureAnnotation *annotation = [[CPDFSignatureAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document];
-    [annotation setImage:image];
-    self.annotManage.pdfListView.addAnnotation = annotation;
-}
-
 #pragma mark - CPDFNoteViewControllerDelegate
 
 - (void)noteViewController:(CPDFNoteViewController *)noteViewController annotSytle:(CAnnotStyle *)annotStyle {
@@ -839,6 +863,9 @@
 - (void)annotationChangedNotification:(NSNotification *)notification {
     if (self.pdfListView.activeAnnotations.firstObject) {
         [self.annotManage setAnnotStyleFromAnnotations:self.pdfListView.activeAnnotations];
+    } else {
+        [self.annotManage setAnnotStyleFromMode:self.pdfListView.annotationMode];
+
     }
     [self updatePropertiesButtonState];
 }
@@ -846,49 +873,109 @@
 #pragma mark - CPDFStampViewControllerDelegate
 
 - (void)stampViewController:(CPDFStampViewController *)stampViewController selectedIndex:(NSInteger)selectedIndex stamp:(NSDictionary *)stamp {
-    if (selectedIndex == -1) {
-        self.annotManage.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
-        [self reloadData];
-    } else {
-        if (stamp.count > 0) {
-            if (stamp[PDFAnnotationStampKeyImagePath]) {
-                UIImage *image = [UIImage imageWithContentsOfFile:stamp[PDFAnnotationStampKeyImagePath]];
-                CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document image:image];
-                self.annotManage.pdfListView.addAnnotation = annotation;
+    if(self.isAddAnnotation) {
+        if (selectedIndex == -1) {
+        } else {
+            if (stamp.count > 0) {
+                if (stamp[PDFAnnotationStampKeyImagePath]) {
+                    UIImage *image = [UIImage imageWithContentsOfFile:stamp[PDFAnnotationStampKeyImagePath]];
+                    CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document image:image];
+                    CGRect bounds = annotation.bounds;
+                    bounds.origin.x = self.menuPoint.x-bounds.size.width/2.0;
+                    bounds.origin.y = self.menuPoint.y-bounds.size.height/2.0;
+                    annotation.bounds = bounds;
+                    [self.annotManage.pdfListView addAnnotation:annotation forPage:self.menuPage];
+                } else {
+                    NSString *stampText = stamp[PDFAnnotationStampKeyText];
+                    BOOL stampShowDate = [stamp[PDFAnnotationStampKeyShowDate] boolValue];
+                    BOOL stampShowTime = [stamp[PDFAnnotationStampKeyShowTime] boolValue];
+                    CPDFStampStyle stampStyle = [stamp[PDFAnnotationStampKeyStyle] integerValue];
+                    CPDFStampShape stampShape = [stamp[PDFAnnotationStampKeyShape] integerValue];
+                    
+                    NSString *detailText = nil;
+                    NSTimeZone *timename = [NSTimeZone systemTimeZone];
+                    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
+                    [outputFormatter setTimeZone:timename];
+                    if (stampShowDate && !stampShowTime){
+                        detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
+                                                                    dateStyle:NSDateFormatterShortStyle
+                                                                    timeStyle:NSDateFormatterNoStyle];
+                    } else if (stampShowTime && !stampShowDate) {
+                        [outputFormatter setDateFormat:@"HH:mm:ss"];
+                        detailText = [outputFormatter stringFromDate:[NSDate date]];
+                    } else if (stampShowDate && stampShowTime) {
+                        [outputFormatter setDateFormat:@" HH:mm"];
+                        detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
+                                                                    dateStyle:NSDateFormatterShortStyle
+                                                                    timeStyle:NSDateFormatterNoStyle];
+                        detailText = [detailText stringByAppendingString:[outputFormatter stringFromDate:[NSDate date]]];
+                    }
+                    
+                    CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document text:stampText detailText:detailText style:stampStyle shape:stampShape];
+                    CGRect bounds = annotation.bounds;
+                    bounds.origin.x = self.menuPoint.x-bounds.size.width/2.0;
+                    bounds.origin.y = self.menuPoint.y-bounds.size.height/2.0;
+                    annotation.bounds = bounds;
+                    [self.annotManage.pdfListView addAnnotation:annotation forPage:self.menuPage];
+                }
             } else {
-                NSString *stampText = stamp[PDFAnnotationStampKeyText];
-                BOOL stampShowDate = [stamp[PDFAnnotationStampKeyShowDate] boolValue];
-                BOOL stampShowTime = [stamp[PDFAnnotationStampKeyShowTime] boolValue];
-                CPDFStampStyle stampStyle = [stamp[PDFAnnotationStampKeyStyle] integerValue];
-                CPDFStampShape stampShape = [stamp[PDFAnnotationStampKeyShape] integerValue];
-                
-                NSString *detailText = nil;
-                NSTimeZone *timename = [NSTimeZone systemTimeZone];
-                NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
-                [outputFormatter setTimeZone:timename];
-                if (stampShowDate && !stampShowTime){
-                    detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
-                                                                dateStyle:NSDateFormatterShortStyle
-                                                                timeStyle:NSDateFormatterNoStyle];
-                } else if (stampShowTime && !stampShowDate) {
-                    [outputFormatter setDateFormat:@"HH:mm:ss"];
-                    detailText = [outputFormatter stringFromDate:[NSDate date]];
-                } else if (stampShowDate && stampShowTime) {
-                    [outputFormatter setDateFormat:@" HH:mm"];
-                    detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
-                                                                dateStyle:NSDateFormatterShortStyle
-                                                                timeStyle:NSDateFormatterNoStyle];
-                    detailText = [detailText stringByAppendingString:[outputFormatter stringFromDate:[NSDate date]]];
+                CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document type:selectedIndex+1];
+                CGRect bounds = annotation.bounds;
+                bounds.origin.x = self.menuPoint.x-bounds.size.width/2.0;
+                bounds.origin.y = self.menuPoint.y-bounds.size.height/2.0;
+                annotation.bounds = bounds;
+                [self.annotManage.pdfListView addAnnotation:annotation forPage:self.menuPage];
+            }
+        }
+        self.isAddAnnotation = NO;
+        self.menuPage = nil;
+        self.menuPoint = CGPointZero;
+    } else {
+        if (selectedIndex == -1) {
+            self.annotManage.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
+            [self reloadData];
+        } else {
+            if (stamp.count > 0) {
+                if (stamp[PDFAnnotationStampKeyImagePath]) {
+                    UIImage *image = [UIImage imageWithContentsOfFile:stamp[PDFAnnotationStampKeyImagePath]];
+                    CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document image:image];
+                    self.annotManage.pdfListView.addAnnotation = annotation;
+                } else {
+                    NSString *stampText = stamp[PDFAnnotationStampKeyText];
+                    BOOL stampShowDate = [stamp[PDFAnnotationStampKeyShowDate] boolValue];
+                    BOOL stampShowTime = [stamp[PDFAnnotationStampKeyShowTime] boolValue];
+                    CPDFStampStyle stampStyle = [stamp[PDFAnnotationStampKeyStyle] integerValue];
+                    CPDFStampShape stampShape = [stamp[PDFAnnotationStampKeyShape] integerValue];
+                    
+                    NSString *detailText = nil;
+                    NSTimeZone *timename = [NSTimeZone systemTimeZone];
+                    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
+                    [outputFormatter setTimeZone:timename];
+                    if (stampShowDate && !stampShowTime){
+                        detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
+                                                                    dateStyle:NSDateFormatterShortStyle
+                                                                    timeStyle:NSDateFormatterNoStyle];
+                    } else if (stampShowTime && !stampShowDate) {
+                        [outputFormatter setDateFormat:@"HH:mm:ss"];
+                        detailText = [outputFormatter stringFromDate:[NSDate date]];
+                    } else if (stampShowDate && stampShowTime) {
+                        [outputFormatter setDateFormat:@" HH:mm"];
+                        detailText = [NSDateFormatter localizedStringFromDate:[NSDate date]
+                                                                    dateStyle:NSDateFormatterShortStyle
+                                                                    timeStyle:NSDateFormatterNoStyle];
+                        detailText = [detailText stringByAppendingString:[outputFormatter stringFromDate:[NSDate date]]];
+                    }
+                    
+                    CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document text:stampText detailText:detailText style:stampStyle shape:stampShape];
+                    self.annotManage.pdfListView.addAnnotation = annotation;
                 }
-                
-                CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document text:stampText detailText:detailText style:stampStyle shape:stampShape];
+            } else {
+                CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document type:selectedIndex+1];
                 self.annotManage.pdfListView.addAnnotation = annotation;
             }
-        } else {
-            CPDFStampAnnotation *annotation = [[CPDFStampAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document type:selectedIndex+1];
-            self.annotManage.pdfListView.addAnnotation = annotation;
         }
     }
+    
 }
 
 @end

+ 7 - 12
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFAnnotationSampleView.m

@@ -243,21 +243,16 @@
             NSString *sampleStr = @"Sample";
             CGContextSetAlpha(context, self.opcity);
             UIFont *font = [UIFont fontWithName:self.fontName size:self.thickness];
-            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-            if (self.isBold && !(self.isItalic)) {
-                font = [UIFont boldSystemFontOfSize:self.thickness];
-            } else if (self.isItalic && !(self.isBold)) {
-                font = [UIFont italicSystemFontOfSize:self.thickness];
-                
-            } else if (self.isBold && self.isItalic) {
-                font = [UIFont boldSystemFontOfSize:self.thickness];
-                font = [UIFont italicSystemFontOfSize:self.thickness];
-            }
             if (!self.fillColor) {
                 self.fillColor = [UIColor whiteColor];
             }
-            [dic addEntriesFromDictionary:@{NSFontAttributeName:font, NSForegroundColorAttributeName:self.fillColor}];
-            [sampleStr drawInRect:self.arrowRect withAttributes:dic];
+            NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:sampleStr attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:self.fillColor}];
+            CGSize textSize = [attributedText boundingRectWithSize:self.bounds.size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil].size;
+
+            CGFloat x = self.bounds.origin.x + (self.bounds.size.width - textSize.width) / 2.0;
+            CGFloat y = self.bounds.origin.y + (self.bounds.size.height - textSize.height) / 2.0;
+            CGPoint center = CGPointMake(x, y);
+            [attributedText drawAtPoint:center];
         }
             break;
         default:

+ 17 - 6
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFFontStyleTableView.m

@@ -12,6 +12,8 @@
 
 #import "CPDFFontStyleTableView.h"
 
+#import <compdfkit_tools/CPDFColorUtils.h>
+
 @interface CPDFFontStyleTableView () <UITableViewDelegate, UITableViewDataSource>
 
 @property (nonatomic, strong) NSArray *dataArray;
@@ -22,6 +24,8 @@
 
 @property (nonatomic, strong) UITableView *tableView;
 
+@property (nonatomic, strong) UIView *headerView;
+
 @end
 
 @implementation CPDFFontStyleTableView
@@ -45,24 +49,31 @@
 
 - (instancetype)initWithFrame:(CGRect)frame {
     if (self = [super initWithFrame:frame]) {
-        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - 120)/2, 0, 120, (self.bounds.size.height - 40)/6)];
+        self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 50)];
+        self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
+        self.headerView.layer.borderWidth = 1.0;
+        self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+        [self addSubview:self.headerView];
+        
+        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - 120)/2, 0, 120, 50)];
         self.titleLabel.text = NSLocalizedString(@"Font Name", nil);
         self.titleLabel.autoresizingMask  = UIViewAutoresizingFlexibleHeight;
-        [self addSubview:self.titleLabel];
+        [self.headerView addSubview:self.titleLabel];
         
-        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, (self.bounds.size.height - 40)/6)];
+        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, 50)];
         self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleHeight;
         [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBarImageUndo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
         [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
-        [self addSubview:self.backBtn];
+        [self.headerView addSubview:self.backBtn];
         
-        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (self.bounds.size.height - 40)/6, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
+        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
         self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
         self.tableView.delegate = self;
         self.tableView.dataSource = self;
+        self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
         [self addSubview:self.tableView];
         
-        self.backgroundColor = [UIColor whiteColor];
+        self.backgroundColor =  self.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];;
     }
     return self;;
 }