123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- //
- // KMAnnotationPropertiesViewController.m
- // SignFlow
- //
- // Created by wanjun on 2021/6/15.
- //
- #import "KMAnnotationPropertiesViewController.h"
- //#import "NSString_SKExtensions.h"
- #import <PDF_Reader_Pro-Swift.h>
- #import "KMSignatureAnnotationViewController.h"
- #import "CSelfSignAnnotation.h"
- #import "CSelfSignAnnotationFreeText.h"
- #define KMFromContentButtonHeightFloat 32
- @interface KMClipView : NSClipView
- @end
- @implementation KMClipView
- - (BOOL)isFlipped {
- return YES;
- }
- @end
- @interface KMAnnotationPropertiesViewController ()
- @property (assign) IBOutlet NSBox *propertiesBox;
- @property (nonatomic,assign) IBOutlet NSView *gradientView;
- @property (weak) IBOutlet NSImageView *emptyImageView;
- @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
- @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
- @property (nonatomic,assign) IBOutlet NSView *emptyView;
- @property (nonatomic,retain) NSViewController *contentViewController;
- @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
- @property (weak) IBOutlet NSLayoutConstraint *buttonbuttonLayoutConstraint;
- @property (assign) IBOutlet NSView *buttonView;
- @property (assign) IBOutlet NSButton *formGeneralButton;
- @property (assign) IBOutlet NSButton *formAppearanceButton;
- @property (assign) IBOutlet NSButton *formOptionsButton;
- @property (assign) IBOutlet NSView *tipsView;
- @property (assign) IBOutlet NSTextField *tipsLabel;
- @property (assign) IBOutlet NSImageView *oneLineImageView;
- @property (assign) IBOutlet NSImageView *lastLineImageView;
- @property (nonatomic, retain) NSButton *clickBtn;
- @end
- @implementation KMAnnotationPropertiesViewController
- #pragma mark - View Methods
- //func addNotification() {
- // NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
- //}
- //
- //func removeNotification() {
- // NotificationCenter.default.removeObserver(self)
- // DistributedNotificationCenter.default().removeObserver(self)
- //}
- //
- //@objc func changeEffectiveAppearance() {
- // let isDarkModel = KMAdvertisementConfig.isDarkModel()
- // if isDarkModel {
- // self.appearance = NSAppearance(named: .darkAqua)
- // } else {
- // self.appearance = NSAppearance(named: .aqua)
- // }
- // self.updateUI()
- //}
- - (void)dealloc {
- [self removeNotification];
- }
- - (void)addNotification {
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(changeEffectiveAppearance) name:@"kEffectiveAppearance" object:nil];
- }
- - (void)removeNotification {
- [NSNotificationCenter.defaultCenter removeObserver:self];
- }
- - (void)changeEffectiveAppearance {
- BOOL isDarkModel = [KMAdvertisementConfig isDarkModel];
- if (isDarkModel) {
- self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
- self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#252526" alpha:1].CGColor;
- } else {
- self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
- self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#FAFAFA" alpha:1].CGColor;
- }
- }
- - (void)loadView {
- [super loadView];
-
- [self addNotification];
-
- self.view.wantsLayer = YES;
- // self.view.layer.backgroundColor = [KMAppearance viewBackgroundColor].CGColor;
- // self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
- [self changeEffectiveAppearance];
- self.view.layer.shadowColor = [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.15].CGColor;
- self.view.layer.shadowOffset = NSMakeSize(0, 0);
- self.view.layer.shadowRadius = 4;
-
- self.emptyImageView.image = [NSImage imageNamed:@"KMImageNameMarkupEmpty"];
- self.subTitleLabel.stringValue = NSLocalizedString(@"Show/Hide Annotation Properties Panel", nil);
- NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
- ps.lineSpacing = 10;
- ps.alignment = NSTextAlignmentCenter;
- self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:self.subTitleLabel.stringValue attributes:@{
- NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
- NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
- NSParagraphStyleAttributeName : ps}];
- self.subTitleLabel.textColor = [NSColor grayColor];
-
- self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
- self.titleLabel.textColor = [KMAppearance KMColor_Layout_H0];
- // [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
-
- self.buttonView.hidden = YES;
- self.formGeneralButton.wantsLayer = YES;
- self.formAppearanceButton.wantsLayer = YES;
- self.formOptionsButton.wantsLayer = YES;
- [self updateFormContentButtonUI:self.formAppearanceButton];
- self.formAppearanceButton.toolTip = NSLocalizedString(@"Appearance", nil);
- [self.formAppearanceButton setTitle:NSLocalizedString(@"Appearance", nil)];
- self.formGeneralButton.toolTip = NSLocalizedString(@"General", nil);
- [self.formGeneralButton setTitle:NSLocalizedString(@"General", nil)];
- self.formOptionsButton.toolTip = NSLocalizedString(@"Preferences", nil);
- [self.formOptionsButton setTitle:NSLocalizedString(@"Preferences", nil)];
-
- self.tipsView.hidden = YES;
- self.tipsView.wantsLayer = YES;
- self.tipsView.layer.cornerRadius = 1.0;
-
- self.oneLineImageView.wantsLayer = YES;
- self.lastLineImageView.wantsLayer = YES;
-
- self.oneLineImageView.hidden = YES;
- }
- #pragma mark - Setter Methods
- -(void)setAnnotations:(NSArray *)annotations
- {
- if (_annotations != annotations) {
- _annotations = annotations;
- }
-
- self.buttonView.hidden = YES;
- CPDFAnnotation *annotation = _annotations.firstObject;
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
- return;
- }
- if (_annotations.count > 1) {
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
-
- } else {
- [self selectAnnotations:_annotations];
- return;
- }
- }
-
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
- self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
- if (buttonWidget.controlType == 1) {
- self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
- } else if (buttonWidget.controlType == 2) {
- self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
- } else if (buttonWidget.controlType == 0) {
- self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
- if (choiceWidget.isListChoice) {
- self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
- } else {
- self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
- }
- } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
- KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
- CAnnotationType type = newAnnotation.annotationType;
- NSString *returnString = @"";
- if (type == CAnnotationTypeSignFalse) {
- returnString = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- returnString = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- returnString = NSLocalizedString(@"Circle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- returnString = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- returnString = NSLocalizedString(@"Dot", nil);
- } else if (type == CAnnotationTypeSignText) {
- returnString = NSLocalizedString(@"Text", nil);
- }
- self.titleLabel.stringValue = returnString;
- } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
- } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
- KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
- if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
- self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
- } else {
- self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
- }
- } else {
- self.titleLabel.stringValue = [annotation type].typeName;
- }
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
- self.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
- self.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
- self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
- self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
- self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
- self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
- self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
- }
- } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
- } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Table", nil);
- } else {
- self.titleLabel.stringValue = [annotation type].typeName;
- }
- self.titleViewHeightConstraint.constant = 40;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]){
- self.buttonView.hidden = NO;
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- [self updateFormContentButtonUI:_formGeneralButton];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- [self fromContentButtonAction:_formOptionsButton];
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
- [self updateFormContentButtonUI:_formGeneralButton];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotations = self.annotations;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
- [self fromContentButtonAction:_formOptionsButton];
- }
- }
- } else if ([annotation isKindOfClass:[KMAnnotationFromSignature class]]) {
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
- if (!_isClickFormSignature) {
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- _isClickFormSignature = NO;
- } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
- NSString *contents = nil;
- if ([linkAnnotation URL]) {
- contents = [linkAnnotation URL];
- if (contents) {
- contents = [NSString stringWithFormat:@"1%@", contents];
- } else {
- contents = @"";
- }
- } else {
- contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
- }
-
- KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
- vc.annotations = self.annotations;
- vc.pdfDocument = self.pdfView.document;
- vc.pdfview = self.pdfView;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
- newAnnotation.annotationType == CAnnotationTypeSignTure ||
- newAnnotation.annotationType == CAnnotationTypeSignCircle ||
- newAnnotation.annotationType == CAnnotationTypeSignLine ||
- newAnnotation.annotationType == CAnnotationTypeSignDot) {
- KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- __weak typeof (self) weakSelf = self;
- vc.callBack = ^(CAnnotationType type) {
- if (type == CAnnotationTypeSignFalse) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- }
-
- if (weakSelf.annoTypeDidChange != nil) {
- weakSelf.annoTypeDidChange(annotation);
- }
- };
- } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
- newAnnotation.annotationType == CAnnotationTypeSignDate) {
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
- if (newAnnotation.subType == CAnnotationTypeSignText ||
- newAnnotation.subType == CAnnotationTypeSignDate) {
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
-
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
- [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
- KMAnnotationTableViewController *vc = [[KMAnnotationTableViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else {
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
-
- // self.buttonbuttonLayoutConstraint.constant = self.buttonView.hidden ? -36 : 0;
- }
- - (void)selectAnnotations:(NSArray *)annotations {
- CPDFAnnotation *fristAnnotation = annotations.firstObject;
- CAnnotationType annotationMode = CAnnotationTypeUnkown;
- if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- annotationMode = CAnnotationTypeHighlight;
- } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
- annotationMode = CAnnotationTypeInk;
- } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
- annotationMode = CAnnotationTypeAnchored;
- } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- annotationMode = CAnnotationTypeSquare;
- } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
- annotationMode = CAnnotationTypeCircle;
- } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
- if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
- ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
- annotationMode = CAnnotationTypeArrow;
- } else {
- annotationMode = CAnnotationTypeLine;
- }
- } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- annotationMode = CAnnotationTypeLink;
- } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
- if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
- annotationMode = CAnnotationTypeSignFalse;
- else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
- annotationMode = CAnnotationTypeSignTure;
- else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
- annotationMode = CAnnotationTypeSignCircle;
- else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
- annotationMode = CAnnotationTypeSignLine;
- else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
- annotationMode = CAnnotationTypeSignDot;
- else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
- annotationMode = CAnnotationTypeSignDot;
- } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
- if (newAnnotation.subType == CAnnotationTypeSignText)
- annotationMode = CAnnotationTypeSignText;
- else if(newAnnotation.subType == CAnnotationTypeSignDate)
- annotationMode = CAnnotationTypeSignDate;
- } else {
- annotationMode = CAnnotationTypeStamp;
- }
- } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- annotationMode = CAnnotationTypeSignature;
- } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
- if (newAnnotation.subType == CAnnotationTypeSignText)
- annotationMode = CAnnotationTypeSignText;
- else if(newAnnotation.subType == CAnnotationTypeSignDate)
- annotationMode = CAnnotationTypeSignDate;
- } else {
- annotationMode = CAnnotationTypeFreeText;
- }
- }
- self.annotationMode = annotationMode;
- }
- - (void)setAnnotationMode:(CAnnotationType)annotationMode {
- _annotationMode = annotationMode;
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- NSString *title = @"";
- if (annotationMode == CAnnotationTypeFreeText)
- title = NSLocalizedString(@"Text", @"Description for export");
- else if (annotationMode == CAnnotationTypeCircle)
- title = NSLocalizedString(@"Circle", @"Description for export");
- else if (annotationMode == CAnnotationTypeSquare)
- title = NSLocalizedString(@"Rectangle", @"Description for export");
- else if (annotationMode == CAnnotationTypeHighlight) {
- title = NSLocalizedString(@"Highlight", @"Description for export");
- if (_annotations.count > 1)
- title = NSLocalizedString(@"General", @"Description for export");
- }
- else if (annotationMode == CAnnotationTypeUnderline) {
- title = NSLocalizedString(@"Underline", @"Description for export");
- if (_annotations.count > 1)
- title = NSLocalizedString(@"General", @"Description for export");
- }
- else if (annotationMode == CAnnotationTypeStrikeOut)
- title = NSLocalizedString(@"Strikethrough", @"Description for export");
- else if (annotationMode == CAnnotationTypeLine)
- title = NSLocalizedString(@"Line", @"Description for export");
- else if (annotationMode == CAnnotationTypeArrow)
- title = NSLocalizedString(@"Arrow", @"Description for export");
- else if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser)
- title = NSLocalizedString(@"Freehand", @"Description for export");
- else if (annotationMode == CAnnotationTypeAnchored)
- title = NSLocalizedString(@"Note", @"Description for export");
- else if (annotationMode == CAnnotationTypeLink)
- title = NSLocalizedString(@"Link", @"Description for export");
- else if (annotationMode == CAnnotationTypeTextField)
- title = NSLocalizedString(@"Text Field", @"Description for export");
- else if (annotationMode == CAnnotationTypeCheckBox)
- title = NSLocalizedString(@"Check Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeListMenu)
- title = NSLocalizedString(@"List Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeComboBox)
- title = NSLocalizedString(@"Combo Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeRadioButton)
- title = NSLocalizedString(@"Radio Button", @"Description for export");
- else if (annotationMode == CAnnotationTypeActionButton)
- title = NSLocalizedString(@"Button", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignature)
- title = NSLocalizedString(@"Sample", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignDot)
- title = NSLocalizedString(@"Dot", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignLine)
- title = NSLocalizedString(@"Line", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignCircle)
- title = NSLocalizedString(@"Rectangle", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignFalse)
- title = NSLocalizedString(@"X", nil);
- else if (annotationMode == CAnnotationTypeSignTure)
- title = NSLocalizedString(@"Check mark", nil);
- else if (annotationMode == CAnnotationTypeSignText)
- title = NSLocalizedString(@"Text", nil);
- else if (annotationMode == CAnnotationTypeSignDate)
- title = NSLocalizedString(@"Date", nil);
- else if (annotationMode == CAnnotationTypeStamp)
- title = NSLocalizedString(@"Stamp", nil);
- else
- title = @"";
- if(_annotations.count > 1) {
- title = NSLocalizedString(@"Properties", nil);
- }
- self.titleLabel.stringValue = title;
- self.titleViewHeightConstraint.constant = 40;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
- if (annotationMode == CAnnotationTypeFreeText ||
- annotationMode == CAnnotationTypeAnchored ||
- annotationMode == CAnnotationTypeCircle ||
- annotationMode == CAnnotationTypeSquare ||
- annotationMode == CAnnotationTypeHighlight ||
- annotationMode == CAnnotationTypeUnderline ||
- annotationMode == CAnnotationTypeStrikeOut ||
- annotationMode == CAnnotationTypeLine ||
- annotationMode == CAnnotationTypeInk ||
- annotationMode == CAnnotationTypeEraser ||
- annotationMode == CAnnotationTypeArrow) {
- //处理多选
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeLink) {
- } else if (annotationMode == CAnnotationTypeRadioButton ||
- annotationMode == CAnnotationTypeCheckBox ||
- annotationMode == CAnnotationTypeTextField ||
- annotationMode == CAnnotationTypeComboBox ||
- annotationMode == CAnnotationTypeListMenu ||
- annotationMode == CAnnotationTypeActionButton) {
- if (annotationMode == CAnnotationTypeTextField) {
- KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeListMenu ||
- annotationMode == CAnnotationTypeComboBox ||
- annotationMode == CAnnotationTypeActionButton) {
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeRadioButton ||
- annotationMode == CAnnotationTypeCheckBox) {
- KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else if (annotationMode == CAnnotationTypeSignFalse ||
- annotationMode == CAnnotationTypeSignTure ||
- annotationMode == CAnnotationTypeSignCircle ||
- annotationMode == CAnnotationTypeSignLine ||
- annotationMode == CAnnotationTypeSignDot) {
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- __weak typeof(self) weakSelf = self;
- vc.callBack = ^(CAnnotationType type) {
- if (type == CAnnotationTypeSignFalse) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- }
-
- if (weakSelf.annoTypeDidChange != nil) {
- weakSelf.annoTypeDidChange(weakSelf.annotations.firstObject);
- }
- };
- } else if (annotationMode == CAnnotationTypeSignText ||
- annotationMode == CAnnotationTypeSignDate) {
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeStamp) {
- KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeSignSignature) {
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- self.titleViewHeightConstraint.constant = 0;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
- - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
- {
- _isEmptyAnnotation = isEmptyAnnotation;
- if (isEmptyAnnotation) {
- self.titleLabel.hidden = YES;
- self.emptyView.hidden = NO;
- } else {
- self.titleLabel.hidden = NO;
- self.emptyView.hidden = YES;
- }
- }
- - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
- _openPropertiesType = openPropertiesType;
- if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
- KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
- vc.mainController = self.mainController;
- vc.pdfView = self.pdfView;
- __block typeof(self) blockSelf = self;
- vc.readerModeBlock = ^(BOOL isReaderMode) {
- if (blockSelf.pageDisplayReaderMode) {
- blockSelf.pageDisplayReaderMode(isReaderMode);
- }
- };
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
- self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
- } else if (openPropertiesType == KMOpenPropertiesType_Link) {
- self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
- KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
- self.propertiesBox.contentView = vc.view;
- } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
- openPropertiesType == KMOpenPropertiesType_ComboBox ||
- openPropertiesType == KMOpenPropertiesType_Button) {
-
- } else if (openPropertiesType == KMOpenPropertiesType_FormSignatureClick) {
- self.contentViewController = nil;
- self.titleLabel.stringValue = @"";
-
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- vc.isClickSignatureList = YES;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
- if (_annotations.count <= 0) {
- return;
- }
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- if (isContinuousAddStamp) {
- self.titleViewHeightConstraint.constant = 0;
- }
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- if (isContinuousAddStamp) {
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- self.titleViewHeightConstraint.constant = 0;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
- }
- + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
- if (!annotation) {
- return 0;
- }
- if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
- [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
- return 0;
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- return 0;
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
- return 279;
- } else {
- return 279;
- }
- }
- + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
- if (CAnnotationTypeSignature == annotationMode ||
- CAnnotationTypeUnkown == annotationMode) {
- return 0;
- }
- return 279;
- }
- #pragma mark - Private Method
- - (CGRect)viewControllerRect {
- CGFloat viewFloat = 0;
- if (_buttonView == nil || self.gradientView == nil) {
- return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
- }
- if (_buttonView.hidden) {
- viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
- } else {
- viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
- }
- return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
- }
- - (void)updateFormContentButtonUI:(NSButton *)button {
- self.clickBtn = button;
-
- switch (button.tag) {
- case 100:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
-
- if([KMAppearance isDarkMode]) {
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- case 101:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
-
- if([KMAppearance isDarkMode]) {
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- case 102:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
-
- if([KMAppearance isDarkMode]) {
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- default:
- break;
- }
- }
- #pragma mark - NSButton Action
- - (IBAction)fromContentButtonAction:(NSButton *)sender {
- [self updateFormContentButtonUI:sender];
-
- self.tipsView.hidden = YES;
-
- switch (sender.tag) {
- case 100:
- {
- self.lastLineImageView.hidden = NO;
- self.oneLineImageView.hidden = YES;
- [self formGeneralProperties];
- }
- break;
- case 101:
- {
- self.lastLineImageView.hidden = YES;
- self.oneLineImageView.hidden = YES;
- [self formAppearanceProperties];
- }
- break;
- case 102:
- {
- self.lastLineImageView.hidden = YES;
- self.oneLineImageView.hidden = NO;
- [self formOptionProperties];
- }
- break;
- default:
- break;
- }
- }
- - (void)formGeneralProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- - (void)formAppearanceProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == 0) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- - (void)formOptionProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
- self.tipsView.hidden = NO;
- 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)];;
- } else {
- self.tipsView.hidden = YES;
- }
- KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
- self.tipsView.hidden = YES;
- self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
- KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- @end
|