KMAnnotationPropertiesViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 {
  141. self.titleLabel.stringValue = [annotation type].typeName;
  142. }
  143. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  144. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  145. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  146. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]){
  147. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  148. vc.pdfView = self.pdfView;
  149. vc.annotationModel = annotationModel;
  150. self.propertiesBox.contentView = vc.view;
  151. self.contentViewController = vc;
  152. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  153. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  154. vc.pdfView = self.pdfView;
  155. vc.annotationModel = annotationModel;
  156. self.propertiesBox.contentView = vc.view;
  157. self.contentViewController = vc;
  158. vc.callback = ^(CAnnotationType type) {
  159. if (type == CAnnotationTypeSignFalse) {
  160. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  161. } else if (type == CAnnotationTypeSignTure) {
  162. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  163. } else if (type == CAnnotationTypeSignCircle) {
  164. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  165. } else if (type == CAnnotationTypeSignLine) {
  166. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  167. } else if (type == CAnnotationTypeSignDot) {
  168. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  169. }
  170. };
  171. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  172. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  173. NSString *contents = nil;
  174. if ([linkAnnotation URL]) {
  175. contents = [linkAnnotation URL];
  176. if (contents) {
  177. contents = [NSString stringWithFormat:@"1%@", contents];
  178. } else {
  179. contents = @"";
  180. }
  181. } else {
  182. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  183. }
  184. KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
  185. vc.annotations = self.annotations;
  186. vc.pdfDocument = self.pdfView.document;
  187. vc.pdfview = self.pdfView;
  188. vc.view.frame = [self viewControllerRect];
  189. [self.view addSubview:vc.view];
  190. self.contentViewController = vc;
  191. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  192. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  193. if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
  194. newAnnotation.annotationType == CAnnotationTypeSignTure ||
  195. newAnnotation.annotationType == CAnnotationTypeSignCircle ||
  196. newAnnotation.annotationType == CAnnotationTypeSignLine ||
  197. newAnnotation.annotationType == CAnnotationTypeSignDot) {
  198. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  199. vc.pdfView = self.pdfView;
  200. vc.annotationModel = annotationModel;
  201. self.propertiesBox.contentView = vc.view;
  202. self.contentViewController = vc;
  203. vc.callback = ^(CAnnotationType type) {
  204. if (type == CAnnotationTypeSignFalse) {
  205. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  206. } else if (type == CAnnotationTypeSignTure) {
  207. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  208. } else if (type == CAnnotationTypeSignCircle) {
  209. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  210. } else if (type == CAnnotationTypeSignLine) {
  211. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  212. } else if (type == CAnnotationTypeSignDot) {
  213. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  214. }
  215. };
  216. } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
  217. newAnnotation.annotationType == CAnnotationTypeSignDate) {
  218. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  219. vc.pdfView = self.pdfView;
  220. vc.annotationModel = annotationModel;
  221. self.propertiesBox.contentView = vc.view;
  222. self.contentViewController = vc;
  223. }
  224. } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  225. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
  226. if (newAnnotation.subType == CAnnotationTypeSignText ||
  227. newAnnotation.subType == CAnnotationTypeSignDate) {
  228. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  229. vc.pdfView = self.pdfView;
  230. vc.annotationModel = annotationModel;
  231. self.propertiesBox.contentView = vc.view;
  232. self.contentViewController = vc;
  233. }
  234. } else if ([annotation isKindOfClass:[KMAnnotationStamp class]]) {
  235. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  236. vc.pdfView = self.pdfView;
  237. vc.annotationModel = annotationModel;
  238. vc.view.frame = [self viewControllerRect];
  239. [self.view addSubview:vc.view];
  240. self.contentViewController = vc;
  241. } else if ([annotation isKindOfClass:[CPDFListSignatureAnnotation class]]) {
  242. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  243. } else {
  244. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  245. vc.pdfView = self.pdfView;
  246. vc.annotationModel = annotationModel;
  247. self.propertiesBox.contentView = vc.view;
  248. self.contentViewController = vc;
  249. }
  250. }
  251. - (void)selectAnnotations:(NSArray *)annotations {
  252. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  253. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  254. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  255. annotationMode = CAnnotationTypeHighlight;
  256. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  257. annotationMode = CAnnotationTypeInk;
  258. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  259. annotationMode = CAnnotationTypeAnchored;
  260. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  261. annotationMode = CAnnotationTypeSquare;
  262. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  263. annotationMode = CAnnotationTypeCircle;
  264. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  265. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  266. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  267. annotationMode = CAnnotationTypeArrow;
  268. } else {
  269. annotationMode = CAnnotationTypeLine;
  270. }
  271. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  272. annotationMode = CAnnotationTypeLink;
  273. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  274. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  275. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  276. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  277. annotationMode = CAnnotationTypeSignFalse;
  278. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  279. annotationMode = CAnnotationTypeSignTure;
  280. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  281. annotationMode = CAnnotationTypeSignCircle;
  282. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  283. annotationMode = CAnnotationTypeSignLine;
  284. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  285. annotationMode = CAnnotationTypeSignDot;
  286. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  287. annotationMode = CAnnotationTypeSignDot;
  288. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  289. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  290. if (newAnnotation.subType == CAnnotationTypeSignText)
  291. annotationMode = CAnnotationTypeSignText;
  292. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  293. annotationMode = CAnnotationTypeSignDate;
  294. } else {
  295. annotationMode = CAnnotationTypeStamp;
  296. }
  297. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  298. annotationMode = CAnnotationTypeSignature;
  299. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  300. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  301. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  302. if (newAnnotation.subType == CAnnotationTypeSignText)
  303. annotationMode = CAnnotationTypeSignText;
  304. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  305. annotationMode = CAnnotationTypeSignDate;
  306. } else {
  307. annotationMode = CAnnotationTypeFreeText;
  308. }
  309. }
  310. self.annotationMode = annotationMode;
  311. }
  312. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  313. _annotationMode = annotationMode;
  314. if (self.contentViewController) {
  315. [self.contentViewController.view removeFromSuperview];
  316. self.contentViewController = nil;
  317. }
  318. NSString *title = @"";
  319. if (annotationMode == CAnnotationTypeFreeText)
  320. title = NSLocalizedString(@"Text", @"Description for export");
  321. else if (annotationMode == CAnnotationTypeCircle)
  322. title = NSLocalizedString(@"Circle", @"Description for export");
  323. else if (annotationMode == CAnnotationTypeSquare)
  324. title = NSLocalizedString(@"Shape", @"Description for export");
  325. else if (annotationMode == CAnnotationTypeHighlight) {
  326. title = NSLocalizedString(@"Highlight", @"Description for export");
  327. if (_annotations.count > 1)
  328. title = NSLocalizedString(@"General", @"Description for export");
  329. }
  330. else if (annotationMode == CAnnotationTypeUnderline) {
  331. title = NSLocalizedString(@"Underline", @"Description for export");
  332. if (_annotations.count > 1)
  333. title = NSLocalizedString(@"General", @"Description for export");
  334. }
  335. else if (annotationMode == CAnnotationTypeStrikeOut)
  336. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  337. else if (annotationMode == CAnnotationTypeLine)
  338. title = NSLocalizedString(@"Line", @"Description for export");
  339. else if (annotationMode == CAnnotationTypeArrow)
  340. title = NSLocalizedString(@"Arrow", @"Description for export");
  341. else if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser)
  342. title = NSLocalizedString(@"Pen", @"Description for export");
  343. else if (annotationMode == CAnnotationTypeAnchored)
  344. title = NSLocalizedString(@"Note", @"Description for export");
  345. else if (annotationMode == CAnnotationTypeLink)
  346. title = NSLocalizedString(@"Link", @"Description for export");
  347. else if (annotationMode == CAnnotationTypeTextField)
  348. title = NSLocalizedString(@"Text Field", @"Description for export");
  349. else if (annotationMode == CAnnotationTypeCheckBox)
  350. title = NSLocalizedString(@"Check Box", @"Description for export");
  351. else if (annotationMode == CAnnotationTypeListMenu)
  352. title = NSLocalizedString(@"List Box", @"Description for export");
  353. else if (annotationMode == CAnnotationTypeComboBox)
  354. title = NSLocalizedString(@"Combo Box", @"Description for export");
  355. else if (annotationMode == CAnnotationTypeRadioButton)
  356. title = NSLocalizedString(@"Radio Button", @"Description for export");
  357. else if (annotationMode == CAnnotationTypeActionButton)
  358. title = NSLocalizedString(@"Button", @"Description for export");
  359. else if (annotationMode == CAnnotationTypeSignature)
  360. title = NSLocalizedString(@"Sample", @"Description for export");
  361. else if (annotationMode == CAnnotationTypeSignDot)
  362. title = NSLocalizedString(@"Dot", @"Description for export");
  363. else if (annotationMode == CAnnotationTypeSignLine)
  364. title = NSLocalizedString(@"Line", @"Description for export");
  365. else if (annotationMode == CAnnotationTypeSignCircle)
  366. title = NSLocalizedString(@"Rectangle", @"Description for export");
  367. else if (annotationMode == CAnnotationTypeSignFalse)
  368. title = NSLocalizedString(@"Fork", nil);
  369. else if (annotationMode == CAnnotationTypeSignTure)
  370. title = NSLocalizedString(@"Hook", nil);
  371. else if (annotationMode == CAnnotationTypeSignText)
  372. title = NSLocalizedString(@"Text", nil);
  373. else if (annotationMode == CAnnotationTypeSignDate)
  374. title = NSLocalizedString(@"Date", nil);
  375. else
  376. title = @"";
  377. if(_annotations.count > 1) {
  378. title = NSLocalizedString(@"Properties", nil);
  379. }
  380. self.titleLabel.stringValue = title;
  381. self.titleViewHeightConstraint.constant = 40;
  382. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  383. if (annotationMode == CAnnotationTypeFreeText ||
  384. annotationMode == CAnnotationTypeAnchored ||
  385. annotationMode == CAnnotationTypeCircle ||
  386. annotationMode == CAnnotationTypeSquare ||
  387. annotationMode == CAnnotationTypeHighlight ||
  388. annotationMode == CAnnotationTypeUnderline ||
  389. annotationMode == CAnnotationTypeStrikeOut ||
  390. annotationMode == CAnnotationTypeLine ||
  391. annotationMode == CAnnotationTypeInk ||
  392. annotationMode == CAnnotationTypeEraser ||
  393. annotationMode == CAnnotationTypeArrow) {
  394. //处理多选
  395. if(_annotations.count > 1) {
  396. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  397. }
  398. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  399. vc.pdfView = self.pdfView;
  400. vc.annotationModel = annotationModel;
  401. self.propertiesBox.contentView = vc.view;
  402. self.contentViewController = vc;
  403. } else if (annotationMode == CAnnotationTypeLink) {
  404. } else if (annotationMode == CAnnotationTypeRadioButton ||
  405. annotationMode == CAnnotationTypeCheckBox ||
  406. annotationMode == CAnnotationTypeTextField ||
  407. annotationMode == CAnnotationTypeComboBox ||
  408. annotationMode == CAnnotationTypeListMenu ||
  409. annotationMode == CAnnotationTypeActionButton) {
  410. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  411. vc.pdfView = self.pdfView;
  412. vc.annotationModel = annotationModel;
  413. self.propertiesBox.contentView = vc.view;
  414. self.contentViewController = vc;
  415. } else if (annotationMode == CAnnotationTypeSignFalse ||
  416. annotationMode == CAnnotationTypeSignTure ||
  417. annotationMode == CAnnotationTypeSignCircle ||
  418. annotationMode == CAnnotationTypeSignLine ||
  419. annotationMode == CAnnotationTypeSignDot) {
  420. if(_annotations.count > 1) {
  421. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  422. }
  423. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  424. vc.pdfView = self.pdfView;
  425. vc.annotationModel = annotationModel;
  426. self.propertiesBox.contentView = vc.view;
  427. self.contentViewController = vc;
  428. vc.callback = ^(CAnnotationType type) {
  429. if (type == CAnnotationTypeSignFalse) {
  430. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  431. } else if (type == CAnnotationTypeSignTure) {
  432. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  433. } else if (type == CAnnotationTypeSignCircle) {
  434. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  435. } else if (type == CAnnotationTypeSignLine) {
  436. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  437. } else if (type == CAnnotationTypeSignDot) {
  438. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  439. }
  440. };
  441. } else if (annotationMode == CAnnotationTypeSignText ||
  442. annotationMode == CAnnotationTypeSignDate) {
  443. if(_annotations.count > 1) {
  444. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  445. }
  446. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  447. vc.pdfView = self.pdfView;
  448. vc.annotationModel = annotationModel;
  449. self.propertiesBox.contentView = vc.view;
  450. self.contentViewController = vc;
  451. } else if (annotationMode == CAnnotationTypeStamp) {
  452. self.titleViewHeightConstraint.constant = 0;
  453. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  454. vc.pdfView = self.pdfView;
  455. vc.annotationModel = annotationModel;
  456. vc.view.frame = [self viewControllerRect];
  457. [self.view addSubview:vc.view];
  458. self.contentViewController = vc;
  459. } else if (annotationMode == CAnnotationTypeSignSignature) {
  460. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  461. self.titleViewHeightConstraint.constant = 0;
  462. vc.annotationModel = annotationModel;
  463. vc.pdfView = self.pdfView;
  464. self.propertiesBox.contentView = vc.view;
  465. self.contentViewController = vc;
  466. }
  467. }
  468. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  469. {
  470. _isEmptyAnnotation = isEmptyAnnotation;
  471. if (isEmptyAnnotation) {
  472. self.titleLabel.hidden = YES;
  473. self.emptyView.hidden = NO;
  474. } else {
  475. self.titleLabel.hidden = NO;
  476. self.emptyView.hidden = YES;
  477. }
  478. }
  479. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  480. _openPropertiesType = openPropertiesType;
  481. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  482. if (self.contentViewController) {
  483. [self.contentViewController.view removeFromSuperview];
  484. self.contentViewController = nil;
  485. }
  486. self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  487. KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  488. vc.mainController = self.mainController;
  489. vc.pdfView = self.pdfView;
  490. __block typeof(self) blockSelf = self;
  491. vc.readerModeBlock = ^(BOOL isReaderMode) {
  492. if (blockSelf.pageDisplayReaderMode) {
  493. blockSelf.pageDisplayReaderMode(isReaderMode);
  494. }
  495. };
  496. self.propertiesBox.contentView = vc.view;
  497. self.contentViewController = vc;
  498. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  499. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  500. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  501. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  502. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  503. self.propertiesBox.contentView = vc.view;
  504. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  505. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  506. openPropertiesType == KMOpenPropertiesType_Button) {
  507. }
  508. }
  509. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  510. if (_annotations.count <= 0) {
  511. return;
  512. }
  513. CPDFAnnotation *annotation = _annotations.firstObject;
  514. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  515. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  516. if (isContinuousAddStamp) {
  517. self.titleViewHeightConstraint.constant = 0;
  518. }
  519. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  520. if (isContinuousAddStamp) {
  521. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  522. self.titleViewHeightConstraint.constant = 0;
  523. vc.annotationModel = annotationModel;
  524. vc.pdfView = self.pdfView;
  525. self.propertiesBox.contentView = vc.view;
  526. self.contentViewController = vc;
  527. }
  528. }
  529. }
  530. - (CGRect)viewControllerRect {
  531. CGFloat viewFloat = 0;
  532. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  533. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  534. }
  535. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  536. if (!annotation) {
  537. return 0;
  538. }
  539. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  540. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  541. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  542. return 0;
  543. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  544. return 279;
  545. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  546. return 279;
  547. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  548. return 279;
  549. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  550. return 279;
  551. } else {
  552. return 279;
  553. }
  554. }
  555. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  556. if (CAnnotationTypeSignature == annotationMode ||
  557. CAnnotationTypeUnkown == annotationMode) {
  558. return 0;
  559. }
  560. return 279;
  561. }
  562. @end