KMSignatureWindowController.m 39 KB

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