KMAnnotationPropertiesViewController.m 32 KB

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