CPDFDigitalSignatureToolBar.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // CPDFDigitalSignatureToolBar.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFDigitalSignatureToolBar.h"
  13. #import "CPDFColorUtils.h"
  14. #import "CPDFListView.h"
  15. #import "CAnnotationManage.h"
  16. #import <ComPDFKit/ComPDFKit.h>
  17. @interface CPDFDigitalSignatureToolBar ()
  18. @property (nonatomic, strong) CPDFListView *pdfListView;
  19. @property (nonatomic, strong) UIButton *addDigitalSignatureBtn;
  20. @property (nonatomic, strong) UIButton *verifyDigitalSignatureBtn;
  21. @property(nonatomic, strong) CAnnotationManage *annotationManage;
  22. @end
  23. @implementation CPDFDigitalSignatureToolBar
  24. #pragma mark - Initializers
  25. - (instancetype)initWithPDFListView:(CPDFListView *)pdfListView {
  26. if (self = [super init]) {
  27. self.pdfListView = pdfListView;
  28. self.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  29. self.addDigitalSignatureBtn = [[UIButton alloc] init];
  30. [self.addDigitalSignatureBtn setTitle:NSLocalizedString(@"Add Signatures", nil) forState:UIControlStateNormal];
  31. [self.addDigitalSignatureBtn setTitleColor:[CPDFColorUtils CPageEditToolbarFontColor] forState:UIControlStateNormal];
  32. [self.addDigitalSignatureBtn setImage:[UIImage imageNamed:@"CPDFDigitalSignatureAdd" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  33. [self.addDigitalSignatureBtn addTarget:self action:@selector(buttonItemClicked_add:) forControlEvents:UIControlEventTouchUpInside];
  34. self.addDigitalSignatureBtn.backgroundColor = [CPDFColorUtils CAnnotationBarNoSelectBackgroundColor];
  35. self.addDigitalSignatureBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  36. self.addDigitalSignatureBtn.layer.cornerRadius = 10.0;
  37. self.addDigitalSignatureBtn.layer.masksToBounds = YES;
  38. self.addDigitalSignatureBtn.selected = NO;
  39. [self addSubview:self.addDigitalSignatureBtn];
  40. self.verifyDigitalSignatureBtn = [[UIButton alloc] init];
  41. [self.verifyDigitalSignatureBtn setTitle:NSLocalizedString(@"Verify the Signature", nil) forState:UIControlStateNormal];
  42. [self.verifyDigitalSignatureBtn setTitleColor:[CPDFColorUtils CPageEditToolbarFontColor] forState:UIControlStateNormal];
  43. [self.verifyDigitalSignatureBtn setImage:[UIImage imageNamed:@"CPDFDigitalSignatureVerify" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  44. [self.verifyDigitalSignatureBtn addTarget:self action:@selector(buttonItemClicked_verify:) forControlEvents:UIControlEventTouchUpInside];
  45. self.verifyDigitalSignatureBtn.backgroundColor = [CPDFColorUtils CAnnotationBarNoSelectBackgroundColor];
  46. [self.verifyDigitalSignatureBtn setBackgroundImage:[self imageWithColor:[CPDFColorUtils CAnnotationBarSelectBackgroundColor]] forState:UIControlStateHighlighted];
  47. self.verifyDigitalSignatureBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  48. self.verifyDigitalSignatureBtn.layer.cornerRadius = 10.0;
  49. self.verifyDigitalSignatureBtn.layer.masksToBounds = YES;
  50. self.addDigitalSignatureBtn.selected = NO;
  51. [self addSubview:self.verifyDigitalSignatureBtn];
  52. self.annotationManage = [[CAnnotationManage alloc] initWithPDFView:pdfListView];
  53. }
  54. return self;
  55. }
  56. - (void)layoutSubviews {
  57. [super layoutSubviews];
  58. self.addDigitalSignatureBtn.frame = CGRectMake((self.frame.size.width-310)/2, 5, 140, 50);
  59. self.verifyDigitalSignatureBtn.frame = CGRectMake(self.addDigitalSignatureBtn.frame.origin.x + 170, 5, 140, 50);
  60. }
  61. #pragma mark - Private Methods
  62. - (UIImage *)imageWithColor:(UIColor *)color {
  63. CGRect rect = CGRectMake(0, 0, 1, 1);
  64. UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
  65. [color setFill];
  66. UIRectFill(rect);
  67. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  68. UIGraphicsEndImageContext();
  69. return image;
  70. }
  71. #pragma mark - Action
  72. - (void)buttonItemClicked_add:(UIButton *)button {
  73. button.selected = !button.selected;
  74. if (button.selected) {
  75. button.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  76. self.verifyDigitalSignatureBtn.backgroundColor = [CPDFColorUtils CAnnotationBarNoSelectBackgroundColor];
  77. self.pdfListView.annotationMode = CPDFViewFormModeSign;
  78. self.pdfListView.toolModel = CToolModelForm;
  79. [self.annotationManage setAnnotStyleFromMode:CPDFViewFormModeSign];
  80. } else {
  81. button.backgroundColor = [CPDFColorUtils CAnnotationBarNoSelectBackgroundColor];
  82. self.pdfListView.toolModel = CToolModelViewer;
  83. self.pdfListView.annotationMode = CPDFViewAnnotationModeNone;
  84. }
  85. if ([self.delegate respondsToSelector:@selector(addSignatureBar:souceButton:)]) {
  86. [self.delegate addSignatureBar:self souceButton:button];
  87. }
  88. }
  89. - (void)buttonItemClicked_verify:(UIButton *)button {
  90. if (button.selected) {
  91. self.addDigitalSignatureBtn.backgroundColor = [CPDFColorUtils CAnnotationBarNoSelectBackgroundColor];
  92. }
  93. if ([self.delegate respondsToSelector:@selector(verifySignatureBar:souceButton:)]) {
  94. [self.delegate verifySignatureBar:self souceButton:button];
  95. }
  96. }
  97. - (void)updateStatusWithsignatures:(NSArray<CPDFSignature *> *) signatures {
  98. if(signatures.count > 0) {
  99. self.verifyDigitalSignatureBtn.enabled = YES;
  100. } else {
  101. self.verifyDigitalSignatureBtn.enabled = NO;
  102. }
  103. }
  104. @end