KMAnnotationPropertiesViewController.m 32 KB

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