KMAnnotationPropertiesViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // KMAnnotationPropertiesViewController.m
  3. // SignFlow
  4. //
  5. // Created by wanjun on 2021/6/15.
  6. //
  7. #import "KMAnnotationPropertiesViewController.h"
  8. //#import "NSString_SKExtensions.h"
  9. #import <PDF_Master-Swift.h>
  10. #import "KMSignatureAnnotationViewController.h"
  11. #import "CSelfSignAnnotation.h"
  12. #import "CSelfSignAnnotationFreeText.h"
  13. #define KMFromContentButtonHeightFloat 32
  14. @interface KMClipView : NSClipView
  15. @end
  16. @implementation KMClipView
  17. - (BOOL)isFlipped {
  18. return YES;
  19. }
  20. @end
  21. @interface KMAnnotationPropertiesViewController ()
  22. @property (assign) IBOutlet NSBox *propertiesBox;
  23. @property (nonatomic,assign) IBOutlet NSView *gradientView;
  24. @property (weak) IBOutlet NSImageView *emptyImageView;
  25. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  26. @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
  27. @property (nonatomic,assign) IBOutlet NSView *emptyView;
  28. @property (nonatomic,retain) NSViewController *contentViewController;
  29. @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
  30. @end
  31. @implementation KMAnnotationPropertiesViewController
  32. #pragma mark - View Methods
  33. - (void)loadView {
  34. [super loadView];
  35. self.view.wantsLayer = YES;
  36. self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
  37. self.view.layer.shadowColor = [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.15].CGColor;
  38. self.view.layer.shadowOffset = NSMakeSize(0, 0);
  39. self.view.layer.shadowRadius = 4;
  40. self.emptyImageView.image = [NSImage imageNamed:@"KMImageNameMarkupEmpty"];
  41. self.subTitleLabel.stringValue = NSLocalizedString(@"Show/Hide Annotation Properties Panel", nil);
  42. NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
  43. ps.lineSpacing = 10;
  44. ps.alignment = NSTextAlignmentCenter;
  45. self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:self.subTitleLabel.stringValue attributes:@{
  46. NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
  47. NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
  48. NSParagraphStyleAttributeName : ps}];
  49. self.subTitleLabel.textColor = [NSColor grayColor];
  50. self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
  51. self.titleLabel.textColor = [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
  52. }
  53. #pragma mark - Setter Methods
  54. -(void)setAnnotations:(NSArray *)annotations
  55. {
  56. if (_annotations != annotations) {
  57. _annotations = annotations;
  58. }
  59. CPDFAnnotation *annotation = _annotations.firstObject;
  60. if (self.contentViewController) {
  61. [self.contentViewController.view removeFromSuperview];
  62. self.contentViewController = nil;
  63. }
  64. if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
  65. return;
  66. }
  67. if (_annotations.count > 1) {
  68. [self selectAnnotations:_annotations];
  69. return;
  70. }
  71. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
  72. self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
  73. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  74. CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
  75. if (buttonWidget.controlType == 1) {
  76. self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
  77. } else if (buttonWidget.controlType == 2) {
  78. self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
  79. } else if (buttonWidget.controlType == 0) {
  80. self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
  81. }
  82. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  83. CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
  84. if (choiceWidget.isListChoice) {
  85. self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
  86. } else {
  87. self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
  88. }
  89. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  90. KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
  91. CAnnotationType type = newAnnotation.annotationType;
  92. NSString *returnString = @"";
  93. if (type == CAnnotationTypeSignFalse) {
  94. returnString = NSLocalizedString(@"X", nil);
  95. } else if (type == CAnnotationTypeSignTure) {
  96. returnString = NSLocalizedString(@"Check mark", nil);
  97. } else if (type == CAnnotationTypeSignCircle) {
  98. returnString = NSLocalizedString(@"Circle", nil);
  99. } else if (type == CAnnotationTypeSignLine) {
  100. returnString = NSLocalizedString(@"Line", nil);
  101. } else if (type == CAnnotationTypeSignDot) {
  102. returnString = NSLocalizedString(@"Dot", nil);
  103. } else if (type == CAnnotationTypeSignText) {
  104. returnString = NSLocalizedString(@"Text", nil);
  105. }
  106. self.titleLabel.stringValue = returnString;
  107. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  108. self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
  109. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  110. if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  111. KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
  112. if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
  113. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  114. } else {
  115. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  116. }
  117. } else {
  118. self.titleLabel.stringValue = [annotation type].typeName;
  119. }
  120. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
  121. [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  122. self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
  123. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  124. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  125. if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
  126. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  127. } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
  128. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  129. } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
  130. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  131. } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
  132. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  133. } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
  134. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  135. } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
  136. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  137. } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
  138. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  139. }
  140. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  141. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  142. } else {
  143. self.titleLabel.stringValue = [annotation type].typeName;
  144. }
  145. self.titleViewHeightConstraint.constant = 40;
  146. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  147. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  148. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  149. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]){
  150. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  151. vc.pdfView = self.pdfView;
  152. vc.annotationModel = annotationModel;
  153. self.propertiesBox.contentView = vc.view;
  154. self.contentViewController = vc;
  155. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  156. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  157. vc.pdfView = self.pdfView;
  158. vc.annotationModel = annotationModel;
  159. self.propertiesBox.contentView = vc.view;
  160. self.contentViewController = vc;
  161. vc.callback = ^(CAnnotationType type) {
  162. if (type == CAnnotationTypeSignFalse) {
  163. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  164. } else if (type == CAnnotationTypeSignTure) {
  165. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  166. } else if (type == CAnnotationTypeSignCircle) {
  167. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  168. } else if (type == CAnnotationTypeSignLine) {
  169. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  170. } else if (type == CAnnotationTypeSignDot) {
  171. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  172. }
  173. };
  174. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  175. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  176. NSString *contents = nil;
  177. if ([linkAnnotation URL]) {
  178. contents = [linkAnnotation URL];
  179. if (contents) {
  180. contents = [NSString stringWithFormat:@"1%@", contents];
  181. } else {
  182. contents = @"";
  183. }
  184. } else {
  185. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  186. }
  187. KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
  188. vc.annotations = self.annotations;
  189. vc.pdfDocument = self.pdfView.document;
  190. vc.pdfview = self.pdfView;
  191. vc.view.frame = [self viewControllerRect];
  192. [self.view addSubview:vc.view];
  193. self.contentViewController = vc;
  194. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  195. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  196. if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
  197. newAnnotation.annotationType == CAnnotationTypeSignTure ||
  198. newAnnotation.annotationType == CAnnotationTypeSignCircle ||
  199. newAnnotation.annotationType == CAnnotationTypeSignLine ||
  200. newAnnotation.annotationType == CAnnotationTypeSignDot) {
  201. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  202. vc.pdfView = self.pdfView;
  203. vc.annotationModel = annotationModel;
  204. self.propertiesBox.contentView = vc.view;
  205. self.contentViewController = vc;
  206. vc.callBack = ^(CAnnotationType type) {
  207. if (type == CAnnotationTypeSignFalse) {
  208. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  209. } else if (type == CAnnotationTypeSignTure) {
  210. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  211. } else if (type == CAnnotationTypeSignCircle) {
  212. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  213. } else if (type == CAnnotationTypeSignLine) {
  214. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  215. } else if (type == CAnnotationTypeSignDot) {
  216. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  217. }
  218. };
  219. } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
  220. newAnnotation.annotationType == CAnnotationTypeSignDate) {
  221. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  222. vc.pdfView = self.pdfView;
  223. vc.annotationModel = annotationModel;
  224. self.propertiesBox.contentView = vc.view;
  225. self.contentViewController = vc;
  226. }
  227. } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  228. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
  229. if (newAnnotation.subType == CAnnotationTypeSignText ||
  230. newAnnotation.subType == CAnnotationTypeSignDate) {
  231. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  232. vc.pdfView = self.pdfView;
  233. vc.annotationModel = annotationModel;
  234. self.propertiesBox.contentView = vc.view;
  235. self.contentViewController = vc;
  236. }
  237. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
  238. [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  239. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  240. vc.pdfView = self.pdfView;
  241. vc.annotationModel = annotationModel;
  242. self.propertiesBox.contentView = vc.view;
  243. self.contentViewController = vc;
  244. } else {
  245. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  246. vc.pdfView = self.pdfView;
  247. vc.annotationModel = annotationModel;
  248. self.propertiesBox.contentView = vc.view;
  249. self.contentViewController = vc;
  250. }
  251. }
  252. - (void)selectAnnotations:(NSArray *)annotations {
  253. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  254. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  255. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  256. annotationMode = CAnnotationTypeHighlight;
  257. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  258. annotationMode = CAnnotationTypeInk;
  259. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  260. annotationMode = CAnnotationTypeAnchored;
  261. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  262. annotationMode = CAnnotationTypeSquare;
  263. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  264. annotationMode = CAnnotationTypeCircle;
  265. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  266. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  267. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  268. annotationMode = CAnnotationTypeArrow;
  269. } else {
  270. annotationMode = CAnnotationTypeLine;
  271. }
  272. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  273. annotationMode = CAnnotationTypeLink;
  274. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  275. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  276. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  277. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  278. annotationMode = CAnnotationTypeSignFalse;
  279. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  280. annotationMode = CAnnotationTypeSignTure;
  281. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  282. annotationMode = CAnnotationTypeSignCircle;
  283. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  284. annotationMode = CAnnotationTypeSignLine;
  285. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  286. annotationMode = CAnnotationTypeSignDot;
  287. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  288. annotationMode = CAnnotationTypeSignDot;
  289. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  290. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  291. if (newAnnotation.subType == CAnnotationTypeSignText)
  292. annotationMode = CAnnotationTypeSignText;
  293. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  294. annotationMode = CAnnotationTypeSignDate;
  295. } else {
  296. annotationMode = CAnnotationTypeStamp;
  297. }
  298. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  299. annotationMode = CAnnotationTypeSignature;
  300. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  301. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  302. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  303. if (newAnnotation.subType == CAnnotationTypeSignText)
  304. annotationMode = CAnnotationTypeSignText;
  305. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  306. annotationMode = CAnnotationTypeSignDate;
  307. } else {
  308. annotationMode = CAnnotationTypeFreeText;
  309. }
  310. }
  311. self.annotationMode = annotationMode;
  312. }
  313. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  314. _annotationMode = annotationMode;
  315. if (self.contentViewController) {
  316. [self.contentViewController.view removeFromSuperview];
  317. self.contentViewController = nil;
  318. }
  319. NSString *title = @"";
  320. if (annotationMode == CAnnotationTypeFreeText)
  321. title = NSLocalizedString(@"Text", @"Description for export");
  322. else if (annotationMode == CAnnotationTypeCircle)
  323. title = NSLocalizedString(@"Circle", @"Description for export");
  324. else if (annotationMode == CAnnotationTypeSquare)
  325. title = NSLocalizedString(@"Shape", @"Description for export");
  326. else if (annotationMode == CAnnotationTypeHighlight) {
  327. title = NSLocalizedString(@"Highlight", @"Description for export");
  328. if (_annotations.count > 1)
  329. title = NSLocalizedString(@"General", @"Description for export");
  330. }
  331. else if (annotationMode == CAnnotationTypeUnderline) {
  332. title = NSLocalizedString(@"Underline", @"Description for export");
  333. if (_annotations.count > 1)
  334. title = NSLocalizedString(@"General", @"Description for export");
  335. }
  336. else if (annotationMode == CAnnotationTypeStrikeOut)
  337. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  338. else if (annotationMode == CAnnotationTypeLine)
  339. title = NSLocalizedString(@"Line", @"Description for export");
  340. else if (annotationMode == CAnnotationTypeArrow)
  341. title = NSLocalizedString(@"Arrow", @"Description for export");
  342. else if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser)
  343. title = NSLocalizedString(@"Pen", @"Description for export");
  344. else if (annotationMode == CAnnotationTypeAnchored)
  345. title = NSLocalizedString(@"Note", @"Description for export");
  346. else if (annotationMode == CAnnotationTypeLink)
  347. title = NSLocalizedString(@"Link", @"Description for export");
  348. else if (annotationMode == CAnnotationTypeTextField)
  349. title = NSLocalizedString(@"Text Field", @"Description for export");
  350. else if (annotationMode == CAnnotationTypeCheckBox)
  351. title = NSLocalizedString(@"Check Box", @"Description for export");
  352. else if (annotationMode == CAnnotationTypeListMenu)
  353. title = NSLocalizedString(@"List Box", @"Description for export");
  354. else if (annotationMode == CAnnotationTypeComboBox)
  355. title = NSLocalizedString(@"Combo Box", @"Description for export");
  356. else if (annotationMode == CAnnotationTypeRadioButton)
  357. title = NSLocalizedString(@"Radio Button", @"Description for export");
  358. else if (annotationMode == CAnnotationTypeActionButton)
  359. title = NSLocalizedString(@"Button", @"Description for export");
  360. else if (annotationMode == CAnnotationTypeSignature)
  361. title = NSLocalizedString(@"Sample", @"Description for export");
  362. else if (annotationMode == CAnnotationTypeSignDot)
  363. title = NSLocalizedString(@"Dot", @"Description for export");
  364. else if (annotationMode == CAnnotationTypeSignLine)
  365. title = NSLocalizedString(@"Line", @"Description for export");
  366. else if (annotationMode == CAnnotationTypeSignCircle)
  367. title = NSLocalizedString(@"Rectangle", @"Description for export");
  368. else if (annotationMode == CAnnotationTypeSignFalse)
  369. title = NSLocalizedString(@"Fork", nil);
  370. else if (annotationMode == CAnnotationTypeSignTure)
  371. title = NSLocalizedString(@"Hook", nil);
  372. else if (annotationMode == CAnnotationTypeSignText)
  373. title = NSLocalizedString(@"Text", nil);
  374. else if (annotationMode == CAnnotationTypeSignDate)
  375. title = NSLocalizedString(@"Date", nil);
  376. else if (annotationMode == CAnnotationTypeStamp)
  377. title = NSLocalizedString(@"Stamp", nil);
  378. else
  379. title = @"";
  380. if(_annotations.count > 1) {
  381. title = NSLocalizedString(@"Properties", nil);
  382. }
  383. self.titleLabel.stringValue = title;
  384. self.titleViewHeightConstraint.constant = 40;
  385. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  386. if (annotationMode == CAnnotationTypeFreeText ||
  387. annotationMode == CAnnotationTypeAnchored ||
  388. annotationMode == CAnnotationTypeCircle ||
  389. annotationMode == CAnnotationTypeSquare ||
  390. annotationMode == CAnnotationTypeHighlight ||
  391. annotationMode == CAnnotationTypeUnderline ||
  392. annotationMode == CAnnotationTypeStrikeOut ||
  393. annotationMode == CAnnotationTypeLine ||
  394. annotationMode == CAnnotationTypeInk ||
  395. annotationMode == CAnnotationTypeEraser ||
  396. annotationMode == CAnnotationTypeArrow) {
  397. //处理多选
  398. if(_annotations.count > 1) {
  399. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  400. }
  401. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  402. vc.pdfView = self.pdfView;
  403. vc.annotationModel = annotationModel;
  404. self.propertiesBox.contentView = vc.view;
  405. self.contentViewController = vc;
  406. } else if (annotationMode == CAnnotationTypeLink) {
  407. } else if (annotationMode == CAnnotationTypeRadioButton ||
  408. annotationMode == CAnnotationTypeCheckBox ||
  409. annotationMode == CAnnotationTypeTextField ||
  410. annotationMode == CAnnotationTypeComboBox ||
  411. annotationMode == CAnnotationTypeListMenu ||
  412. annotationMode == CAnnotationTypeActionButton) {
  413. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  414. vc.pdfView = self.pdfView;
  415. vc.annotationModel = annotationModel;
  416. self.propertiesBox.contentView = vc.view;
  417. self.contentViewController = vc;
  418. } else if (annotationMode == CAnnotationTypeSignFalse ||
  419. annotationMode == CAnnotationTypeSignTure ||
  420. annotationMode == CAnnotationTypeSignCircle ||
  421. annotationMode == CAnnotationTypeSignLine ||
  422. annotationMode == CAnnotationTypeSignDot) {
  423. if(_annotations.count > 1) {
  424. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  425. }
  426. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  427. vc.pdfView = self.pdfView;
  428. vc.annotationModel = annotationModel;
  429. self.propertiesBox.contentView = vc.view;
  430. self.contentViewController = vc;
  431. vc.callBack = ^(CAnnotationType type) {
  432. if (type == CAnnotationTypeSignFalse) {
  433. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  434. } else if (type == CAnnotationTypeSignTure) {
  435. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  436. } else if (type == CAnnotationTypeSignCircle) {
  437. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  438. } else if (type == CAnnotationTypeSignLine) {
  439. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  440. } else if (type == CAnnotationTypeSignDot) {
  441. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  442. }
  443. };
  444. } else if (annotationMode == CAnnotationTypeSignText ||
  445. annotationMode == CAnnotationTypeSignDate) {
  446. if(_annotations.count > 1) {
  447. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  448. }
  449. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  450. vc.pdfView = self.pdfView;
  451. vc.annotationModel = annotationModel;
  452. self.propertiesBox.contentView = vc.view;
  453. self.contentViewController = vc;
  454. } else if (annotationMode == CAnnotationTypeStamp) {
  455. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  456. vc.pdfView = self.pdfView;
  457. vc.annotationModel = annotationModel;
  458. self.propertiesBox.contentView = vc.view;
  459. self.contentViewController = vc;
  460. } else if (annotationMode == CAnnotationTypeSignSignature) {
  461. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  462. self.titleViewHeightConstraint.constant = 0;
  463. vc.annotationModel = annotationModel;
  464. vc.pdfView = self.pdfView;
  465. self.propertiesBox.contentView = vc.view;
  466. self.contentViewController = vc;
  467. }
  468. }
  469. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  470. {
  471. _isEmptyAnnotation = isEmptyAnnotation;
  472. if (isEmptyAnnotation) {
  473. self.titleLabel.hidden = YES;
  474. self.emptyView.hidden = NO;
  475. } else {
  476. self.titleLabel.hidden = NO;
  477. self.emptyView.hidden = YES;
  478. }
  479. }
  480. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  481. _openPropertiesType = openPropertiesType;
  482. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  483. if (self.contentViewController) {
  484. [self.contentViewController.view removeFromSuperview];
  485. self.contentViewController = nil;
  486. }
  487. self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  488. KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  489. vc.mainController = self.mainController;
  490. vc.pdfView = self.pdfView;
  491. __block typeof(self) blockSelf = self;
  492. vc.readerModeBlock = ^(BOOL isReaderMode) {
  493. if (blockSelf.pageDisplayReaderMode) {
  494. blockSelf.pageDisplayReaderMode(isReaderMode);
  495. }
  496. };
  497. self.propertiesBox.contentView = vc.view;
  498. self.contentViewController = vc;
  499. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  500. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  501. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  502. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  503. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  504. self.propertiesBox.contentView = vc.view;
  505. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  506. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  507. openPropertiesType == KMOpenPropertiesType_Button) {
  508. }
  509. }
  510. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  511. if (_annotations.count <= 0) {
  512. return;
  513. }
  514. CPDFAnnotation *annotation = _annotations.firstObject;
  515. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  516. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  517. if (isContinuousAddStamp) {
  518. self.titleViewHeightConstraint.constant = 0;
  519. }
  520. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  521. if (isContinuousAddStamp) {
  522. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  523. self.titleViewHeightConstraint.constant = 0;
  524. vc.annotationModel = annotationModel;
  525. vc.pdfView = self.pdfView;
  526. self.propertiesBox.contentView = vc.view;
  527. self.contentViewController = vc;
  528. }
  529. }
  530. }
  531. - (CGRect)viewControllerRect {
  532. CGFloat viewFloat = 0;
  533. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  534. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  535. }
  536. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  537. if (!annotation) {
  538. return 0;
  539. }
  540. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  541. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  542. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  543. return 0;
  544. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  545. return 279;
  546. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  547. return 279;
  548. } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
  549. return 279;
  550. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  551. return 0;
  552. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  553. return 279;
  554. } else {
  555. return 279;
  556. }
  557. }
  558. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  559. if (CAnnotationTypeSignature == annotationMode ||
  560. CAnnotationTypeUnkown == annotationMode) {
  561. return 0;
  562. }
  563. return 279;
  564. }
  565. @end