KMSignatureWindowController.m 39 KB

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