KMAnnotationPropertiesViewController.m 31 KB

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