KMAnnotationPropertiesViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. //
  2. // KMAnnotationPropertiesViewController.m
  3. // SignFlow
  4. //
  5. // Created by wanjun on 2021/6/15.
  6. //
  7. #import "KMAnnotationPropertiesViewController.h"
  8. #import "KMGeneralAnnotationViewController.h"
  9. //#import "NSString_SKExtensions.h"
  10. #import "KMAnnotationStampViewController.h"
  11. #import <PDF_Master-Swift.h>
  12. #import "KMSignatureAnnotationViewController.h"
  13. #import "CSelfSignAnnotation.h"
  14. #import "CSelfSignAnnotationFreeText.h"
  15. #define KMFromContentButtonHeightFloat 32
  16. @interface KMClipView : NSClipView
  17. @end
  18. @implementation KMClipView
  19. - (BOOL)isFlipped {
  20. return YES;
  21. }
  22. @end
  23. @interface KMAnnotationPropertiesViewController ()
  24. @property (assign) IBOutlet NSBox *propertiesBox;
  25. @property (nonatomic,assign) IBOutlet NSView *gradientView;
  26. @property (weak) IBOutlet NSImageView *emptyImageView;
  27. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  28. @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
  29. @property (nonatomic,assign) IBOutlet NSView *emptyView;
  30. @property (nonatomic,retain) NSViewController *contentViewController;
  31. @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
  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. CPDFAnnotation *annotation = _annotations.firstObject;
  62. if (self.contentViewController) {
  63. [self.contentViewController.view removeFromSuperview];
  64. self.contentViewController = nil;
  65. }
  66. if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
  67. return;
  68. }
  69. if (_annotations.count > 1) {
  70. [self selectAnnotations:_annotations];
  71. return;
  72. }
  73. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
  74. self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
  75. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  76. CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
  77. if (buttonWidget.controlType == 1) {
  78. self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
  79. } else if (buttonWidget.controlType == 2) {
  80. self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
  81. } else if (buttonWidget.controlType == 0) {
  82. self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
  83. }
  84. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  85. CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
  86. if (choiceWidget.isListChoice) {
  87. self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
  88. } else {
  89. self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
  90. }
  91. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  92. KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
  93. CAnnotationType type = newAnnotation.annotationType;
  94. NSString *returnString = @"";
  95. if (type == CAnnotationTypeSignFalse) {
  96. returnString = NSLocalizedString(@"X", nil);
  97. } else if (type == CAnnotationTypeSignTure) {
  98. returnString = NSLocalizedString(@"Check mark", nil);
  99. } else if (type == CAnnotationTypeSignCircle) {
  100. returnString = NSLocalizedString(@"Circle", nil);
  101. } else if (type == CAnnotationTypeSignLine) {
  102. returnString = NSLocalizedString(@"Line", nil);
  103. } else if (type == CAnnotationTypeSignDot) {
  104. returnString = NSLocalizedString(@"Dot", nil);
  105. } else if (type == CAnnotationTypeSignText) {
  106. returnString = NSLocalizedString(@"Text", nil);
  107. }
  108. self.titleLabel.stringValue = returnString;
  109. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  110. self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
  111. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  112. if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  113. KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
  114. if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
  115. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  116. } else {
  117. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  118. }
  119. } else {
  120. self.titleLabel.stringValue = [annotation type].typeName;
  121. }
  122. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
  123. [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  124. self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
  125. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  126. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  127. if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
  128. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  129. } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
  130. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  131. } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
  132. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  133. } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
  134. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  135. } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
  136. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  137. } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
  138. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  139. } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
  140. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  141. }
  142. } else {
  143. self.titleLabel.stringValue = [annotation type].typeName;
  144. }
  145. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  146. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  147. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  148. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]){
  149. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  150. vc.pdfView = self.pdfView;
  151. vc.annotationModel = annotationModel;
  152. self.propertiesBox.contentView = vc.view;
  153. self.contentViewController = vc;
  154. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  155. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  156. vc.pdfView = self.pdfView;
  157. vc.annotationModel = annotationModel;
  158. self.propertiesBox.contentView = vc.view;
  159. self.contentViewController = vc;
  160. vc.callback = ^(CAnnotationType type) {
  161. if (type == CAnnotationTypeSignFalse) {
  162. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  163. } else if (type == CAnnotationTypeSignTure) {
  164. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  165. } else if (type == CAnnotationTypeSignCircle) {
  166. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  167. } else if (type == CAnnotationTypeSignLine) {
  168. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  169. } else if (type == CAnnotationTypeSignDot) {
  170. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  171. }
  172. };
  173. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  174. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  175. NSString *contents = nil;
  176. if ([linkAnnotation URL]) {
  177. contents = [linkAnnotation URL];
  178. if (contents) {
  179. contents = [NSString stringWithFormat:@"1%@", contents];
  180. } else {
  181. contents = @"";
  182. }
  183. } else {
  184. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  185. }
  186. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  187. vc.pdfview = self.pdfView;
  188. vc.annotationModel = annotationModel;
  189. self.propertiesBox.contentView = vc.view;
  190. self.contentViewController = vc;
  191. vc.pageCount = self.pdfView.document.pageCount;
  192. [vc setContent:contents];
  193. vc.startDestination = [[CPDFDestination alloc] initWithDocument:self.pdfView.document pageIndex:linkAnnotation.page.pageIndex atPoint:linkAnnotation.bounds.origin zoom:self.pdfView.scaleFactor];
  194. if (linkAnnotation.destination) {
  195. CPDFDestination *des = linkAnnotation.destination;
  196. vc.targetDestination = [[CPDFDestination alloc] initWithDocument:des.document pageIndex:des.pageIndex atPoint:des.point zoom:des.zoom];
  197. }
  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. KMFillSignShapePanel *vc = [[KMFillSignShapePanel 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:[CPDFStampAnnotation class]]) {
  242. // KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  243. // vc.annotationModel = annotationModel;
  244. // vc.pdfView = self.pdfView;
  245. // self.propertiesBox.contentView = vc.view;
  246. // self.contentViewController = vc;
  247. } else if ([annotation isKindOfClass:[CPDFListSignatureAnnotation class]]) {
  248. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  249. } else {
  250. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  251. vc.pdfView = self.pdfView;
  252. vc.annotationModel = annotationModel;
  253. self.propertiesBox.contentView = vc.view;
  254. self.contentViewController = vc;
  255. if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  256. __block typeof(self) blockSelf = self;
  257. vc.callBack = ^(CAnnotationType newType) {
  258. NSString *returnString = @"";
  259. if (newType == CAnnotationTypeSignFalse) {
  260. returnString = NSLocalizedString(@"X", nil);
  261. } else if (newType == CAnnotationTypeSignTure) {
  262. returnString = NSLocalizedString(@"Check mark", nil);
  263. } else if (newType == CAnnotationTypeSignCircle) {
  264. returnString = NSLocalizedString(@"Circle", nil);
  265. } else if (newType == CAnnotationTypeSignLine) {
  266. returnString = NSLocalizedString(@"Line", nil);
  267. } else if (newType == CAnnotationTypeSignDot) {
  268. returnString = NSLocalizedString(@"Dot", nil);
  269. } else if (newType == CAnnotationTypeSignText) {
  270. returnString = NSLocalizedString(@"Text", nil);
  271. } else if (newType == CAnnotationTypeInk) {
  272. returnString = NSLocalizedString(@"Pen", nil);
  273. } else if (newType == CAnnotationTypeEraser) {
  274. returnString = NSLocalizedString(@"Eraser", nil);
  275. }
  276. blockSelf.titleLabel.stringValue = returnString;
  277. };
  278. } else {
  279. vc.callBack = nil;
  280. }
  281. }
  282. }
  283. - (void)selectAnnotations:(NSArray *)annotations {
  284. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  285. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  286. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  287. annotationMode = CAnnotationTypeHighlight;
  288. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  289. annotationMode = CAnnotationTypeInk;
  290. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  291. annotationMode = CAnnotationTypeAnchored;
  292. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  293. annotationMode = CAnnotationTypeSquare;
  294. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  295. annotationMode = CAnnotationTypeCircle;
  296. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  297. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  298. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  299. annotationMode = CAnnotationTypeArrow;
  300. } else {
  301. annotationMode = CAnnotationTypeLine;
  302. }
  303. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  304. annotationMode = CAnnotationTypeLink;
  305. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  306. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  307. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  308. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  309. annotationMode = CAnnotationTypeSignFalse;
  310. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  311. annotationMode = CAnnotationTypeSignTure;
  312. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  313. annotationMode = CAnnotationTypeSignCircle;
  314. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  315. annotationMode = CAnnotationTypeSignLine;
  316. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  317. annotationMode = CAnnotationTypeSignDot;
  318. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  319. annotationMode = CAnnotationTypeSignDot;
  320. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  321. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  322. if (newAnnotation.subType == CAnnotationTypeSignText)
  323. annotationMode = CAnnotationTypeSignText;
  324. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  325. annotationMode = CAnnotationTypeSignDate;
  326. } else {
  327. annotationMode = CAnnotationTypeStamp;
  328. }
  329. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  330. annotationMode = CAnnotationTypeSignature;
  331. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  332. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  333. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  334. if (newAnnotation.subType == CAnnotationTypeSignText)
  335. annotationMode = CAnnotationTypeSignText;
  336. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  337. annotationMode = CAnnotationTypeSignDate;
  338. } else {
  339. annotationMode = CAnnotationTypeFreeText;
  340. }
  341. }
  342. self.annotationMode = annotationMode;
  343. }
  344. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  345. _annotationMode = annotationMode;
  346. if (self.contentViewController) {
  347. [self.contentViewController.view removeFromSuperview];
  348. self.contentViewController = nil;
  349. }
  350. NSString *title = @"";
  351. if (annotationMode == CAnnotationTypeFreeText)
  352. title = NSLocalizedString(@"Text", @"Description for export");
  353. else if (annotationMode == CAnnotationTypeCircle)
  354. title = NSLocalizedString(@"Circle", @"Description for export");
  355. else if (annotationMode == CAnnotationTypeSquare)
  356. title = NSLocalizedString(@"Shape", @"Description for export");
  357. else if (annotationMode == CAnnotationTypeHighlight) {
  358. title = NSLocalizedString(@"Highlight", @"Description for export");
  359. if (_annotations.count > 1)
  360. title = NSLocalizedString(@"General", @"Description for export");
  361. }
  362. else if (annotationMode == CAnnotationTypeUnderline) {
  363. title = NSLocalizedString(@"Underline", @"Description for export");
  364. if (_annotations.count > 1)
  365. title = NSLocalizedString(@"General", @"Description for export");
  366. }
  367. else if (annotationMode == CAnnotationTypeStrikeOut)
  368. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  369. else if (annotationMode == CAnnotationTypeLine)
  370. title = NSLocalizedString(@"Line", @"Description for export");
  371. else if (annotationMode == CAnnotationTypeArrow)
  372. title = NSLocalizedString(@"Arrow", @"Description for export");
  373. else if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser)
  374. title = NSLocalizedString(@"Pen", @"Description for export");
  375. else if (annotationMode == CAnnotationTypeAnchored)
  376. title = NSLocalizedString(@"Note", @"Description for export");
  377. else if (annotationMode == CAnnotationTypeLink)
  378. title = NSLocalizedString(@"Link", @"Description for export");
  379. else if (annotationMode == CAnnotationTypeTextField)
  380. title = NSLocalizedString(@"Text Field", @"Description for export");
  381. else if (annotationMode == CAnnotationTypeCheckBox)
  382. title = NSLocalizedString(@"Check Box", @"Description for export");
  383. else if (annotationMode == CAnnotationTypeListMenu)
  384. title = NSLocalizedString(@"List Box", @"Description for export");
  385. else if (annotationMode == CAnnotationTypeComboBox)
  386. title = NSLocalizedString(@"Combo Box", @"Description for export");
  387. else if (annotationMode == CAnnotationTypeRadioButton)
  388. title = NSLocalizedString(@"Radio Button", @"Description for export");
  389. else if (annotationMode == CAnnotationTypeActionButton)
  390. title = NSLocalizedString(@"Button", @"Description for export");
  391. else if (annotationMode == CAnnotationTypeSignature)
  392. title = NSLocalizedString(@"Sample", @"Description for export");
  393. else if (annotationMode == CAnnotationTypeSignDot)
  394. title = NSLocalizedString(@"Dot", @"Description for export");
  395. else if (annotationMode == CAnnotationTypeSignLine)
  396. title = NSLocalizedString(@"Line", @"Description for export");
  397. else if (annotationMode == CAnnotationTypeSignCircle)
  398. title = NSLocalizedString(@"Rectangle", @"Description for export");
  399. else if (annotationMode == CAnnotationTypeSignFalse)
  400. title = NSLocalizedString(@"Fork", nil);
  401. else if (annotationMode == CAnnotationTypeSignTure)
  402. title = NSLocalizedString(@"Hook", nil);
  403. else if (annotationMode == CAnnotationTypeSignText)
  404. title = NSLocalizedString(@"Text", nil);
  405. else if (annotationMode == CAnnotationTypeSignDate)
  406. title = NSLocalizedString(@"Date", nil);
  407. else
  408. title = @"";
  409. if(_annotations.count > 1) {
  410. title = NSLocalizedString(@"Properties", nil);
  411. }
  412. self.titleLabel.stringValue = title;
  413. self.titleViewHeightConstraint.constant = 40;
  414. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  415. if (annotationMode == CAnnotationTypeFreeText ||
  416. annotationMode == CAnnotationTypeAnchored ||
  417. annotationMode == CAnnotationTypeCircle ||
  418. annotationMode == CAnnotationTypeSquare ||
  419. annotationMode == CAnnotationTypeHighlight ||
  420. annotationMode == CAnnotationTypeUnderline ||
  421. annotationMode == CAnnotationTypeStrikeOut ||
  422. annotationMode == CAnnotationTypeLine ||
  423. annotationMode == CAnnotationTypeInk ||
  424. annotationMode == CAnnotationTypeEraser ||
  425. annotationMode == CAnnotationTypeArrow) {
  426. //处理多选
  427. if(_annotations.count > 1) {
  428. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  429. }
  430. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  431. vc.pdfView = self.pdfView;
  432. vc.annotationModel = annotationModel;
  433. self.propertiesBox.contentView = vc.view;
  434. self.contentViewController = vc;
  435. if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser) {
  436. __block typeof(self) blockSelf = self;
  437. vc.callBack = ^(CAnnotationType newType) {
  438. NSString *returnString = @"";
  439. if (newType == CAnnotationTypeInk) {
  440. returnString = NSLocalizedString(@"Pen", nil);
  441. } else if (newType == CAnnotationTypeEraser) {
  442. returnString = NSLocalizedString(@"Eraser", nil);
  443. }
  444. blockSelf.titleLabel.stringValue = returnString;
  445. };
  446. } else {
  447. vc.callBack = nil;
  448. }
  449. } else if (annotationMode == CAnnotationTypeLink) {
  450. // KMAnnotationEmptyLinkViewController *vc = [[KMAnnotationEmptyLinkViewController alloc] init];
  451. // vc.annotationModel = annotationModel;
  452. // self.propertiesBox.contentView = vc.view;
  453. // self.contentViewController = vc;
  454. } else if (annotationMode == CAnnotationTypeRadioButton ||
  455. annotationMode == CAnnotationTypeCheckBox ||
  456. annotationMode == CAnnotationTypeTextField ||
  457. annotationMode == CAnnotationTypeComboBox ||
  458. annotationMode == CAnnotationTypeListMenu ||
  459. annotationMode == CAnnotationTypeActionButton) {
  460. KMFormPropertPanelViewController *vc = [[KMFormPropertPanelViewController alloc] init];
  461. vc.pdfView = self.pdfView;
  462. vc.annotationModel = annotationModel;
  463. self.propertiesBox.contentView = vc.view;
  464. self.contentViewController = vc;
  465. } else if (annotationMode == CAnnotationTypeSignFalse ||
  466. annotationMode == CAnnotationTypeSignTure ||
  467. annotationMode == CAnnotationTypeSignCircle ||
  468. annotationMode == CAnnotationTypeSignLine ||
  469. annotationMode == CAnnotationTypeSignDot) {
  470. if(_annotations.count > 1) {
  471. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  472. }
  473. KMFillSignShapePanel *vc = [[KMFillSignShapePanel alloc] init];
  474. vc.pdfView = self.pdfView;
  475. vc.annotationModel = annotationModel;
  476. self.propertiesBox.contentView = vc.view;
  477. self.contentViewController = vc;
  478. vc.callback = ^(CAnnotationType type) {
  479. if (type == CAnnotationTypeSignFalse) {
  480. self.titleLabel.stringValue = NSLocalizedString(@"Fork", nil);
  481. } else if (type == CAnnotationTypeSignTure) {
  482. self.titleLabel.stringValue = NSLocalizedString(@"Hook", nil);
  483. } else if (type == CAnnotationTypeSignCircle) {
  484. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  485. } else if (type == CAnnotationTypeSignLine) {
  486. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  487. } else if (type == CAnnotationTypeSignDot) {
  488. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  489. }
  490. };
  491. } else if (annotationMode == CAnnotationTypeSignText ||
  492. annotationMode == CAnnotationTypeSignDate) {
  493. if(_annotations.count > 1) {
  494. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  495. }
  496. KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
  497. vc.pdfView = self.pdfView;
  498. vc.annotationModel = annotationModel;
  499. self.propertiesBox.contentView = vc.view;
  500. self.contentViewController = vc;
  501. } else if (annotationMode == CAnnotationTypeStamp) {
  502. self.titleViewHeightConstraint.constant = 0;
  503. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  504. vc.annotationModel = annotationModel;
  505. vc.pdfView = self.pdfView;
  506. self.propertiesBox.contentView = vc.view;
  507. self.contentViewController = vc;
  508. } else if (annotationMode == CAnnotationTypeSignSignature) {
  509. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  510. self.titleViewHeightConstraint.constant = 0;
  511. vc.annotationModel = annotationModel;
  512. vc.pdfView = self.pdfView;
  513. self.propertiesBox.contentView = vc.view;
  514. self.contentViewController = vc;
  515. }
  516. }
  517. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  518. {
  519. _isEmptyAnnotation = isEmptyAnnotation;
  520. if (isEmptyAnnotation) {
  521. self.titleLabel.hidden = YES;
  522. self.emptyView.hidden = NO;
  523. } else {
  524. self.titleLabel.hidden = NO;
  525. self.emptyView.hidden = YES;
  526. }
  527. }
  528. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  529. _openPropertiesType = openPropertiesType;
  530. CPDFAnnotationModel * annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_pdfView.activeAnnotations];
  531. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  532. // self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  533. // KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  534. // vc.mainController = self.mainController;
  535. // vc.pdfView = self.pdfView;
  536. // __block typeof(self) blockSelf = self;
  537. // vc.readerModeBlock = ^(BOOL isReaderMode) {
  538. // [blockSelf.mainController readMode:blockSelf];
  539. // };
  540. // self.propertiesBox.contentView = vc.view;
  541. // self.contentViewController = vc;
  542. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  543. // self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  544. // KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  545. // vc.annotationModel = annotationModel;
  546. // vc.pdfView = self.pdfView;
  547. // self.propertiesBox.contentView = vc.view;
  548. // self.contentViewController = vc;
  549. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  550. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  551. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  552. vc.annotationModel = annotationModel;
  553. vc.pdfview = self.pdfView;
  554. vc.pageCount = self.pdfView.document.pageCount;
  555. [vc setIsCreateLink:YES];
  556. self.propertiesBox.contentView = vc.view;
  557. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  558. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  559. openPropertiesType == KMOpenPropertiesType_Button) {
  560. }
  561. }
  562. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  563. if (_annotations.count <= 0) {
  564. return;
  565. }
  566. CPDFAnnotation *annotation = _annotations.firstObject;
  567. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  568. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  569. if (isContinuousAddStamp) {
  570. self.titleViewHeightConstraint.constant = 0;
  571. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  572. vc.annotationModel = annotationModel;
  573. vc.pdfView = self.pdfView;
  574. vc.isContinuousAddStamp = YES;
  575. self.propertiesBox.contentView = vc.view;
  576. self.contentViewController = vc;
  577. }
  578. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  579. if (isContinuousAddStamp) {
  580. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  581. self.titleViewHeightConstraint.constant = 0;
  582. vc.annotationModel = annotationModel;
  583. vc.pdfView = self.pdfView;
  584. self.propertiesBox.contentView = vc.view;
  585. self.contentViewController = vc;
  586. }
  587. }
  588. }
  589. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  590. if (!annotation) {
  591. return 0;
  592. }
  593. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  594. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  595. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  596. return 0;
  597. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  598. return 279;
  599. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  600. return 279;
  601. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  602. return 279;
  603. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  604. return 279;
  605. } else {
  606. return 279;
  607. }
  608. }
  609. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  610. if (CAnnotationTypeSignature == annotationMode ||
  611. CAnnotationTypeUnkown == annotationMode) {
  612. return 0;
  613. }
  614. return 279;
  615. }
  616. @end