KMSignatureWindowController.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. //
  2. // KMSignatureWindowController.m
  3. // PDF Reader Premium
  4. //
  5. // Created by wangshuai on 14/12/3.
  6. // Copyright (c) 2014年 zhangjie. All rights reserved.
  7. //
  8. #import "KMSignatureWindowController.h"
  9. #import "KMDrawView.h"
  10. #import "KMSignatureManager.h"
  11. #import "NSImage+CustomImage.h"
  12. #import "KMPDFSignatureImageView.h"
  13. #import "KMPDFSignatureTextView.h"
  14. #import "KMPopUpButton.h"
  15. #import "CPDFListView.h"
  16. #import <PDF_Master-Swift.h>
  17. #import "KMSignatureHelpViewController.h"
  18. static NSMutableArray * recentlyFonts;
  19. #pragma mark KMSignatureColorButton
  20. @interface KMSignatureColorButton : NSButton
  21. @property (nonatomic,retain) NSColor *circleColor;
  22. @property (nonatomic,retain) NSImage *drawImage;
  23. @end
  24. @implementation KMSignatureColorButton
  25. -(void)setCircleColor:(NSColor *)circleColor
  26. {
  27. _circleColor = circleColor;
  28. [self setNeedsDisplay:YES];
  29. }
  30. -(id)initWithCoder:(NSCoder *)coder {
  31. if (self == [super initWithCoder:coder]) {
  32. self.wantsLayer = YES;
  33. self.layer.cornerRadius = 12;
  34. self.layer.masksToBounds = YES;
  35. self.layer.borderWidth = 1.5;
  36. }
  37. return self;
  38. }
  39. -(void)drawRect:(NSRect)rect
  40. {
  41. [super drawRect:rect];
  42. if (_circleColor) {
  43. NSBezierPath *path3 = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(3, 3, rect.size.width - 6, rect.size.height - 6)];
  44. [self.circleColor set];
  45. [path3 fill];
  46. } else if (self.drawImage) {
  47. [self.drawImage drawInRect:CGRectMake(3,3,rect.size.width -6,rect.size.height - 6)
  48. fromRect:NSZeroRect
  49. operation:NSCompositeSourceOver
  50. fraction:1.0];
  51. }
  52. }
  53. @end
  54. #pragma mark KMSignatureButton
  55. @interface KMSignatureButton : NSButton
  56. @end
  57. @implementation KMSignatureButton
  58. - (NSMenu*)menuForEvent:(NSEvent *)theEvent
  59. {
  60. NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
  61. NSMenuItem *item = [menu addItemWithTitle:NSLocalizedString(@"Delete", nil) action:@selector(delete) keyEquivalent:@""];
  62. item.target = self;
  63. item = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil keyEquivalent:@""];
  64. NSMenu * tSubMenu = [[NSMenu alloc] init];
  65. NSMenuItem *tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(export:) target:self atIndex:0];
  66. tMenuItem.tag = 0;
  67. tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(export:) target:self atIndex:1];
  68. tMenuItem.tag = 1;
  69. tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(export:) target:self atIndex:2];
  70. tMenuItem.tag = 2;
  71. item.submenu = tSubMenu;
  72. return menu;
  73. }
  74. - (void)delete
  75. {
  76. [[NSNotificationCenter defaultCenter] postNotificationName:@"kKMSignatureDeleteNotification" object:[NSNumber numberWithInteger:self.tag]];
  77. }
  78. - (void)export:(NSMenuItem *)sender
  79. {
  80. NSInteger index = self.tag;
  81. NSInteger type = sender.tag;
  82. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  83. [signatureManager loadAllSignatureList];
  84. KMSignature *signature = signatureManager.sigatureList[index];
  85. NSImage *image = signature.pathsImage;
  86. if (type == 0) {
  87. NSData *data = image.TIFFRepresentation;
  88. NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
  89. [imageRep setSize:image.size];
  90. NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:@{}];
  91. NSSavePanel *savePanel = [NSSavePanel savePanel];
  92. savePanel.allowedFileTypes = @[@"png"];
  93. [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
  94. if (result) {
  95. if ([imageData writeToURL:savePanel.URL atomically:YES]) {
  96. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  97. inFileViewerRootedAtPath:@""];
  98. }
  99. }
  100. }];
  101. } else if (type == 1) {
  102. NSData *data = image.TIFFRepresentation;
  103. NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
  104. [imageRep setSize:image.size];
  105. NSData *imageData = [imageRep representationUsingType:NSJPEGFileType properties:@{}];
  106. NSSavePanel *savePanel = [NSSavePanel savePanel];
  107. savePanel.allowedFileTypes = @[@"jpg"];
  108. [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
  109. if (result) {
  110. if ([imageData writeToURL:savePanel.URL atomically:YES]) {
  111. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  112. inFileViewerRootedAtPath:@""];
  113. }
  114. }
  115. }];
  116. } else {
  117. CPDFDocument *pdf = [[CPDFDocument alloc] init];
  118. // CPDFPage *page = [[CPDFPage alloc] initWithImage:image];
  119. NSString *signatureImagePath =[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"signatureImage.png"];
  120. NSData *data = image.TIFFRepresentation;
  121. [data writeToURL:[NSURL fileURLWithPath:signatureImagePath] atomically:YES];
  122. [pdf insertPage:image.size withImage:signatureImagePath atIndex:0];
  123. NSSavePanel *savePanel = [NSSavePanel savePanel];
  124. savePanel.allowedFileTypes = @[@"pdf"];
  125. [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result) {
  126. if (result) {
  127. if ([pdf writeToURL:savePanel.URL]) {
  128. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  129. inFileViewerRootedAtPath:@""];
  130. }
  131. }
  132. }];
  133. }
  134. }
  135. @end
  136. #pragma mark KMSignatureWindowController
  137. static KMSignatureWindowController *windowController_signature;
  138. @interface KMSignatureWindowController () <KMDrawViewDelegate,KMChangeSignatureTextDelegate, KMSelectPopButtonDelegate>
  139. @property (weak) IBOutlet NSButton *cancelBtton;
  140. @property (weak) IBOutlet NSButton *applyButton;
  141. @property (nonatomic, strong) KMDesignButton *cancelButtonVC;
  142. @property (nonatomic, strong) KMDesignButton *applyButtonVC;
  143. @property (weak) IBOutlet NSButton *clearButton;
  144. @property (strong) IBOutlet NSView *signTypeView;
  145. @property (weak) IBOutlet NSButton *inputButton;
  146. @property (weak) IBOutlet NSButton *drawingButton;
  147. @property (weak) IBOutlet NSButton *pictureButton;
  148. @property (strong) IBOutlet NSView *signTypeBackView;
  149. @property (weak) IBOutlet NSTextField *trackpadLabel;
  150. @property (weak) IBOutlet NSBox *contentBox;
  151. @property (weak) IBOutlet NSTextField *titleLabel;
  152. //keyboard
  153. @property (strong) IBOutlet NSView *inputView;
  154. @property (weak) IBOutlet KMPDFSignatureTextView *keyboardView;
  155. @property (weak) IBOutlet NSPopUpButton *fontBox;
  156. @property (strong) IBOutlet NSButton *keyboardColorBtn1;
  157. @property (strong) IBOutlet NSButton *keyboardColorBtn2;
  158. @property (strong) IBOutlet NSButton *keyboardColorBtn3;
  159. @property (strong) IBOutlet NSButton *keyboardColorBtn4;
  160. @property (strong) IBOutlet NSView *keyboardColorSelView;
  161. @property (weak) IBOutlet KMSignatureColorButton *textColorButton;
  162. @property (nonatomic, strong) KMDesignSelect *fontVC;
  163. @property (nonatomic, strong) NSArray *fontValues;
  164. @property (nonatomic, copy) NSString *fontDefaultValue;
  165. //Draw
  166. @property (strong) IBOutlet NSView *drawingView;
  167. @property (weak) IBOutlet KMDrawView *drawView;
  168. @property (weak) IBOutlet NSButton *trackpadButton;
  169. @property (nonatomic, strong) KMDesignButton *trackpadButtonVC;
  170. @property (strong) IBOutlet NSPopUpButton *drawSizeBox;
  171. @property (strong) IBOutlet NSView *colorBGView;
  172. @property (strong) IBOutlet NSView *drawColorSelView;
  173. @property (strong) IBOutlet NSButton *drawColorBtn1;
  174. @property (strong) IBOutlet NSButton *drawColorBtn2;
  175. @property (strong) IBOutlet NSButton *drawColorBtn3;
  176. @property (strong) IBOutlet NSButton *drawColorBtn4;
  177. @property (nonatomic, strong) KMDesignSelect *drawSizeVC;
  178. @property (nonatomic, strong) NSArray *drawSizeValues;
  179. @property (nonatomic, copy) NSString *drawSizeDefaultValue;
  180. @property (weak) IBOutlet NSView *drawTipView;
  181. @property (weak) IBOutlet NSTextField *drawTipLabel;
  182. //Picture
  183. @property (strong) IBOutlet NSView *pictureView;
  184. @property (weak) IBOutlet KMPDFSignatureImageView *pictureBackView;
  185. @property (strong) IBOutlet NSButton *pictureClearBackBtn;
  186. @property (nonatomic, strong) KMDesignButton *pictureClearBackBtnVC;
  187. @property (weak) IBOutlet KMCoverButton *pictureHelpButton;
  188. @property (nonatomic,strong) KMSignature *selectedSignature;
  189. @property (nonatomic,strong) NSMenuItem *selectItem;
  190. @property (nonatomic,assign) kKMPDFSignatureType type;
  191. @property (nonatomic,copy) void (^handler)(KMSignature*);
  192. @property (nonatomic, strong) NSPopover *popover;
  193. @end
  194. @implementation KMSignatureWindowController
  195. - (id)init
  196. {
  197. if (self = [super initWithWindowNibName:@"KMSignatureWindowController"]) {
  198. NSMutableArray *fonts = [NSMutableArray array];
  199. for (NSDictionary *dic in [CPDFAnnotationModel supportFonts]) {
  200. [fonts addObject:dic.allKeys.firstObject];
  201. }
  202. self.fontValues = fonts.copy;
  203. self.fontDefaultValue = @"Helvetica";
  204. self.drawSizeValues = @[@"1.0",@"2.0",@"4.0",@"6.0",@"8.0"];
  205. self.drawSizeDefaultValue = @"2.0";
  206. }
  207. return self;
  208. }
  209. - (void)dealloc
  210. {
  211. _drawView.delegate = nil;
  212. _keyboardView.delegate = nil;
  213. [[NSNotificationCenter defaultCenter] removeObserver:self];
  214. [[NSColorPanel sharedColorPanel] setTarget:nil];
  215. [[NSColorPanel sharedColorPanel] setAction:nil];
  216. }
  217. #pragma mark - View Methods
  218. - (void)windowDidLoad {
  219. [super windowDidLoad];
  220. __weak typeof (self) weakSelf = self;
  221. self.type = kKMPDFSignatureType_Text;
  222. // self.textColorButton.drawImage = self.mouseColorButton.drawImage = [NSImage imageNamed:@"view_color"];
  223. self.cancelBtton.title = @"";
  224. self.cancelButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  225. [self.cancelBtton addSubview:self.cancelButtonVC.view];
  226. self.cancelButtonVC.view.frame = self.cancelBtton.bounds;
  227. self.cancelButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  228. self.cancelButtonVC.stringValue = NSLocalizedString(@"Cancel", nil);
  229. self.cancelButtonVC.target = self;
  230. self.cancelButtonVC.action = @selector(dismissSheet:);
  231. [self.cancelButtonVC buttonWithType:TokenButtonTypeSec_Icon size:TokenButtonSizeM height:nil];
  232. [self.clearButton setTarget:self];
  233. [self.clearButton setAction:@selector(clearButton_Click:)];
  234. self.clearButton.hidden = YES;
  235. self.applyButton.title = @"";
  236. self.applyButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  237. [self.applyButton addSubview:self.applyButtonVC.view];
  238. self.applyButtonVC.view.frame = self.applyButton.bounds;
  239. self.applyButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  240. self.applyButtonVC.stringValue = NSLocalizedString(@"Save", nil);
  241. self.applyButtonVC.target = self;
  242. self.applyButtonVC.action = @selector(applyButton_Click:);
  243. [self.applyButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeM height:nil];
  244. self.applyButtonVC.enabled = NO;
  245. self.contentBox.wantsLayer = YES;
  246. self.contentBox.layer.backgroundColor = [NSColor clearColor].CGColor;
  247. self.contentBox.borderType = NSNoBorder;
  248. self.inputButton.bordered = self.drawingButton.bordered = self.pictureButton.bordered = NO;
  249. //Keyboard
  250. self.inputView.wantsLayer = YES;
  251. self.inputView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  252. self.keyboardView.wantsLayer = YES;
  253. self.keyboardView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  254. self.keyboardView.changeSignatureTextCallback = ^(BOOL isTure) {
  255. if (isTure) {
  256. weakSelf.clearButton.hidden = NO;
  257. weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
  258. } else {
  259. weakSelf.clearButton.hidden = YES;
  260. }
  261. };
  262. self.keyboardColorBtn1.wantsLayer = self.keyboardColorBtn2.wantsLayer = self.keyboardColorBtn3.wantsLayer = self.keyboardColorBtn4.wantsLayer = YES;
  263. self.keyboardColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
  264. self.keyboardColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
  265. self.keyboardColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
  266. self.keyboardColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
  267. self.keyboardColorBtn1.layer.cornerRadius = self.keyboardColorBtn2.layer.cornerRadius = self.keyboardColorBtn3.layer.cornerRadius = self.keyboardColorBtn4.layer.cornerRadius = 10.;
  268. self.keyboardColorBtn1.layer.masksToBounds = self.keyboardColorBtn2.layer.masksToBounds = self.keyboardColorBtn3.layer.masksToBounds = self.keyboardColorBtn4.layer.masksToBounds = YES;
  269. self.keyboardColorSelView.wantsLayer = YES;
  270. self.keyboardColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
  271. self.keyboardColorSelView.layer.borderWidth = 1.;
  272. self.keyboardColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
  273. self.keyboardColorSelView.layer.cornerRadius = 4.;
  274. self.keyboardColorSelView.layer.masksToBounds = YES;
  275. [self colorTextButtonAction:self.keyboardColorBtn1];
  276. //Draw
  277. self.drawView.delegate = self;
  278. self.drawView.wantsLayer = YES;
  279. self.drawView.strokeRadius = [self.drawSizeDefaultValue floatValue];
  280. self.drawView.layer.cornerRadius = 4.;
  281. self.drawView.layer.masksToBounds = YES;
  282. self.drawView.layer.borderWidth = 1.;
  283. self.drawView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  284. self.drawView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  285. self.drawColorBtn1.wantsLayer = self.drawColorBtn2.wantsLayer = self.drawColorBtn3.wantsLayer = self.drawColorBtn4.wantsLayer = YES;
  286. self.drawColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
  287. self.drawColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
  288. self.drawColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
  289. self.drawColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
  290. self.drawColorBtn1.layer.cornerRadius = self.drawColorBtn2.layer.cornerRadius = self.drawColorBtn3.layer.cornerRadius = self.drawColorBtn4.layer.cornerRadius = 10.;
  291. self.drawColorBtn1.layer.masksToBounds = self.drawColorBtn2.layer.masksToBounds = self.drawColorBtn3.layer.masksToBounds = self.drawColorBtn4.layer.masksToBounds = YES;
  292. self.drawColorSelView.wantsLayer = YES;
  293. self.drawColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
  294. self.drawColorSelView.layer.borderWidth = 1.;
  295. self.drawColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
  296. self.drawColorSelView.layer.cornerRadius = 4.;
  297. self.drawColorSelView.layer.masksToBounds = YES;
  298. [self drawColorBtnClicked:self.drawColorBtn1];
  299. for (NSString *pxSize in @[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"]) {
  300. NSDictionary *attrited = @{NSFontAttributeName:[NSFont systemFontOfSize:14]};
  301. NSAttributedString *string = [[NSAttributedString alloc] initWithString:pxSize attributes:attrited];
  302. NSMenuItem *item = [[NSMenuItem alloc] init];
  303. item.attributedTitle = string;
  304. [self.drawSizeBox.menu addItem:item];
  305. }
  306. [self.drawSizeBox selectItem:[self.drawSizeBox itemAtIndex:1]];
  307. [self.drawSizeBox setTitle:@"1.0 pt"];
  308. //Picture
  309. self.pictureView.wantsLayer = YES;
  310. self.pictureView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  311. self.pictureBackView.wantsLayer = YES;
  312. self.pictureBackView.layer.cornerRadius = 4.;
  313. self.pictureBackView.layer.masksToBounds = YES;
  314. self.pictureBackView.layer.borderWidth = 1.;
  315. self.pictureBackView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  316. self.pictureBackView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  317. self.pictureBackView.changeSignatureImageCallback = ^(BOOL isTure) {
  318. if (isTure) {
  319. weakSelf.applyButtonVC.enabled = YES;
  320. } else {
  321. weakSelf.applyButtonVC.enabled = NO;
  322. }
  323. if (weakSelf.pictureBackView.signatureImage) {
  324. weakSelf.clearButton.hidden = NO;
  325. weakSelf.clearButton.title = NSLocalizedString(@"Reselect", nil);
  326. } else {
  327. weakSelf.clearButton.hidden = YES;
  328. }
  329. };
  330. [self.trackpadLabel setHidden:YES];
  331. self.drawTipView.hidden = YES;
  332. self.keyboardView.delegate = self;
  333. self.drawView.changeDrawCallback = ^(BOOL isTure) {
  334. if (isTure) {
  335. weakSelf.applyButtonVC.enabled = YES;
  336. } else {
  337. weakSelf.applyButtonVC.enabled = NO;
  338. }
  339. };
  340. self.drawView.touchEndCallback = ^(BOOL isClear) {
  341. if (isClear) {
  342. weakSelf.clearButton.hidden = YES;
  343. } else {
  344. weakSelf.clearButton.hidden = NO;
  345. weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
  346. }
  347. };
  348. [self inputButton_Click:nil];
  349. self.pictureHelpButton.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
  350. self.pictureHelpButton.toolTip = @"Remove white background from images";
  351. self.pictureHelpButton.action = @selector(showHelpTip:);
  352. self.pictureHelpButton.coverAction = ^(KMCoverButton * _Nonnull button, KMCoverAction action) {
  353. if (action == KMCoverActionEnter) {
  354. button.image = [NSImage imageNamed:@"KMImageNameHelpHover"];
  355. // [weakSelf showHelpTip:button];
  356. } else if (action == KMCoverActionExit) {
  357. button.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
  358. // [weakSelf dismissHelpTip];
  359. }
  360. };
  361. [self localizedString];
  362. [self setupUI];
  363. }
  364. - (void)setupUI {
  365. NSString *fontName = @"SFProText-Regular";
  366. self.titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:16];
  367. self.titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  368. self.signTypeView.wantsLayer = YES;
  369. self.signTypeView.layer.backgroundColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  370. self.signTypeView.layer.cornerRadius = 4.;
  371. self.signTypeView.layer.masksToBounds = YES;
  372. self.signTypeBackView.wantsLayer = YES;
  373. self.signTypeBackView.layer.cornerRadius = 2.;
  374. self.signTypeBackView.layer.masksToBounds = YES;
  375. self.signTypeBackView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  376. for (NSButton *button in @[self.inputButton, self.drawingButton, self.pictureButton]) {
  377. [button setTitleColorWithColor:[NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f] font:nil];
  378. button.font = [NSFont fontWithName:fontName size:12];
  379. }
  380. // Input
  381. self.fontVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
  382. [self.fontBox.superview addSubview:self.fontVC.view];
  383. [self.fontVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  384. make.left.equalTo(self.fontBox);
  385. make.centerY.equalTo(self.fontBox);
  386. make.size.mas_equalTo(NSMakeSize(200, 32));
  387. }];
  388. self.fontBox.hidden = YES;
  389. [self.fontVC addItemsWithObjectValues:self.fontValues];
  390. self.fontVC.stringValue = self.fontDefaultValue;
  391. self.fontVC.delete = self;
  392. // Drawing
  393. self.drawSizeVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
  394. [self.drawSizeBox.superview addSubview:self.drawSizeVC.view];
  395. [self.drawSizeVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  396. make.left.equalTo(self.drawSizeBox);
  397. make.centerY.equalTo(self.drawSizeBox);
  398. make.size.mas_equalTo(NSMakeSize(85, 32));
  399. }];
  400. self.drawSizeBox.hidden = YES;
  401. self.drawSizeVC.delete = self;
  402. NSMutableArray *drawSizes = [NSMutableArray array];
  403. for (NSString *value in self.drawSizeValues) {
  404. [drawSizes addObject:[NSString stringWithFormat:@"%@ pt", value]];
  405. }
  406. [self.drawSizeVC addItemsWithObjectValues:drawSizes.copy];
  407. self.drawSizeVC.stringValue = [NSString stringWithFormat:@"%@ pt", self.drawSizeDefaultValue];
  408. self.trackpadButton.title = NSLocalizedString(@"Trackpad", nil);
  409. self.trackpadButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
  410. [self.trackpadButton.superview addSubview:self.trackpadButtonVC.view];
  411. self.trackpadButtonVC.stringValue = NSLocalizedString(@"Trackpad", nil);
  412. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  413. [self.trackpadButtonVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
  414. self.trackpadButtonVC.target = self;
  415. self.trackpadButtonVC.action = @selector(trackpadButton_Click:);
  416. [self.trackpadButtonVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  417. make.left.equalTo(self.trackpadButton);
  418. make.centerY.equalTo(self.drawSizeVC.view);
  419. make.width.mas_equalTo(120);
  420. make.height.mas_equalTo(22);
  421. }];
  422. self.trackpadButton.hidden = YES;
  423. self.drawTipView.wantsLayer = YES;
  424. self.drawTipView.layer.backgroundColor = [NSColor colorWithRed:189/255.f green:223/255.f blue:253/255.f alpha:1.f].CGColor;
  425. self.drawTipLabel.stringValue = NSLocalizedString(@"Press any key to disable the touchpad", nil);
  426. self.drawTipLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  427. self.drawTipLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  428. // Picture
  429. self.pictureBackView.emptyTipLbl.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1];
  430. self.pictureBackView.emptyTipLbl.font = [NSFont fontWithName:fontName size:14];
  431. self.pictureClearBackBtn.title = NSLocalizedString(@"Clear background", nil);
  432. self.pictureClearBackBtnVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
  433. [self.pictureClearBackBtn.superview addSubview:self.pictureClearBackBtnVC.view];
  434. self.pictureClearBackBtnVC.stringValue = NSLocalizedString(@"Clear background", nil);
  435. self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
  436. [self.pictureClearBackBtnVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
  437. self.pictureClearBackBtnVC.target = self;
  438. self.pictureClearBackBtnVC.action = @selector(pictureClearBackBtnAction:);
  439. self.pictureClearBackBtn.hidden = YES;
  440. [self.pictureClearBackBtnVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  441. make.edges.equalTo(self.pictureClearBackBtn);
  442. }];
  443. }
  444. - (void)setType:(kKMPDFSignatureType)type {
  445. _type = type;
  446. CGRect rect = self.signTypeBackView.frame;
  447. if (_type == kKMPDFSignatureType_Text) {
  448. rect.origin.x = 1;
  449. } else if (_type == kKMPDFSignatureType_Ink) {
  450. rect.origin.x = 2 + 75;
  451. } else if (_type == kKMPDFSignatureType_Image) {
  452. rect.origin.x = 2 + 75*2;
  453. }
  454. rect.origin.y = (CGRectGetHeight(self.signTypeBackView.superview.frame) - CGRectGetHeight(self.signTypeBackView.frame))/2.;
  455. self.signTypeBackView.frame = rect;
  456. self.clearButton.hidden = YES;
  457. if (_type == kKMPDFSignatureType_Text) {
  458. } else if (_type == kKMPDFSignatureType_Ink) {
  459. } else if (_type == kKMPDFSignatureType_Image) {
  460. if (self.pictureBackView.signatureImage) {
  461. self.clearButton.title = NSLocalizedString(@"Reselect", nil);
  462. self.clearButton.hidden = NO;
  463. }
  464. }
  465. }
  466. #pragma mark - mouse
  467. - (void)mouseDown:(NSEvent *)event {
  468. [self dismissHelpTip];
  469. }
  470. #pragma mark - Private Methods
  471. -(void)localizedString
  472. {
  473. self.titleLabel.stringValue = NSLocalizedString(@"Create Signature", "");
  474. [self.trackpadButton setTitle:NSLocalizedString(@"Trackpad", nil)];
  475. [self.clearButton setTitle:NSLocalizedString(@"Clear", nil)];
  476. [self.trackpadLabel setStringValue:NSLocalizedString(@"Press \"esc\" to disable the Trackpad.", nil)];
  477. NSArray *seletorFonts = @[@"Mistral", @"Bradley Hand", @"Brush Script MT", @"SignPainter", @"Edwardian Script ITC", @"American Typewriter",@"Baoli SC",@"Snell Roundhand", @"Apple Chancery", @"Monotype Corsiva"];
  478. NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  479. for (NSString *fontName in fonts) {
  480. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
  481. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  482. NSMenuItem *item = [[NSMenuItem alloc] init];
  483. item.attributedTitle = string;
  484. [self.fontBox.menu addItem:item];
  485. }
  486. NSString * fontName = nil;
  487. if (!recentlyFonts) {
  488. recentlyFonts = [[NSMutableArray alloc] init];
  489. }
  490. if (recentlyFonts.count < 1) {
  491. for (NSString *name in seletorFonts) {
  492. if ([fonts containsObject:name]) {
  493. fontName = name;
  494. break;
  495. }
  496. }
  497. if (fontName) {
  498. [recentlyFonts addObject:fontName];
  499. }
  500. } else {
  501. fontName = recentlyFonts.firstObject;
  502. }
  503. // if ([fonts containsObject:fontName]) {
  504. // self.keyboardView.fontName = fontName;
  505. // [self.fontBox setTitle:fontName];
  506. // } else {
  507. // self.keyboardView.fontName = fonts.firstObject;
  508. // [self.fontBox setTitle:fonts.firstObject];
  509. // }
  510. self.keyboardView.fontName = self.fontDefaultValue;
  511. for (NSInteger i = 0; i<recentlyFonts.count; i++) {
  512. NSString *fontName = recentlyFonts[i];
  513. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
  514. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  515. NSMenuItem *item = [[NSMenuItem alloc] init];
  516. item.attributedTitle = string;
  517. [self.fontBox.menu insertItem:item atIndex:1 + i];
  518. }
  519. NSMenuItem *sep = [NSMenuItem separatorItem];
  520. [self.fontBox.menu insertItem:sep atIndex:(recentlyFonts.count)+1];
  521. self.selectItem = [self.fontBox.menu itemAtIndex:1];
  522. self.selectItem.state = NSControlStateValueOn;
  523. [self.inputButton setTitle:NSLocalizedString(@"Keyboard", nil)];
  524. [self.drawingButton setTitle:NSLocalizedString(@"Trackpad", nil)];
  525. [self.pictureButton setTitle:NSLocalizedString(@"Image", nil)];
  526. }
  527. - (void)showHelpTip:(NSButton *)sender {
  528. if (self.popover) {
  529. [self dismissHelpTip];
  530. return;
  531. }
  532. NSPopover *pop = [[NSPopover alloc] init];
  533. self.popover = pop;
  534. KMSignatureHelpViewController *controller = [[KMSignatureHelpViewController alloc] init];
  535. pop.contentViewController = controller;
  536. controller.tipString = NSLocalizedString(@"Remove white background from images", nil);
  537. [pop setValue:@YES forKey:@"shouldHideAnchor"];
  538. [pop showRelativeToRect:NSMakeRect(0, -8, NSWidth(sender.bounds), NSHeight(sender.bounds)) ofView:sender preferredEdge:NSRectEdgeMaxY];
  539. }
  540. - (void)dismissHelpTip {
  541. [self.popover close];
  542. self.popover = nil;
  543. }
  544. #pragma mark Button Mehtods
  545. - (IBAction)inputButton_Click:(id)sender {
  546. self.contentBox.contentView = self.inputView;
  547. self.type = kKMPDFSignatureType_Text;
  548. }
  549. - (IBAction)drawingButton_Click:(id)sender {
  550. self.contentBox.contentView = self.drawingView;
  551. self.type = kKMPDFSignatureType_Ink;
  552. }
  553. - (IBAction)pictureButton_Click:(id)sender {
  554. self.contentBox.contentView = self.pictureView;
  555. self.type = kKMPDFSignatureType_Image;
  556. }
  557. - (void)clearButton_Click:(id)sender
  558. {
  559. if (kKMPDFSignatureType_Image == self.type) {
  560. [self.pictureBackView reSelectImage];
  561. } else if (kKMPDFSignatureType_Ink == self.type) {
  562. [self.drawView clearImage];
  563. }else if (kKMPDFSignatureType_Text == self.type) {
  564. [self.keyboardView clearImage];
  565. }
  566. self.applyButtonVC.enabled = NO;
  567. }
  568. - (void)applyButton_Click:(id)sender
  569. {
  570. KMSignature *signature = [[KMSignature alloc] init];
  571. if (kKMPDFSignatureType_Text == self.type) {
  572. NSImage *image = [self.keyboardView signatureImage];
  573. if (!image) {
  574. NSAlert *alert = [[NSAlert alloc] init];
  575. [alert setAlertStyle:NSAlertStyleCritical];
  576. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  577. [alert runModal];
  578. return;
  579. }
  580. signature.pathsImage = image;
  581. signature.signatureType = kKMPDFSignatureType_Text;
  582. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  583. [signatureManager loadAllSignatureList];
  584. [signatureManager addSignature:signature];
  585. [signatureManager saveSingaturesToFile];
  586. } else if(kKMPDFSignatureType_Image == self.type) {
  587. NSImage *image = [self.pictureBackView signatureImage];
  588. if (!image) {
  589. NSAlert *alert = [[NSAlert alloc] init];
  590. [alert setAlertStyle:NSAlertStyleCritical];
  591. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  592. [alert runModal];
  593. return;
  594. }
  595. signature.pathsImage = image;
  596. signature.signatureType = kKMPDFSignatureType_Image;
  597. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  598. [signatureManager loadAllSignatureList];
  599. [signatureManager addSignature:signature];
  600. [signatureManager saveSingaturesToFile];
  601. } else {
  602. NSImage *image = [self.drawView signatureImage];
  603. if (!image) {
  604. NSAlert *alert = [[NSAlert alloc] init];
  605. [alert setAlertStyle:NSAlertStyleCritical];
  606. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  607. [alert runModal];
  608. return;
  609. }
  610. [signature addPath:self.drawView.drawBezierPath];
  611. signature.signatureType = kKMPDFSignatureType_Ink;
  612. signature.signatureColor = self.drawView.drawColor;
  613. signature.pathsImage = image;
  614. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  615. [signatureManager loadAllSignatureList];
  616. [signatureManager addSignature:signature];
  617. [signatureManager saveSingaturesToFile];
  618. }
  619. self.selectedSignature = signature;
  620. [self dismissSheet:nil];
  621. }
  622. - (IBAction)trackpadButton_Click:(id)sender
  623. {
  624. if (self.trackpadButtonVC.state == KMDesignTokenStateChecked) {
  625. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  626. self.trackpadLabel.hidden = YES;
  627. self.drawTipView.hidden = YES;
  628. self.drawView.isAcceptsTouch = NO;
  629. } else {
  630. self.trackpadButtonVC.state = KMDesignTokenStateChecked;
  631. self.trackpadLabel.hidden = YES;
  632. self.drawTipView.hidden = NO;
  633. self.drawView.isAcceptsTouch = YES;
  634. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  635. self.drawTipView.hidden = YES;
  636. });
  637. }
  638. }
  639. - (IBAction)boxItemClicked_Font:(id)sender
  640. {
  641. NSString * name = self.fontBox.selectedItem.title;
  642. self.fontBox.title = name;
  643. self.keyboardView.fontName = name;
  644. if ([recentlyFonts containsObject:name]) {
  645. NSInteger index = [recentlyFonts indexOfObject:name];
  646. [recentlyFonts removeObject:name];
  647. [self.fontBox.menu removeItemAtIndex:index +1];
  648. }
  649. if (recentlyFonts.count >0) {
  650. [recentlyFonts insertObject:name atIndex:0];
  651. } else {
  652. [recentlyFonts addObject:name];
  653. }
  654. if (recentlyFonts.count >5) {
  655. [recentlyFonts removeLastObject];
  656. [self.fontBox.menu removeItemAtIndex:recentlyFonts.count];
  657. }
  658. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:name size:12.0]};
  659. NSAttributedString *string = [[NSAttributedString alloc] initWithString:name attributes:attrited];
  660. NSMenuItem *item = [[NSMenuItem alloc] init];
  661. item.attributedTitle = string;
  662. [self.fontBox.menu insertItem:item atIndex:1];
  663. self.selectItem.state = NSControlStateValueOff;
  664. self.selectItem = [self.fontBox.menu itemAtIndex:1];
  665. self.selectItem.state = NSControlStateValueOn;
  666. }
  667. - (IBAction)colorTextButtonAction:(id)sender {
  668. if ([sender isEqual:self.keyboardColorBtn1] ||
  669. [sender isEqual:self.keyboardColorBtn2] ||
  670. [sender isEqual:self.keyboardColorBtn3] ||
  671. [sender isEqual:self.keyboardColorBtn4]) {
  672. self.keyboardView.keyboardColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
  673. CGRect rect = self.keyboardView.frame;
  674. rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
  675. rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
  676. rect.size.width = rect.size.height = 32;
  677. self.keyboardColorSelView.frame = rect;
  678. } else {
  679. [[NSColorPanel sharedColorPanel] setTarget:self];
  680. [[NSColorPanel sharedColorPanel] setAction:@selector(keyboardColorPanelColorDidChange:)];
  681. [[NSColorPanel sharedColorPanel] orderFront:nil];
  682. }
  683. }
  684. - (IBAction)drawColorBtnClicked:(NSButton *)sender {
  685. if ([sender isEqual:self.drawColorBtn1] ||
  686. [sender isEqual:self.drawColorBtn2] ||
  687. [sender isEqual:self.drawColorBtn3] ||
  688. [sender isEqual:self.drawColorBtn4]) {
  689. self.drawView.drawColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
  690. CGRect rect = self.drawColorSelView.frame;
  691. rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
  692. rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
  693. rect.size.width = rect.size.height = 32;
  694. self.drawColorSelView.frame = rect;
  695. }
  696. }
  697. - (IBAction)drawSizeBtnClicked:(NSPopUpButton *)sender {
  698. NSString * name = self.drawSizeBox.selectedItem.title;
  699. self.drawSizeBox.title = name;
  700. self.drawView.strokeRadius = [[@[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"] objectAtIndex:(self.drawSizeBox.indexOfSelectedItem -1)] floatValue];
  701. }
  702. //Picture
  703. - (IBAction)pictureClearBackBtnAction:(NSButton *)sender {
  704. BOOL clearBack = YES;
  705. if (self.pictureClearBackBtnVC.state == KMDesignTokenStateChecked) {
  706. self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
  707. clearBack = NO;
  708. } else {
  709. self.pictureClearBackBtnVC.state = KMDesignTokenStateChecked;
  710. clearBack = YES;
  711. }
  712. self.pictureBackView.clearBackground = clearBack;
  713. }
  714. - (void)keyboardColorPanelColorDidChange:(id)sender
  715. {
  716. self.textColorButton.layer.borderColor= [NSColor clearColor].CGColor;
  717. CGFloat red,green,blue,alpha;
  718. NSColor *color = [NSColorPanel sharedColorPanel].color ? : [NSColor clearColor];
  719. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  720. self.keyboardView.keyboardColor = color;
  721. self.textColorButton.layer.borderColor = [NSColor colorWithRed:33.0/255.0 green:124.0/255.0 blue:234.0/255.0 alpha:1.0].CGColor;
  722. }
  723. #pragma mark KMDrawViewDelegate Methods
  724. - (void)drawViewDidFinishTouchMode:(KMDrawView *)view
  725. {
  726. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  727. [self.trackpadLabel setHidden:YES];
  728. // [NSAnimationContext beginGrouping];
  729. // [NSAnimationContext currentContext].duration = 1.5;
  730. // [NSAnimationContext currentContext].timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  731. // self.scrollView.animator.frame = originFrame;
  732. self.drawTipView.animator.hidden = YES;
  733. // [NSAnimationContext endGrouping];
  734. }
  735. #pragma mark KMChangeSignatureTextDelegate Methods
  736. - (void)changeSignatureText:(BOOL)isTure {
  737. self.applyButtonVC.enabled = isTure;
  738. }
  739. #pragma mark Show Methods
  740. - (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
  741. {
  742. if (contextInfo != NULL && self.handler) {
  743. self.handler(self.selectedSignature);
  744. }
  745. }
  746. - (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void (^)(KMSignature *signature))handler;
  747. {
  748. windowController_signature = self;
  749. [NSApp beginSheet:[self window]
  750. modalForWindow:window
  751. modalDelegate:self
  752. didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
  753. contextInfo:(__bridge void * _Null_unspecified)(handler ? handler : NULL)];
  754. self.handler = handler;
  755. }
  756. - (void)dismissSheet:(id)sender {
  757. windowController_signature = nil;
  758. if (sender) {
  759. [NSApp endSheet:[self window] returnCode:0];
  760. } else {
  761. [NSApp endSheet:[self window] returnCode:1];
  762. }
  763. [[self window] orderOut:self];
  764. }
  765. #pragma mark -
  766. #pragma mark - KMSelectPopButtonDelegate
  767. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  768. if ([obj isEqual:self.fontVC]) {
  769. NSInteger index = self.fontVC.indexOfSelectedItem;
  770. if (index < 0) {
  771. index = 0;
  772. }
  773. self.keyboardView.fontName = self.fontVC.items[index];
  774. } else if ([obj isEqual:self.drawSizeVC]) {
  775. NSInteger index = self.drawSizeVC.indexOfSelectedItem;
  776. if (index < 0) {
  777. index = 0;
  778. }
  779. self.drawView.strokeRadius = [self.drawSizeValues[index] floatValue];
  780. }
  781. }
  782. #pragma mark NSTabViewDelegate Methods
  783. - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(nullable NSTabViewItem *)tabViewItem
  784. {
  785. return YES;
  786. }
  787. - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
  788. {
  789. BOOL isImage = NO;
  790. if ([tabView indexOfTabViewItem:tabViewItem] == 0) {
  791. self.type = kKMPDFSignatureType_Text;
  792. if ([self.keyboardView signatureImage]) {
  793. isImage = YES;
  794. }
  795. } else if ([tabView indexOfTabViewItem:tabViewItem] == 1) {
  796. self.type = kKMPDFSignatureType_Ink;
  797. if ([self.drawView signatureImage]) {
  798. isImage = YES;
  799. }
  800. } else if ([tabView indexOfTabViewItem:tabViewItem] == 2) {
  801. self.type = kKMPDFSignatureType_Image;
  802. if ([self.pictureBackView signatureImage]) {
  803. isImage = YES;
  804. }
  805. }
  806. if (isImage) {
  807. self.applyButtonVC.enabled = YES;
  808. } else {
  809. self.applyButtonVC.enabled = NO;
  810. }
  811. }
  812. @end