KMAnnotationPropertiesViewController.m 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. //
  2. // KMAnnotationPropertiesViewController.m
  3. // SignFlow
  4. //
  5. // Created by wanjun on 2021/6/15.
  6. //
  7. #import "KMAnnotationPropertiesViewController.h"
  8. //#import "NSString_SKExtensions.h"
  9. #import <PDF_Reader_Pro-Swift.h>
  10. #import "KMSignatureAnnotationViewController.h"
  11. #import "CSelfSignAnnotation.h"
  12. #import "CSelfSignAnnotationFreeText.h"
  13. #define KMFromContentButtonHeightFloat 32
  14. @interface KMClipView : NSClipView
  15. @end
  16. @implementation KMClipView
  17. - (BOOL)isFlipped {
  18. return YES;
  19. }
  20. @end
  21. @interface KMAnnotationPropertiesViewController ()
  22. @property (assign) IBOutlet NSBox *propertiesBox;
  23. @property (nonatomic,assign) IBOutlet NSView *gradientView;
  24. @property (weak) IBOutlet NSImageView *emptyImageView;
  25. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  26. @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
  27. @property (nonatomic,assign) IBOutlet NSView *emptyView;
  28. @property (nonatomic,retain) NSViewController *contentViewController;
  29. @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
  30. @property (weak) IBOutlet NSLayoutConstraint *buttonbuttonLayoutConstraint;
  31. @property (assign) IBOutlet NSView *buttonView;
  32. @property (assign) IBOutlet NSButton *formGeneralButton;
  33. @property (assign) IBOutlet NSButton *formAppearanceButton;
  34. @property (assign) IBOutlet NSButton *formOptionsButton;
  35. @property (assign) IBOutlet NSView *tipsView;
  36. @property (assign) IBOutlet NSTextField *tipsLabel;
  37. @property (assign) IBOutlet NSImageView *oneLineImageView;
  38. @property (assign) IBOutlet NSImageView *lastLineImageView;
  39. @property (nonatomic, retain) NSButton *clickBtn;
  40. @end
  41. @implementation KMAnnotationPropertiesViewController
  42. #pragma mark - View Methods
  43. //func addNotification() {
  44. // NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  45. //}
  46. //
  47. //func removeNotification() {
  48. // NotificationCenter.default.removeObserver(self)
  49. // DistributedNotificationCenter.default().removeObserver(self)
  50. //}
  51. //
  52. //@objc func changeEffectiveAppearance() {
  53. // let isDarkModel = KMAdvertisementConfig.isDarkModel()
  54. // if isDarkModel {
  55. // self.appearance = NSAppearance(named: .darkAqua)
  56. // } else {
  57. // self.appearance = NSAppearance(named: .aqua)
  58. // }
  59. // self.updateUI()
  60. //}
  61. - (void)dealloc {
  62. [self removeNotification];
  63. }
  64. - (void)addNotification {
  65. [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(changeEffectiveAppearance) name:@"kEffectiveAppearance" object:nil];
  66. }
  67. - (void)removeNotification {
  68. [NSNotificationCenter.defaultCenter removeObserver:self];
  69. }
  70. - (void)changeEffectiveAppearance {
  71. BOOL isDarkModel = [KMAdvertisementConfig isDarkModel];
  72. if (isDarkModel) {
  73. self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
  74. self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#252526" alpha:1].CGColor;
  75. } else {
  76. self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
  77. self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#FAFAFA" alpha:1].CGColor;
  78. }
  79. }
  80. - (void)loadView {
  81. [super loadView];
  82. [self addNotification];
  83. self.view.wantsLayer = YES;
  84. // self.view.layer.backgroundColor = [KMAppearance viewBackgroundColor].CGColor;
  85. // self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
  86. [self changeEffectiveAppearance];
  87. self.view.layer.shadowColor = [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.15].CGColor;
  88. self.view.layer.shadowOffset = NSMakeSize(0, 0);
  89. self.view.layer.shadowRadius = 4;
  90. self.emptyImageView.image = [NSImage imageNamed:@"KMImageNameMarkupEmpty"];
  91. self.subTitleLabel.stringValue = NSLocalizedString(@"Show/Hide Annotation Properties Panel", nil);
  92. NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
  93. ps.lineSpacing = 10;
  94. ps.alignment = NSTextAlignmentCenter;
  95. NSString *subTitle = self.subTitleLabel.stringValue != nil ? self.subTitleLabel.stringValue : @"";
  96. self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subTitle attributes:@{
  97. NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
  98. NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
  99. NSParagraphStyleAttributeName : ps}];
  100. self.subTitleLabel.textColor = [NSColor grayColor];
  101. self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
  102. self.titleLabel.textColor = [KMAppearance KMColor_Layout_H0];
  103. // [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
  104. self.buttonView.hidden = YES;
  105. self.formGeneralButton.wantsLayer = YES;
  106. self.formAppearanceButton.wantsLayer = YES;
  107. self.formOptionsButton.wantsLayer = YES;
  108. [self updateFormContentButtonUI:self.formAppearanceButton];
  109. self.formAppearanceButton.toolTip = NSLocalizedString(@"Appearance", nil);
  110. [self.formAppearanceButton setTitle:NSLocalizedString(@"Appearance", nil)];
  111. self.formGeneralButton.toolTip = NSLocalizedString(@"General", nil);
  112. [self.formGeneralButton setTitle:NSLocalizedString(@"General", nil)];
  113. self.formOptionsButton.toolTip = NSLocalizedString(@"Preferences", nil);
  114. [self.formOptionsButton setTitle:NSLocalizedString(@"Preferences", nil)];
  115. self.tipsView.hidden = YES;
  116. self.tipsView.wantsLayer = YES;
  117. self.tipsView.layer.cornerRadius = 1.0;
  118. self.oneLineImageView.wantsLayer = YES;
  119. self.lastLineImageView.wantsLayer = YES;
  120. self.oneLineImageView.hidden = YES;
  121. }
  122. #pragma mark - Setter Methods
  123. -(void)setAnnotations:(NSArray *)annotations
  124. {
  125. if (_annotations != annotations) {
  126. _annotations = annotations;
  127. }
  128. self.buttonView.hidden = YES;
  129. CPDFAnnotation *annotation = _annotations.firstObject;
  130. if (self.contentViewController) {
  131. [self.contentViewController.view removeFromSuperview];
  132. self.contentViewController = nil;
  133. }
  134. if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
  135. return;
  136. }
  137. if (_annotations.count > 1) {
  138. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  139. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  140. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  141. } else {
  142. [self selectAnnotations:_annotations];
  143. return;
  144. }
  145. }
  146. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
  147. self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
  148. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  149. CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
  150. if (buttonWidget.controlType == 1) {
  151. self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
  152. } else if (buttonWidget.controlType == 2) {
  153. self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
  154. } else if (buttonWidget.controlType == 0) {
  155. self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
  156. }
  157. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  158. CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
  159. if (choiceWidget.isListChoice) {
  160. self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
  161. } else {
  162. self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
  163. }
  164. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  165. KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
  166. CAnnotationType type = newAnnotation.annotationType;
  167. NSString *returnString = @"";
  168. if (type == CAnnotationTypeSignFalse) {
  169. returnString = NSLocalizedString(@"X", nil);
  170. } else if (type == CAnnotationTypeSignTure) {
  171. returnString = NSLocalizedString(@"Check mark", nil);
  172. } else if (type == CAnnotationTypeSignCircle) {
  173. returnString = NSLocalizedString(@"Circle", nil);
  174. } else if (type == CAnnotationTypeSignLine) {
  175. returnString = NSLocalizedString(@"Line", nil);
  176. } else if (type == CAnnotationTypeSignDot) {
  177. returnString = NSLocalizedString(@"Dot", nil);
  178. } else if (type == CAnnotationTypeSignText) {
  179. returnString = NSLocalizedString(@"Text", nil);
  180. }
  181. self.titleLabel.stringValue = returnString;
  182. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  183. self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
  184. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  185. if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  186. KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
  187. if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
  188. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  189. } else {
  190. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  191. }
  192. } else {
  193. self.titleLabel.stringValue = [annotation type].typeName;
  194. }
  195. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
  196. [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  197. self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
  198. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  199. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  200. if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
  201. self.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  202. } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
  203. self.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  204. } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
  205. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  206. } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
  207. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  208. } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
  209. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  210. } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
  211. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  212. } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
  213. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  214. }
  215. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  216. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  217. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  218. self.titleLabel.stringValue = NSLocalizedString(@"Table", nil);
  219. } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
  220. if (self.pdfView.toolMode == CMeasureToolMode ||
  221. [(CPDFLineAnnotation *)annotation isMeasure]) {
  222. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  223. }
  224. } else if ([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) {
  225. self.titleLabel.stringValue = NSLocalizedString(@"Multilines", nil);
  226. } else if ([annotation isKindOfClass:[CPDFPolygonAnnotation class]]) {
  227. if (self.pdfView.annotationType == CAnnotationTypeSquare) {
  228. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  229. } else {
  230. self.titleLabel.stringValue = NSLocalizedString(@"Polygon", nil);
  231. }
  232. } else {
  233. self.titleLabel.stringValue = [annotation type].typeName;
  234. }
  235. self.titleViewHeightConstraint.constant = 40;
  236. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  237. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  238. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  239. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  240. self.buttonView.hidden = NO;
  241. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  242. [self updateFormContentButtonUI:_formGeneralButton];
  243. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  244. vc.pdfview = self.pdfView;
  245. vc.annotationModel = annotationModel;
  246. vc.view.frame = [self viewControllerRect];
  247. [self.view addSubview:vc.view];
  248. self.contentViewController = vc;
  249. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  250. [self fromContentButtonAction:_formOptionsButton];
  251. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  252. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  253. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  254. [self updateFormContentButtonUI:_formGeneralButton];
  255. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  256. vc.pdfview = self.pdfView;
  257. vc.annotations = self.annotations;
  258. vc.view.frame = [self viewControllerRect];
  259. [self.view addSubview:vc.view];
  260. self.contentViewController = vc;
  261. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  262. [self fromContentButtonAction:_formOptionsButton];
  263. }
  264. }
  265. } else if ([annotation isKindOfClass:[KMAnnotationFromSignature class]]) {
  266. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  267. vc.pdfview = self.pdfView;
  268. vc.annotationModel = annotationModel;
  269. vc.view.frame = [self viewControllerRect];
  270. [self.view addSubview:vc.view];
  271. self.contentViewController = vc;
  272. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  273. if (!_isClickFormSignature) {
  274. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  275. vc.pdfview = self.pdfView;
  276. vc.annotationModel = annotationModel;
  277. vc.view.frame = [self viewControllerRect];
  278. [self.view addSubview:vc.view];
  279. self.contentViewController = vc;
  280. }
  281. _isClickFormSignature = NO;
  282. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  283. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  284. NSString *contents = nil;
  285. if ([linkAnnotation URL]) {
  286. contents = [linkAnnotation URL];
  287. if (contents) {
  288. contents = [NSString stringWithFormat:@"1%@", contents];
  289. } else {
  290. contents = @"";
  291. }
  292. } else {
  293. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  294. }
  295. KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
  296. vc.annotations = self.annotations;
  297. vc.pdfDocument = self.pdfView.document;
  298. vc.pdfview = self.pdfView;
  299. vc.view.frame = [self viewControllerRect];
  300. [self.view addSubview:vc.view];
  301. self.contentViewController = vc;
  302. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  303. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  304. if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
  305. newAnnotation.annotationType == CAnnotationTypeSignTure ||
  306. newAnnotation.annotationType == CAnnotationTypeSignCircle ||
  307. newAnnotation.annotationType == CAnnotationTypeSignLine ||
  308. newAnnotation.annotationType == CAnnotationTypeSignDot) {
  309. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  310. vc.pdfView = self.pdfView;
  311. vc.annotationModel = annotationModel;
  312. self.propertiesBox.contentView = vc.view;
  313. self.contentViewController = vc;
  314. __weak typeof (self) weakSelf = self;
  315. vc.callBack = ^(CAnnotationType type) {
  316. if (type == CAnnotationTypeSignFalse) {
  317. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  318. } else if (type == CAnnotationTypeSignTure) {
  319. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  320. } else if (type == CAnnotationTypeSignCircle) {
  321. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  322. } else if (type == CAnnotationTypeSignLine) {
  323. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  324. } else if (type == CAnnotationTypeSignDot) {
  325. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  326. }
  327. if (weakSelf.annoTypeDidChange != nil) {
  328. weakSelf.annoTypeDidChange(annotation);
  329. }
  330. };
  331. } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
  332. newAnnotation.annotationType == CAnnotationTypeSignDate) {
  333. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  334. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  335. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  336. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  337. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  338. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  339. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  340. }
  341. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  342. vc.subType = subType;
  343. vc.pdfView = self.pdfView;
  344. vc.annotationModel = annotationModel;
  345. self.propertiesBox.contentView = vc.view;
  346. self.contentViewController = vc;
  347. }
  348. } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  349. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
  350. if (newAnnotation.subType == CAnnotationTypeSignText ||
  351. newAnnotation.subType == CAnnotationTypeSignDate) {
  352. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  353. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  354. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  355. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  356. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  357. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  358. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  359. }
  360. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  361. vc.subType = subType;
  362. vc.pdfView = self.pdfView;
  363. vc.annotationModel = annotationModel;
  364. self.propertiesBox.contentView = vc.view;
  365. self.contentViewController = vc;
  366. }
  367. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
  368. [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  369. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  370. vc.pdfView = self.pdfView;
  371. vc.annotationModel = annotationModel;
  372. self.propertiesBox.contentView = vc.view;
  373. self.contentViewController = vc;
  374. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  375. KMAnnotationTableViewController *vc = [[KMAnnotationTableViewController alloc] init];
  376. vc.pdfView = self.pdfView;
  377. vc.annotationModel = annotationModel;
  378. self.propertiesBox.contentView = vc.view;
  379. self.contentViewController = vc;
  380. } else if (([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) ||
  381. ([annotation isKindOfClass:[CPDFPolygonAnnotation class]])) {
  382. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  383. vc.pdfView = self.pdfView;
  384. vc.annotationModel = annotationModel;
  385. self.propertiesBox.contentView = vc.view;
  386. self.contentViewController = vc;
  387. } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
  388. if ((self.pdfView.toolMode == CMeasureToolMode) ||
  389. [(CPDFLineAnnotation *)annotation isMeasure]) {
  390. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  391. vc.pdfView = self.pdfView;
  392. vc.annotationModel = annotationModel;
  393. self.propertiesBox.contentView = vc.view;
  394. self.contentViewController = vc;
  395. } else {
  396. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  397. vc.pdfView = self.pdfView;
  398. vc.annotationModel = annotationModel;
  399. self.propertiesBox.contentView = vc.view;
  400. self.contentViewController = vc;
  401. }
  402. } else {
  403. if ([annotation isKindOfClass:[CPDFInkAnnotation class]]) {
  404. KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
  405. vc.pdfView = self.pdfView;
  406. vc.annotationModel = annotationModel;
  407. self.propertiesBox.contentView = vc.view;
  408. self.contentViewController = vc;
  409. } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  410. CPDFMarkupAnnotation *markupA = (CPDFMarkupAnnotation *)annotation;
  411. if (markupA.markupType == CPDFMarkupTypeSquiggly) {
  412. KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
  413. vc.pdfView = self.pdfView;
  414. vc.annotationModel = annotationModel;
  415. self.propertiesBox.contentView = vc.view;
  416. self.contentViewController = vc;
  417. } else {
  418. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  419. vc.pdfView = self.pdfView;
  420. vc.annotationModel = annotationModel;
  421. self.propertiesBox.contentView = vc.view;
  422. self.contentViewController = vc;
  423. }
  424. } else {
  425. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  426. vc.pdfView = self.pdfView;
  427. vc.annotationModel = annotationModel;
  428. self.propertiesBox.contentView = vc.view;
  429. self.contentViewController = vc;
  430. }
  431. }
  432. // self.buttonbuttonLayoutConstraint.constant = self.buttonView.hidden ? -36 : 0;
  433. }
  434. - (void)selectAnnotations:(NSArray *)annotations {
  435. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  436. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  437. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  438. annotationMode = CAnnotationTypeHighlight;
  439. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  440. annotationMode = CAnnotationTypeInk;
  441. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  442. annotationMode = CAnnotationTypeAnchored;
  443. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  444. annotationMode = CAnnotationTypeSquare;
  445. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  446. annotationMode = CAnnotationTypeCircle;
  447. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  448. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  449. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  450. annotationMode = CAnnotationTypeArrow;
  451. } else {
  452. annotationMode = CAnnotationTypeLine;
  453. }
  454. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  455. annotationMode = CAnnotationTypeLink;
  456. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  457. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  458. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  459. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  460. annotationMode = CAnnotationTypeSignFalse;
  461. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  462. annotationMode = CAnnotationTypeSignTure;
  463. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  464. annotationMode = CAnnotationTypeSignCircle;
  465. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  466. annotationMode = CAnnotationTypeSignLine;
  467. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  468. annotationMode = CAnnotationTypeSignDot;
  469. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  470. annotationMode = CAnnotationTypeSignDot;
  471. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  472. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  473. if (newAnnotation.subType == CAnnotationTypeSignText)
  474. annotationMode = CAnnotationTypeSignText;
  475. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  476. annotationMode = CAnnotationTypeSignDate;
  477. } else {
  478. annotationMode = CAnnotationTypeStamp;
  479. }
  480. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  481. annotationMode = CAnnotationTypeSignature;
  482. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  483. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  484. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  485. if (newAnnotation.subType == CAnnotationTypeSignText)
  486. annotationMode = CAnnotationTypeSignText;
  487. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  488. annotationMode = CAnnotationTypeSignDate;
  489. } else {
  490. annotationMode = CAnnotationTypeFreeText;
  491. }
  492. }
  493. self.annotationMode = annotationMode;
  494. }
  495. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  496. _annotationMode = annotationMode;
  497. if (self.contentViewController) {
  498. [self.contentViewController.view removeFromSuperview];
  499. self.contentViewController = nil;
  500. }
  501. NSString *title = @"";
  502. if (annotationMode == CAnnotationTypeFreeText)
  503. title = NSLocalizedString(@"Text", @"Description for export");
  504. else if (annotationMode == CAnnotationTypeCircle)
  505. title = NSLocalizedString(@"Circle", @"Description for export");
  506. else if (annotationMode == CAnnotationTypeSquare)
  507. title = NSLocalizedString(@"Rectangle", @"Description for export");
  508. else if (annotationMode == CAnnotationTypeHighlight) {
  509. title = NSLocalizedString(@"Highlight", @"Description for export");
  510. if (_annotations.count > 1)
  511. title = NSLocalizedString(@"General", @"Description for export");
  512. }
  513. else if (annotationMode == CAnnotationTypeUnderline) {
  514. title = NSLocalizedString(@"Underline", @"Description for export");
  515. if (_annotations.count > 1)
  516. title = NSLocalizedString(@"General", @"Description for export");
  517. }
  518. else if (annotationMode == CAnnotationTypeStrikeOut)
  519. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  520. else if (annotationMode == CAnnotationTypeLine)
  521. title = NSLocalizedString(@"Line", @"Description for export");
  522. else if (annotationMode == CAnnotationTypeArrow)
  523. title = NSLocalizedString(@"Arrow", @"Description for export");
  524. else if (annotationMode == CAnnotationTypeInk)
  525. title = NSLocalizedString(@"Freehand", @"Description for export");
  526. else if (annotationMode == CAnnotationTypeEraser)
  527. title = NSLocalizedString(@"Eraser", @"Description for export");
  528. else if (annotationMode == CAnnotationTypeAnchored)
  529. title = NSLocalizedString(@"Note", @"Description for export");
  530. else if (annotationMode == CAnnotationTypeLink)
  531. title = NSLocalizedString(@"Link", @"Description for export");
  532. else if (annotationMode == CAnnotationTypeTextField)
  533. title = NSLocalizedString(@"Text Field", @"Description for export");
  534. else if (annotationMode == CAnnotationTypeCheckBox)
  535. title = NSLocalizedString(@"Check Box", @"Description for export");
  536. else if (annotationMode == CAnnotationTypeListMenu)
  537. title = NSLocalizedString(@"List Box", @"Description for export");
  538. else if (annotationMode == CAnnotationTypeComboBox)
  539. title = NSLocalizedString(@"Combo Box", @"Description for export");
  540. else if (annotationMode == CAnnotationTypeRadioButton)
  541. title = NSLocalizedString(@"Radio Button", @"Description for export");
  542. else if (annotationMode == CAnnotationTypeActionButton)
  543. title = NSLocalizedString(@"Button", @"Description for export");
  544. else if (annotationMode == CAnnotationTypeSignature)
  545. title = NSLocalizedString(@"Sample", @"Description for export");
  546. else if (annotationMode == CAnnotationTypeSignDot)
  547. title = NSLocalizedString(@"Dot", @"Description for export");
  548. else if (annotationMode == CAnnotationTypeSignLine)
  549. title = NSLocalizedString(@"Line", @"Description for export");
  550. else if (annotationMode == CAnnotationTypeSignCircle)
  551. title = NSLocalizedString(@"Rectangle", @"Description for export");
  552. else if (annotationMode == CAnnotationTypeSignFalse)
  553. title = NSLocalizedString(@"X", nil);
  554. else if (annotationMode == CAnnotationTypeSignTure)
  555. title = NSLocalizedString(@"Check mark", nil);
  556. else if (annotationMode == CAnnotationTypeSignText)
  557. title = NSLocalizedString(@"Text", nil);
  558. else if (annotationMode == CAnnotationTypeSignDate)
  559. title = NSLocalizedString(@"Date", nil);
  560. else if (annotationMode == CAnnotationTypeStamp)
  561. title = NSLocalizedString(@"Stamp", nil);
  562. else if (annotationMode == CAnnotationTypeSquiggly)
  563. title = NSLocalizedString(@"Squiggly", nil);
  564. else
  565. title = @"";
  566. if(_annotations.count > 1) {
  567. title = NSLocalizedString(@"Properties", nil);
  568. }
  569. self.titleLabel.stringValue = title;
  570. self.titleViewHeightConstraint.constant = 40;
  571. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  572. if (annotationMode == CAnnotationTypeFreeText ||
  573. annotationMode == CAnnotationTypeAnchored ||
  574. annotationMode == CAnnotationTypeCircle ||
  575. annotationMode == CAnnotationTypeSquare ||
  576. annotationMode == CAnnotationTypeHighlight ||
  577. annotationMode == CAnnotationTypeUnderline ||
  578. annotationMode == CAnnotationTypeStrikeOut ||
  579. annotationMode == CAnnotationTypeSquiggly ||
  580. annotationMode == CAnnotationTypeLine ||
  581. annotationMode == CAnnotationTypeInk ||
  582. annotationMode == CAnnotationTypeEraser ||
  583. annotationMode == CAnnotationTypeArrow) {
  584. //处理多选
  585. if(_annotations.count > 1) {
  586. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  587. }
  588. if (annotationMode == CAnnotationTypeInk) {
  589. KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
  590. vc.pdfView = self.pdfView;
  591. vc.annotationModel = annotationModel;
  592. self.propertiesBox.contentView = vc.view;
  593. self.contentViewController = vc;
  594. } else if (annotationMode == CAnnotationTypeSquiggly) {
  595. KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
  596. vc.pdfView = self.pdfView;
  597. vc.annotationModel = annotationModel;
  598. self.propertiesBox.contentView = vc.view;
  599. self.contentViewController = vc;
  600. } else if (annotationMode == CAnnotationTypeEraser) {
  601. KMEraserAnnotationController *vc = [[KMEraserAnnotationController alloc] init];
  602. vc.pdfView = self.pdfView;
  603. vc.annotationModel = annotationModel;
  604. self.propertiesBox.contentView = vc.view;
  605. self.contentViewController = vc;
  606. } else {
  607. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  608. vc.pdfView = self.pdfView;
  609. vc.annotationModel = annotationModel;
  610. self.propertiesBox.contentView = vc.view;
  611. self.contentViewController = vc;
  612. }
  613. } else if (annotationMode == CAnnotationTypeLink) {
  614. } else if (annotationMode == CAnnotationTypeRadioButton ||
  615. annotationMode == CAnnotationTypeCheckBox ||
  616. annotationMode == CAnnotationTypeTextField ||
  617. annotationMode == CAnnotationTypeComboBox ||
  618. annotationMode == CAnnotationTypeListMenu ||
  619. annotationMode == CAnnotationTypeActionButton) {
  620. if (annotationMode == CAnnotationTypeTextField) {
  621. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  622. vc.pdfView = self.pdfView;
  623. vc.annotationModel = annotationModel;
  624. self.propertiesBox.contentView = vc.view;
  625. self.contentViewController = vc;
  626. } else if (annotationMode == CAnnotationTypeListMenu ||
  627. annotationMode == CAnnotationTypeComboBox ||
  628. annotationMode == CAnnotationTypeActionButton) {
  629. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  630. vc.annotationModel = annotationModel;
  631. vc.pdfView = self.pdfView;
  632. self.propertiesBox.contentView = vc.view;
  633. self.contentViewController = vc;
  634. } else if (annotationMode == CAnnotationTypeRadioButton ||
  635. annotationMode == CAnnotationTypeCheckBox) {
  636. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  637. vc.annotationModel = annotationModel;
  638. vc.pdfView = self.pdfView;
  639. self.propertiesBox.contentView = vc.view;
  640. self.contentViewController = vc;
  641. }
  642. } else if (annotationMode == CAnnotationTypeSignFalse ||
  643. annotationMode == CAnnotationTypeSignTure ||
  644. annotationMode == CAnnotationTypeSignCircle ||
  645. annotationMode == CAnnotationTypeSignLine ||
  646. annotationMode == CAnnotationTypeSignDot) {
  647. if(_annotations.count > 1) {
  648. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  649. }
  650. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  651. vc.pdfView = self.pdfView;
  652. vc.annotationModel = annotationModel;
  653. self.propertiesBox.contentView = vc.view;
  654. self.contentViewController = vc;
  655. __weak typeof(self) weakSelf = self;
  656. vc.callBack = ^(CAnnotationType type) {
  657. if (type == CAnnotationTypeSignFalse) {
  658. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  659. } else if (type == CAnnotationTypeSignTure) {
  660. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  661. } else if (type == CAnnotationTypeSignCircle) {
  662. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  663. } else if (type == CAnnotationTypeSignLine) {
  664. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  665. } else if (type == CAnnotationTypeSignDot) {
  666. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  667. }
  668. if (weakSelf.annoTypeDidChange != nil) {
  669. weakSelf.annoTypeDidChange(weakSelf.annotations.firstObject);
  670. }
  671. };
  672. } else if (annotationMode == CAnnotationTypeSignText ||
  673. annotationMode == CAnnotationTypeSignDate) {
  674. if(_annotations.count > 1) {
  675. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  676. }
  677. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  678. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  679. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  680. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  681. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  682. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  683. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  684. }
  685. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  686. vc.subType = subType;
  687. vc.pdfView = self.pdfView;
  688. vc.annotationModel = annotationModel;
  689. self.propertiesBox.contentView = vc.view;
  690. self.contentViewController = vc;
  691. } else if (annotationMode == CAnnotationTypeStamp) {
  692. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  693. vc.pdfView = self.pdfView;
  694. vc.annotationModel = annotationModel;
  695. self.propertiesBox.contentView = vc.view;
  696. self.contentViewController = vc;
  697. } else if (annotationMode == CAnnotationTypeSignSignature) {
  698. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  699. self.titleViewHeightConstraint.constant = 0;
  700. vc.annotationModel = annotationModel;
  701. vc.pdfView = self.pdfView;
  702. self.propertiesBox.contentView = vc.view;
  703. self.contentViewController = vc;
  704. }
  705. }
  706. - (void)setMeasureMode:(CAnnotationType)annotationMode {
  707. _annotationMode = annotationMode;
  708. if (self.contentViewController) {
  709. [self.contentViewController.view removeFromSuperview];
  710. self.contentViewController = nil;
  711. }
  712. NSString *title = @"";
  713. if (annotationMode == CAnnotationTypeSquare)
  714. title = NSLocalizedString(@"Rectangle", @"Description for export");
  715. else if (annotationMode == CAnnotationTypeLine)
  716. title = NSLocalizedString(@"Line", @"Description for export");
  717. else if (annotationMode == CAnnotationTypePolyLine)
  718. title = NSLocalizedString(@"Multilines", nil);
  719. else if (annotationMode == CAnnotationTypePolyGon)
  720. title = NSLocalizedString(@"Polygon", nil);
  721. else
  722. title = @"";
  723. if(_annotations.count > 1) {
  724. title = NSLocalizedString(@"Properties", nil);
  725. }
  726. self.titleLabel.stringValue = title;
  727. self.titleViewHeightConstraint.constant = 40;
  728. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  729. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  730. vc.pdfView = self.pdfView;
  731. vc.annotationModel = annotationModel;
  732. self.propertiesBox.contentView = vc.view;
  733. self.contentViewController = vc;
  734. }
  735. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  736. {
  737. _isEmptyAnnotation = isEmptyAnnotation;
  738. if (isEmptyAnnotation) {
  739. self.titleLabel.hidden = YES;
  740. self.emptyView.hidden = NO;
  741. } else {
  742. self.titleLabel.hidden = NO;
  743. self.emptyView.hidden = YES;
  744. }
  745. }
  746. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  747. self.contentViewController = nil;
  748. self.titleLabel.stringValue = @"";
  749. self.titleViewHeightConstraint.constant = 0;
  750. _openPropertiesType = openPropertiesType;
  751. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  752. if (self.contentViewController) {
  753. [self.contentViewController.view removeFromSuperview];
  754. self.contentViewController = nil;
  755. }
  756. self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  757. KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  758. vc.mainController = self.mainController;
  759. vc.pdfView = self.pdfView;
  760. __weak typeof(self) weakSelf = self;
  761. vc.readerModeBlock = ^(BOOL isReaderMode) {
  762. if (weakSelf.pageDisplayReaderMode) {
  763. weakSelf.pageDisplayReaderMode(isReaderMode);
  764. }
  765. };
  766. self.propertiesBox.contentView = vc.view;
  767. self.contentViewController = vc;
  768. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  769. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  770. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  771. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  772. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  773. self.propertiesBox.contentView = vc.view;
  774. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  775. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  776. openPropertiesType == KMOpenPropertiesType_Button) {
  777. } else if (openPropertiesType == KMOpenPropertiesType_FormSignatureClick) {
  778. self.contentViewController = nil;
  779. self.titleLabel.stringValue = @"";
  780. self.titleViewHeightConstraint.constant = 0;
  781. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  782. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  783. vc.isClickSignatureList = YES;
  784. vc.annotationModel = annotationModel;
  785. vc.pdfView = self.pdfView;
  786. self.propertiesBox.contentView = vc.view;
  787. self.contentViewController = vc;
  788. }
  789. }
  790. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  791. if (_annotations.count <= 0) {
  792. return;
  793. }
  794. CPDFAnnotation *annotation = _annotations.firstObject;
  795. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  796. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  797. if (isContinuousAddStamp) {
  798. self.titleViewHeightConstraint.constant = 0;
  799. }
  800. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  801. if (isContinuousAddStamp) {
  802. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  803. self.titleViewHeightConstraint.constant = 0;
  804. vc.annotationModel = annotationModel;
  805. vc.pdfView = self.pdfView;
  806. self.propertiesBox.contentView = vc.view;
  807. self.contentViewController = vc;
  808. }
  809. }
  810. }
  811. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  812. if (!annotation) {
  813. return 0;
  814. }
  815. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  816. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  817. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  818. return 0;
  819. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  820. return 279;
  821. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  822. return 279;
  823. } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
  824. return 279;
  825. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  826. return 0;
  827. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  828. return 279;
  829. } else {
  830. return 279;
  831. }
  832. }
  833. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  834. if (CAnnotationTypeSignature == annotationMode ||
  835. CAnnotationTypeUnkown == annotationMode) {
  836. return 0;
  837. }
  838. return 279;
  839. }
  840. #pragma mark - Private Method
  841. - (CGRect)viewControllerRect {
  842. CGFloat viewFloat = 0;
  843. if (_buttonView == nil || self.gradientView == nil) {
  844. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  845. }
  846. if (_buttonView.hidden) {
  847. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
  848. } else {
  849. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  850. }
  851. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  852. }
  853. - (void)updateFormContentButtonUI:(NSButton *)button {
  854. self.clickBtn = button;
  855. switch (button.tag) {
  856. case 100:
  857. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  858. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  859. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  860. if([KMAppearance isDarkMode]) {
  861. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  862. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  863. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  864. } else {
  865. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  866. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  867. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  868. }
  869. break;
  870. case 101:
  871. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  872. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  873. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  874. if([KMAppearance isDarkMode]) {
  875. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  876. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  877. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  878. } else {
  879. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  880. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  881. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  882. }
  883. break;
  884. case 102:
  885. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  886. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  887. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  888. if([KMAppearance isDarkMode]) {
  889. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  890. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  891. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  892. } else {
  893. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  894. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  895. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  896. }
  897. break;
  898. default:
  899. break;
  900. }
  901. }
  902. #pragma mark - NSButton Action
  903. - (IBAction)fromContentButtonAction:(NSButton *)sender {
  904. [self updateFormContentButtonUI:sender];
  905. self.tipsView.hidden = YES;
  906. switch (sender.tag) {
  907. case 100:
  908. {
  909. self.lastLineImageView.hidden = NO;
  910. self.oneLineImageView.hidden = YES;
  911. [self formGeneralProperties];
  912. }
  913. break;
  914. case 101:
  915. {
  916. self.lastLineImageView.hidden = YES;
  917. self.oneLineImageView.hidden = YES;
  918. [self formAppearanceProperties];
  919. }
  920. break;
  921. case 102:
  922. {
  923. self.lastLineImageView.hidden = YES;
  924. self.oneLineImageView.hidden = NO;
  925. [self formOptionProperties];
  926. }
  927. break;
  928. default:
  929. break;
  930. }
  931. }
  932. - (void)formGeneralProperties {
  933. CPDFAnnotation *annotation = _annotations.firstObject;
  934. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  935. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
  936. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  937. if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
  938. return;
  939. }
  940. [self.contentViewController.view removeFromSuperview];
  941. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  942. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  943. vc.pdfview = self.pdfView;
  944. vc.annotationModel = annotationModel;
  945. vc.view.frame = [self viewControllerRect];
  946. [self.view addSubview:vc.view];
  947. self.contentViewController = vc;
  948. }
  949. }
  950. - (void)formAppearanceProperties {
  951. CPDFAnnotation *annotation = _annotations.firstObject;
  952. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  953. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  954. if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
  955. return;
  956. }
  957. [self.contentViewController.view removeFromSuperview];
  958. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  959. vc.pdfView = self.pdfView;
  960. vc.annotationModel = annotationModel;
  961. vc.view.frame = [self viewControllerRect];
  962. [self.view addSubview:vc.view];
  963. self.contentViewController = vc;
  964. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  965. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  966. if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
  967. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
  968. return;
  969. }
  970. [self.contentViewController.view removeFromSuperview];
  971. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  972. vc.pdfView = self.pdfView;
  973. vc.annotationModel = annotationModel;
  974. vc.view.frame = [self viewControllerRect];
  975. [self.view addSubview:vc.view];
  976. self.contentViewController = vc;
  977. } else if (newAnnotation.controlType == 0) {
  978. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  979. return;
  980. }
  981. [self.contentViewController.view removeFromSuperview];
  982. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  983. vc.pdfView = self.pdfView;
  984. vc.annotationModel = annotationModel;
  985. vc.view.frame = [self viewControllerRect];
  986. [self.view addSubview:vc.view];
  987. self.contentViewController = vc;
  988. }
  989. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  990. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  991. return;
  992. }
  993. [self.contentViewController.view removeFromSuperview];
  994. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  995. vc.pdfView = self.pdfView;
  996. vc.annotationModel = annotationModel;
  997. vc.view.frame = [self viewControllerRect];
  998. [self.view addSubview:vc.view];
  999. self.contentViewController = vc;
  1000. }
  1001. }
  1002. - (void)formOptionProperties {
  1003. CPDFAnnotation *annotation = _annotations.firstObject;
  1004. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  1005. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  1006. if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
  1007. return;
  1008. }
  1009. [self.contentViewController.view removeFromSuperview];
  1010. KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
  1011. vc.pdfView = self.pdfView;
  1012. vc.annotationModel = annotationModel;
  1013. vc.view.frame = [self viewControllerRect];
  1014. [self.view addSubview:vc.view];
  1015. self.contentViewController = vc;
  1016. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  1017. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  1018. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  1019. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
  1020. return;
  1021. }
  1022. [self.contentViewController.view removeFromSuperview];
  1023. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
  1024. self.tipsView.hidden = NO;
  1025. self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"To create a set of mutually exclusive radio buttons (i.e., where only one can be selected at a time), give the fields the same name but different button choices.", nil)];;
  1026. } else {
  1027. self.tipsView.hidden = YES;
  1028. }
  1029. KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
  1030. vc.pdfView = self.pdfView;
  1031. vc.annotationModel = annotationModel;
  1032. vc.view.frame = [self viewControllerRect];
  1033. [self.view addSubview:vc.view];
  1034. self.contentViewController = vc;
  1035. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  1036. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
  1037. return;
  1038. }
  1039. [self.contentViewController.view removeFromSuperview];
  1040. KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
  1041. vc.pdfView = self.pdfView;
  1042. vc.annotationModel = annotationModel;
  1043. vc.view.frame = [self viewControllerRect];
  1044. [self.view addSubview:vc.view];
  1045. self.contentViewController = vc;
  1046. }
  1047. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  1048. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
  1049. return;
  1050. }
  1051. [self.contentViewController.view removeFromSuperview];
  1052. self.tipsView.hidden = YES;
  1053. self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
  1054. KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
  1055. vc.pdfView = self.pdfView;
  1056. vc.annotationModel = annotationModel;
  1057. vc.view.frame = [self viewControllerRect];
  1058. [self.view addSubview:vc.view];
  1059. self.contentViewController = vc;
  1060. }
  1061. }
  1062. @end