1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305 |
- //
- // KMGeneralAnnotationViewController.m
- // SignFlow
- //
- // Created by wanjun on 2021/6/15.
- //
- #import "KMGeneralAnnotationViewController.h"
- #import "KMColorPickerViewController.h"
- #import <PDF_Master-Swift.h>
- @interface KMGeneralAnnotationViewController () <NSTextViewDelegate, NSPopoverDelegate, KMSelectPopButtonDelegate>
- @property (assign) IBOutlet NSView *generalImageBoxView;
- @property (assign) IBOutlet NSImageView *generalImageView;
- @property (weak) IBOutlet NSView *mianView;
- @property (weak) IBOutlet NSLayoutConstraint *generaImageTopLayoutConstraint;
- @property (weak) IBOutlet NSView *inkView;
- @property (weak) IBOutlet NSButton *addInkButton;
- @property (weak) IBOutlet NSButton *clearInkButton;
- @property (assign) IBOutlet NSView *fontView; //字体
- @property (assign) IBOutlet NSTextField *fontLabel;
- @property (assign) IBOutlet NSButton *fontButton;
- @property (assign) IBOutlet NSBox *fontNameBox;
- @property (assign) IBOutlet NSBox *fontSizeBox;
- @property (assign) IBOutlet NSBox *fontStyleBox;
- @property (assign) IBOutlet NSBox *leftAlignBox;
- @property (assign) IBOutlet NSBox *centerAlignBox;
- @property (assign) IBOutlet NSBox *rightAlignBox;
- @property (assign) IBOutlet NSBox *fontBox;
- @property (assign) IBOutlet KMGeneralButton *fontColorButton;
- @property (assign) IBOutlet NSButton *fontCustomColorButton;
- @property (assign) IBOutlet NSLayoutConstraint *fontViewTopConstraint;
- @property (weak) IBOutlet NSLayoutConstraint *fontDefaultTopConstraint;
- @property (weak) IBOutlet NSBox *moreBox;
- @property (weak) IBOutlet NSBox *textPresuppositionContentBox;
- @property (weak) IBOutlet NSView *defaultFontView;
- @property (assign) IBOutlet NSView *fillColorView; //填充颜色
- @property (assign) IBOutlet NSTextField *fillColorLabel;
- @property (assign) IBOutlet NSBox *fillColorBox;
- @property (assign) IBOutlet KMColorPickerViewController *fillColorPickerVC;
- @property (assign) IBOutlet NSLayoutConstraint *fillColorViewTopConstraint;
- @property (weak) IBOutlet NSButton *fillButton;
- //填充
- @property (assign) IBOutlet NSView *opacityView; //透明度
- @property (assign) IBOutlet NSSlider *opacitySlider;
- @property (assign) IBOutlet NSComboBox *opacityComboBox;
- @property (weak) IBOutlet NSButton *showOpacityButton;
- @property (assign) IBOutlet NSView *borderColorView; //边框颜色
- @property (assign) IBOutlet NSTextField *borderColorLabel;
- @property (assign) IBOutlet NSBox *borderColorBox;
- @property (assign) IBOutlet KMColorPickerViewController *borderColorPickerVC;
- @property (assign) IBOutlet NSLayoutConstraint *borderColorViewTopConstraint;
- @property (assign) IBOutlet NSView *borderOpacityView; //透明度
- @property (assign) IBOutlet NSSlider *borderOpacitySlider;
- @property (assign) IBOutlet NSComboBox *borderOpacityComboBox;
- @property (weak) IBOutlet NSButton *showborderOpacityButton;
- @property (assign) IBOutlet NSView *borderWidthView; //线段宽度
- @property (assign) IBOutlet NSTextField *borderWidthLabel;
- @property (assign) IBOutlet NSSlider *borderWidthSlider;
- @property (assign) IBOutlet NSBox *borderWidthBox;
- @property (assign) IBOutlet NSLayoutConstraint *borderWidthViewTopConstraint;
- @property (strong) IBOutlet NSView *boderWidthStyleView;
- @property (weak) IBOutlet NSButton *borderWidthStyleReal;
- @property (weak) IBOutlet NSButton *borderWidthStyleDotted;
- @property (assign) IBOutlet NSLayoutConstraint *boderWidthStyleViewTopConstraint;
- @property (assign) IBOutlet NSView *rotateView; //旋转
- @property (assign) IBOutlet NSTextField *rotateLabel;
- @property (assign) IBOutlet NSBox *leftRotateBox;
- @property (assign) IBOutlet NSBox *rightRotateBox;
- @property (assign) IBOutlet NSLayoutConstraint *rotateViewTopConstraint;
- @property (assign) IBOutlet NSView *noteView; //笔记
- @property (assign) IBOutlet NSTextField *noteViewLabel;
- @property (assign) IBOutlet NSBox *noteTextBox;
- @property (assign) IBOutlet NSTextView *noteTextView;
- @property (assign) IBOutlet NSLayoutConstraint *noteViewTopConstraint;
- @property (assign) IBOutlet NSView *backgroundView;
- @property (assign) IBOutlet NSTextField *backgroundLabel;
- @property (assign) IBOutlet NSBox *backgroundBox;
- @property (assign) IBOutlet KMColorPickerViewController *backgroundColorPickerVC;
- @property (assign) IBOutlet NSLayoutConstraint *backgroundTopConstraint;
- @property (weak) IBOutlet NSLayoutConstraint *figureTopConstraint;
- @property (weak) IBOutlet NSView *figureView;
- @property (weak) IBOutlet NSBox *squareBox;
- @property (weak) IBOutlet NSBox *circleBox;
- @property (weak) IBOutlet NSBox *arrowBox;
- @property (weak) IBOutlet NSBox *lineBox;
- @property (assign) IBOutlet NSView *typeView;
- @property (assign) IBOutlet NSTextField *typeLabel;
- @property (assign) IBOutlet NSButton *tureTypeButton;
- @property (assign) IBOutlet NSButton *falseTypeButton;
- @property (assign) IBOutlet NSButton *circletypeButton;
- @property (assign) IBOutlet NSButton *lineTypeButton;
- @property (assign) IBOutlet NSButton *dotTypeButton;
- @property (assign) IBOutlet NSLayoutConstraint *typeTopConstraint;
- @property (assign) IBOutlet NSView *dateView;
- @property (assign) IBOutlet NSTextField *dateLabel;
- @property (assign) IBOutlet KMPopUpButton *datePopupButton;
- @property (assign) IBOutlet NSButton *dateButton;
- @property (assign) IBOutlet NSLayoutConstraint *dateTopConstraint;
- @property (weak) IBOutlet NSView *noteStyleView;
- @property (weak) IBOutlet NSTextField *noteStyleTextField;
- @property (weak) IBOutlet NSLayoutConstraint *noteStyleTopConstraint;
- @property (weak) IBOutlet NSButton *noteStyleNoneButton;
- @property (weak) IBOutlet NSButton *noteStyleButton1;
- @property (weak) IBOutlet NSButton *noteStyleButton2;
- @property (weak) IBOutlet NSButton *noteStyleButton3;
- @property (weak) IBOutlet NSButton *noteStyleButton4;
- @property (weak) IBOutlet NSButton *noteStyleButton5;
- @property (weak) IBOutlet NSButton *noteStyleButton6;
- @property (nonatomic, assign) CAnnotationType selfSignType;
- @property (nonatomic, retain) NSMutableArray*fonts;
- @property (nonatomic, assign) CAnnotationType annotationType;
- @property (nonatomic, retain) KMGeneralAnnotationViewController * annotationViewController;
- @property (nonatomic, retain) NSPopover *fillColorPopover;
- @property (nonatomic, retain) NSPopover *borderColorPopover;
- @property (nonatomic, retain) KMDesignPropertySelector *leftAlignVC;
- @property (nonatomic, retain) KMDesignPropertySelector *centerAlignVC;
- @property (nonatomic, retain) KMDesignPropertySelector *rightAlignVC;
- @property (nonatomic, retain) KMDesignPropertySelector *leftRotateVC;
- @property (nonatomic, retain) KMDesignPropertySelector *rightRotateVC;
- @property (nonatomic, retain) KMDesignSelect *textPresuppositionVC;
- @property (nonatomic, retain) KMDesignPropertySelector *textPresuppositionResetVC;
- @property (nonatomic, retain) KMDesignSelect *fontNameVC;
- @property (nonatomic, retain) KMDesignSelect *fontSizeVC;
- @property (nonatomic, retain) KMDesignSelect *fontStyleVC;
- @property (nonatomic, retain) KMDesignSelect *borderWidthVC;
- @property (nonatomic, retain) KMDesignPropertySelector *squareVC;
- @property (nonatomic, retain) KMDesignPropertySelector *circleVC;
- @property (nonatomic, retain) KMDesignPropertySelector *arrowVC;
- @property (nonatomic, retain) KMDesignPropertySelector *lineVC;
- //文字缓存
- @property (nonatomic, assign) NSInteger fontSize;
- @property (nonatomic, strong) NSString *fontName;
- @property (nonatomic, strong) NSString *fontStyle;
- @end
- @implementation KMGeneralAnnotationViewController
- #pragma mark - init Method
- - (void)dealloc {
- if (_annotationModel.annotation &&
- _annotationModel.annotations.count == 1) {
- NSArray *keys = @[@"contents",@"markupText"];
- for (NSString *key in keys) {
- [_annotationModel.annotation removeObserver:self forKeyPath:key];
- }
- }
- [[NSColorPanel sharedColorPanel] setTarget:nil];
- [[NSColorPanel sharedColorPanel] setAction:nil];
- [[NSColorPanel sharedColorPanel] orderOut:nil];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- -(void)viewDidAppear
- {
- [super viewDidAppear];
-
- BOOL showConvertDetails = [KMPropertiesViewPopController showChangeColorDetails];
- if (showConvertDetails && [(NSDocument *)self.view.window.windowController.document fileURL]) {
- [[KMPropertiesViewPopController defaultManager] showChangeColorDetailsView:self.fillColorPickerVC.firstBox];
- }
- }
- #pragma mark - View Methods
- - (void)loadView {
- [super loadView];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- if([NSColorPanel sharedColorPanel].visible) {
- [[NSColorPanel sharedColorPanel] close];
- }
- });
-
- self.fonts = [CPDFAnnotationModel supportFonts];
- [self loadingUIAndLocalization];
-
- if (_annotationModel.annotation &&
- _annotationModel.annotations.count == 1) {
- CPDFAnnotation *annotation = _annotationModel.annotation;
- NSArray *keys = @[@"contents",@"markupText"];
- for (NSString *key in keys) {
- [annotation addObserver:self forKeyPath:key options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];
- }
- }
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alignmentTypeNotification:) name:@"KMAnnotationAlignmentTypeNotification1" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadingUIAndLocalization) name:@"KMPreferenceDidChangeNotificationName" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(annotationChangeNotification:) name:CPDFListViewAnnotationsAttributeHasChangeNotification object:nil];
- }
- - (void)loadingUIAndLocalization
- {
- self.view.wantsLayer = YES;
- self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
-
- self.annotationType = self.annotationModel.annotationType;
- _generalImageBoxView.wantsLayer = YES;
- _generalImageBoxView.layer.borderColor = [NSColor colorWithRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1].CGColor;
- _generalImageBoxView.layer.borderWidth = 1.0f;
- _generalImageBoxView.layer.cornerRadius = 4;
-
- NSColor *color = [NSColor whiteColor];
- if (CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeSignDot == _annotationType ||
- CAnnotationTypeSignCircle == _annotationType ||
- CAnnotationTypeSignLine == _annotationType ||
- CAnnotationTypeSignTure == _annotationType ||
- CAnnotationTypeSignFalse == _annotationType) {
- if (@available(macOS 10.14, *)) {
- NSAppearanceName appearanceName = [[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
- if ([appearanceName isEqualToString:NSAppearanceNameDarkAqua]) {
- color = [NSColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.15];
- }
- }
- }
-
- _generalImageBoxView.layer.backgroundColor = color.CGColor;
- _generalImageBoxView.layer.cornerRadius = 6.0f;
-
- _fontLabel.stringValue = NSLocalizedString(@"Fonts", nil);
- _fillColorLabel.stringValue = NSLocalizedString(@"Fill", nil);
- _borderColorLabel.stringValue = NSLocalizedString(@"Border", nil);
- _borderWidthLabel.stringValue = NSLocalizedString(@"Line", nil);
- _rotateLabel.stringValue = NSLocalizedString(@"Rotate", nil);
- _noteViewLabel.stringValue = NSLocalizedString(@"Note", nil);
- _typeLabel.stringValue = NSLocalizedString(@"Type", nil);
- _dateLabel.stringValue = NSLocalizedString(@"Date", nil);
- _backgroundLabel.stringValue = NSLocalizedString(@"Background Color", nil);
- _dateButton.title = NSLocalizedString(@"Time", nil);
- _noteStyleTextField.stringValue = NSLocalizedString(@"Style", nil);
-
- _fontLabel.textColor =
- _fillColorLabel.textColor =
- _borderColorLabel.textColor =
- _borderWidthLabel.textColor =
- _rotateLabel.textColor =
- _noteViewLabel.textColor =
- _dateLabel.textColor =
- _typeLabel.textColor =
- _noteStyleTextField.textColor =
- _backgroundLabel.textColor = [NSColor colorWithRed:97.0/255.0 green:100.0/255.0 blue:105.0/255.0 alpha:1];
-
- _fillColorBox.contentView = _fillColorPickerVC.view;
- _borderColorBox.contentView = _borderColorPickerVC.view;
-
- _noteTextView.backgroundColor = [NSColor whiteColor];
- _opacityComboBox.wantsLayer =
- _borderOpacityComboBox.wantsLayer =
- _falseTypeButton.wantsLayer =
- _tureTypeButton.wantsLayer =
- _circletypeButton.wantsLayer =
- _lineTypeButton.wantsLayer =
- _dotTypeButton.wantsLayer = YES;
- _opacityComboBox.layer.backgroundColor =
- _borderOpacityComboBox.layer.backgroundColor = [NSColor clearColor].CGColor;
- _fontBox.borderColor = [NSColor colorWithRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1];
- _fontBox.fillColor = [NSColor clearColor];
-
- _opacityComboBox.layer.borderWidth =
- _noteTextBox.borderWidth = 0.5f;
-
- _opacityComboBox.layer.borderColor = [NSColor grayColor].CGColor;
- _noteTextBox.borderColor = [NSColor grayColor];
-
- _leftRotateBox.borderColor =
- _rightRotateBox.borderColor = [NSColor grayColor];
-
- _opacityComboBox.layer.cornerRadius =
- _falseTypeButton.layer.cornerRadius =
- _tureTypeButton.layer.cornerRadius =
- _circletypeButton.layer.cornerRadius =
- _lineTypeButton.layer.cornerRadius =
- _dotTypeButton.layer.cornerRadius= 5.0f;
-
- _leftAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _centerAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _rightAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _leftAlignBox.fillColor = [NSColor clearColor];
- _leftAlignBox.contentView = _leftAlignVC.view;
- _leftAlignVC.target = self;
- _leftAlignVC.action = @selector(leftAlignButtonAction:);
- _leftAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_left"];
- _centerAlignBox.fillColor = [NSColor clearColor];
- _centerAlignBox.contentView = _centerAlignVC.view;
- _centerAlignVC.target = self;
- _centerAlignVC.action = @selector(centerAlignButtonAction:);
- _centerAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_center"];
- _rightAlignBox.fillColor = [NSColor clearColor];
- _rightAlignBox.contentView = _rightAlignVC.view;
- _rightAlignVC.target = self;
- _rightAlignVC.action = @selector(rightAlignButtonAction:);
- _rightAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_right"];
-
- _leftRotateVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _rightRotateVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _leftRotateBox.fillColor = [NSColor clearColor];
- _leftRotateBox.contentView = _leftRotateVC.view;
- _rightRotateBox.fillColor = [NSColor clearColor];
- _rightRotateBox.contentView = _rightRotateVC.view;
-
- //textPresupposition
- _textPresuppositionVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
- _textPresuppositionContentBox.contentView = _textPresuppositionVC.view;
- _textPresuppositionContentBox.fillColor = [NSColor clearColor];
- [_textPresuppositionVC addItemsWithObjectValues: [KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [_textPresuppositionVC selectItemAt:0];
- _textPresuppositionVC.delete = self;
-
- _textPresuppositionResetVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _moreBox.contentView = _textPresuppositionResetVC.view;
- _moreBox.fillColor = [NSColor clearColor];
- _textPresuppositionResetVC.target = self;
- _textPresuppositionResetVC.action = @selector(resetTextPresuppositionButtonAction:);
- _textPresuppositionResetVC.image = [NSImage imageNamed:@"KMImagePropertPanelTextDefaultMore"];
-
- _fontNameVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
- _fontStyleVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
- _fontSizeVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
- NSMutableArray *fontNames = [NSMutableArray array];
- for (NSDictionary *font in [CPDFAnnotationModel supportFonts]) {
- NSString *fontName = font.allKeys.firstObject;
- [fontNames addObject:fontName];
- }
- _fontNameBox.fillColor = [NSColor clearColor];
- _fontNameBox.contentView = _fontNameVC.view;
- [_fontNameVC removeAllItems];
- [_fontNameVC addItemsWithObjectValues:fontNames];
- [_fontNameVC selectItemAt:0];
- _fontNameVC.delete = self;
-
- NSArray *fontnames = [_annotationModel.fontName componentsSeparatedByString:@"-"];
- NSFont *currentFont = [NSFont systemFontOfSize:12.0];
- if ([fontnames.lastObject isEqualToString:@"Regular"]) {
- currentFont = [NSFont fontWithName:fontnames.firstObject size:_annotationModel.fontSize];
- } else {
- currentFont = [NSFont fontWithName:_annotationModel.fontName size:_annotationModel.fontSize];
- }
- _fontStyleBox.fillColor = [NSColor clearColor];
- _fontStyleBox.contentView = _fontStyleVC.view;
- NSArray *styles = [currentFont km_styles];
- [_fontStyleVC addItemsWithObjectValues:styles];
- [_fontStyleVC selectItemAt:0];
- _fontStyleVC.delete = self;
- _fontSizeBox.fillColor = [NSColor clearColor];
- _fontSizeBox.contentView = _fontSizeVC.view;
- [_fontSizeVC removeAllItems];
- [_fontSizeVC addItemsWithObjectValues:@[@"8pt", @"9pt", @"10pt", @"11pt", @"12pt", @"14pt", @"16pt", @"18pt", @"20pt", @"22pt", @"24pt", @"26pt", @"28pt", @"36pt", @"48pt", @"72pt"]];
- [_fontSizeVC selectItemAt:0.0];
- _fontSizeVC.delete = self;
-
- _borderWidthVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
- _borderWidthBox.fillColor = [NSColor clearColor];
- _borderWidthBox.contentView = _borderWidthVC.view;
- [_borderWidthVC removeAllItems];
- if(_annotationModel.annotationType == CAnnotationTypeEraser) {
- self.borderWidthSlider.minValue = 5;
- [_borderWidthVC addItemsWithObjectValues:@[@"5pt", @"6pt", @"8pt", @"10pt", @"12pt"]];
- } else {
- [_borderWidthVC addItemsWithObjectValues:@[@"1pt", @"2pt", @"4pt", @"6pt", @"8pt"]];
- }
- [_borderWidthVC selectItemAt:0.0];
- _borderWidthVC.delete = self;
-
- _squareVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _circleVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _arrowVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _lineVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
- _squareBox.fillColor = [NSColor clearColor];
- _squareBox.contentView = _squareVC.view;
- _squareVC.target = self;
- _squareVC.action = @selector(updateFigurateModelAction:);
- _squareVC.image = [NSImage imageNamed:@"KMImageNameMainToolSquare"];
- _squareVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolSquareSelect"];
- _circleBox.fillColor = [NSColor clearColor];
- _circleBox.contentView = _circleVC.view;
- _circleVC.target = self;
- _circleVC.action = @selector(updateFigurateModelAction:);
- _circleVC.image = [NSImage imageNamed:@"KMImageNameMainToolRectangle"];
- _circleVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolRectangle"];
- _arrowBox.fillColor = [NSColor clearColor];
- _arrowBox.contentView = _arrowVC.view;
- _arrowVC.target = self;
- _arrowVC.action = @selector(updateFigurateModelAction:);
- _arrowVC.image = [NSImage imageNamed:@"KMImageNameMainToolShapes"];
- _arrowVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolShapesSelect"];
- _lineBox.fillColor = [NSColor clearColor];
- _lineBox.contentView = _lineVC.view;
- _lineVC.target = self;
- _lineVC.action = @selector(updateFigurateModelAction:);
- _lineVC.image = [NSImage imageNamed:@"KMImageNameMainToolStraightLine"];
- _lineVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolStraightLineSelect"];
- [self configureUIView];
-
- if (CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeSignText == _annotationType ||
- CAnnotationTypeSignDate == _annotationType ) {
- self.fillColorPickerVC.isFreeText = YES;
- } else {
- self.fillColorPickerVC.isFreeText = NO;
- }
-
- _datePopupButton.type = KMPopUpButtonTypeArrowUpDown;
-
- self.generalImageView.image = [self.annotationModel annotationImage];
- if (CAnnotationTypeSignFalse != _annotationType &&
- CAnnotationTypeSignTure != _annotationType &&
- CAnnotationTypeSignDot != _annotationType &&
- CAnnotationTypeSignLine != _annotationType &&
- CAnnotationTypeSignCircle != _annotationType &&
- CAnnotationTypeSignDate != _annotationType) {
- if (CAnnotationTypeStamp == _annotationType ||
- CAnnotationTypeInk == _annotationType ||
- CAnnotationTypeSquare == _annotationType ||
- CAnnotationTypeCircle == _annotationType ||
- CAnnotationTypeArrow == _annotationType ||
- CAnnotationTypeLine == _annotationType ||
- CAnnotationTypeHighlight == _annotationType ||
- CAnnotationTypeUnderline == _annotationType ||
- CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeStrikeOut == _annotationType) {
- self.noteView.hidden = YES;
- } else {
- self.noteView.hidden = self.annotationModel.annotation==nil;
- }
- }
- //全部便签都隐藏
- self.noteView.hidden = YES;
-
- if (self.annotationModel.annotations.count > 1) {
- self.noteView.hidden = YES;
- }
- self.noteTextView.wantsLayer = YES;
- if (self.annotationModel.annotation) {
- CPDFAnnotation *annotation = self.annotationModel.annotation;
-
- NSString *contextString = annotation.contents ? : @"";
- if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- contextString = [(CPDFMarkupAnnotation *)annotation markupContent];
- }
- self.noteTextView.string = contextString?:@"";
- self.noteTextView.textColor = [NSColor labelColor];
- self.noteTextView.delegate = self;
- }
- self.opacityView.wantsLayer = YES;
- self.opacityView.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.opacityView.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.16].CGColor;
- self.opacityView.layer.shadowOffset = NSMakeSize(0, 2);
- self.opacityView.layer.cornerRadius = 5;
-
- self.borderOpacityView.wantsLayer = YES;
- self.borderOpacityView.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.borderOpacityView.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.16].CGColor;
- self.borderOpacityView.layer.shadowOffset = NSMakeSize(0, 2);
- self.borderOpacityView.layer.cornerRadius = 5;
- }
- #pragma mark - private
- - (void)hiddenSubviews {
- if(self.generalImageBoxView.hidden) {
- self.generaImageTopLayoutConstraint.constant = -(self.generalImageBoxView.bounds.size.height) - (self.inkView.bounds.size.height);
- } else {
- self.generaImageTopLayoutConstraint.constant = self.inkView.hidden ? -(self.inkView.bounds.size.height) : 16.0f;
- }
-
- self.fontDefaultTopConstraint.constant = self.defaultFontView.hidden ? -(self.defaultFontView.bounds.size.height) : 16.0f;
- self.figureTopConstraint.constant = self.figureView.hidden ? -(self.figureView.bounds.size.height) : 8.0f;
- self.fontViewTopConstraint.constant = self.fontView.hidden ? -(self.fontView.bounds.size.height) : 8.0f;
- self.fillColorViewTopConstraint.constant = self.fillColorView.hidden ? -(self.fillColorView.bounds.size.height) : 8.0f;
- self.borderColorViewTopConstraint.constant = self.borderColorView.hidden ? -(self.borderColorView.bounds.size.height) : 8.0f;
- self.borderWidthViewTopConstraint.constant = self.borderWidthView.hidden ? -(self.borderWidthView.bounds.size.height) : 0.0f;
- self.boderWidthStyleViewTopConstraint.constant = self.boderWidthStyleView.hidden ? -(self.boderWidthStyleView.bounds.size.height) : 16.0f;
- self.rotateViewTopConstraint.constant = self.rotateView.hidden ? -(self.rotateView.bounds.size.height) : 16.0f;
- self.noteViewTopConstraint.constant = self.noteStyleView.hidden ? -(self.rotateView.bounds.size.height) : 16.0f;
- self.noteViewTopConstraint.constant = self.noteView.hidden ? -(self.noteView.bounds.size.height) : 16.0f;
- self.backgroundTopConstraint.constant = self.backgroundView.hidden ? -(self.backgroundView.bounds.size.height) : 16.0f;
- self.typeTopConstraint.constant = self.typeView.hidden ? -(self.typeView.bounds.size.height) : 16.0f;
- self.dateTopConstraint.constant = self.dateView.hidden ? -(self.dateView.bounds.size.height) : 16.0f;
- self.noteStyleTopConstraint.constant = self.noteStyleView.hidden ? -(self.noteStyleView.bounds.size.height) : 8.0f;
- }
- - (void)configureUIView
- {
- [self updateOpacityView];
- if (!self.annotationModel.annotation) {
- self.noteView.hidden = YES;
- }
-
- if (_annotationType == CAnnotationTypeInk || _annotationType == CAnnotationTypeEraser) {
- if (self.annotationModel.annotations.count > 0) {
- self.inkView.hidden = YES;
- [self updateInkAction:self.addInkButton];
- } else {
- self.inkView.hidden = NO;
- if (_annotationType == CAnnotationTypeInk) {
- [self updateInkAction:self.addInkButton];
- } else {
- [self updateInkAction:self.clearInkButton];
- }
- }
- } else {
- self.inkView.hidden = YES;
- }
-
- if (self.annotationModel.annotations.count > 1) {
- self.generalImageBoxView.hidden = YES;
- } else {
- self.generalImageBoxView.hidden = NO;
- }
-
- self.noteStyleView.hidden = YES;
- self.borderOpacityView.hidden = YES;
- switch (_annotationType) {
- case CAnnotationTypeHighlight:
- case CAnnotationTypeUnderline:
- case CAnnotationTypeStrikeOut:
- {
- self.fontView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.figureView.hidden = YES;
- self.noteView.hidden = YES;
-
- [self createMarkupProperties];
- [self updateFillColorPickerVC];
- }
- break;
- case CAnnotationTypeInk:
- case CAnnotationTypeLine:
- case CAnnotationTypeArrow:
- {
- self.fontView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.fillColorView.hidden = NO;
- self.boderWidthStyleView.hidden = NO;
- self.defaultFontView.hidden = YES;
- self.noteView.hidden = YES;
- if(_annotationType != CAnnotationTypeInk && self.pdfView.annotationType != CAnnotationTypeUnkown) {
- self.figureView.hidden = NO;
- [self updateFigureModel];
- } else {
- self.figureView.hidden = YES;
- }
- if (_annotationType == CAnnotationTypeLine || _annotationType == CAnnotationTypeArrow) {
- _fillColorLabel.stringValue = NSLocalizedString(@"Border Style", nil);
- }
- [self createInkAndLineProperties];
- [self updateBorderWidthView];
- [self updateFillColorPickerVC];
- }
- break;
- case CAnnotationTypeEraser:
- {
- self.fontView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.fillColorView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.figureView.hidden = YES;
- [self hiddenSubviews];
- [self updateBorderWidthView];
- }
- break;
- case CAnnotationTypeAnchored:
- {
- self.fontView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.noteStyleView.hidden = NO;
- self.figureView.hidden = YES;
-
- _fillColorLabel.stringValue = NSLocalizedString(@"Color", nil);
- [self createTextProperties];
- [self updateFillColorPickerVC];
- }
- break;
- case CAnnotationTypeCircle:
- case CAnnotationTypeSquare:
- {
- self.fontView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.defaultFontView.hidden = YES;
- if(self.pdfView.annotationType != CAnnotationTypeUnkown) {
- self.figureView.hidden = NO;
- [self updateFigureModel];
- } else {
- self.figureView.hidden = YES;
- }
- if (_annotationType == CAnnotationTypeCircle) {
- _borderColorLabel.stringValue = NSLocalizedString(@"Border Style", nil);
- }
- self.borderColorView.hidden = NO;
- self.borderOpacityView.hidden = NO;
-
- if ((_annotationType == CAnnotationTypeCircle || _annotationType == CAnnotationTypeSquare) && _annotationModel.annotations.count > 1) {
- BOOL otherType = NO;
- for (CPDFAnnotation *annotation in _annotationModel.annotations) {
- if ([annotation.type isEqualToString:@"Line"] || [annotation.type isEqualToString:@"Arrow"]) {
- otherType = YES;
- }
- }
- if (otherType) {
- self.fillColorView.hidden = YES;
- }
- }
-
- [self createSquareAndCircleProperties];
- [self updateBorderOpacityView];
- [self updateBorderWidthView];
- [self updateFillColorPickerVC];
- [self updateBorderColorPickerVC];
- [self updateFigureModel];
- }
- break;
- case CAnnotationTypeFreeText:
- case CAnnotationTypeSignText:
- {
- self.borderColorView.hidden = YES;
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.rotateView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.figureView.hidden = YES;
-
- _fillColorLabel.stringValue = NSLocalizedString(@"Fill", nil);
- [self createFreeTextProperties];
- [self updateFillColorPickerVC];
- // [self updateFontView];
- [self selectTextAnnotation];
- }
- break;
- case CAnnotationTypeStamp:
- {
- self.fontView.hidden = YES;
- self.fillColorView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.rotateView.hidden = YES;
- self.typeView.hidden = YES;
- self.dateView.hidden = YES;
- self.opacityView.hidden = YES;
- self.noteView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.figureView.hidden = YES;
-
- [self createStampProperties];
- }
- break;
- case CAnnotationTypeSignDate:
- self.fillColorView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- self.typeView.hidden = YES;
- self.rotateView.hidden = YES;
- self.noteView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.figureView.hidden = YES;
-
- [self createSelfSignFreeTextProperties];
- [self updateBackgroundColorPickerVC];
- // [self updateFontView];
- [self updateDateView];
- break;
- case CAnnotationTypeSignLine:
- case CAnnotationTypeSignDot:
- case CAnnotationTypeSignCircle:
- case CAnnotationTypeSignTure:
- case CAnnotationTypeSignFalse:
- self.fontView.hidden = YES;
- self.borderColorView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.rotateView.hidden = YES;
- self.dateView.hidden = YES;
- self.noteView.hidden = YES;
- self.defaultFontView.hidden = YES;
- self.figureView.hidden = YES;
- if (_pdfView.annotationType == CAnnotationTypeSignDot) {
- self.borderWidthView.hidden = YES;
- self.boderWidthStyleView.hidden = YES;
- }
-
- self.typeView.hidden = self.annotationModel.annotation == nil;
- [self createSelfSignProperties];
- break;
- default:
- break;
- }
- }
- - (void)alignmentTypeSelected:(NSTextAlignment)type {
- self.leftAlignVC.state = KMDesignTokenStateNorm;
- self.centerAlignVC.state = KMDesignTokenStateNorm;
- self.rightAlignVC.state = KMDesignTokenStateNorm;
- if (type == NSTextAlignmentLeft) {
- self.leftAlignVC.state = KMDesignTokenStateSel;
- } else if (type == NSTextAlignmentCenter) {
- self.centerAlignVC.state = KMDesignTokenStateSel;
- } else if (type == NSTextAlignmentRight) {
- self.rightAlignVC.state = KMDesignTokenStateSel;
- }
- }
- - (void)updateOpacityView
- {
- CGFloat opacity = self.annotationModel.opacity;
- if(self.annotationModel.annotations.count > 1) {
- opacity = self.annotationModel.annotation.opacity;
- }
- if (CAnnotationTypeCircle == _annotationType ||
- CAnnotationTypeSquare == _annotationType) {
- opacity = self.annotationModel.interiorOpacity;
- } else if (CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeSignDate == _annotationType ||
- CAnnotationTypeSignText == _annotationType ) {
- opacity = self.annotationModel.interiorOpacity;
- }
- self.opacitySlider.floatValue = opacity;
- self.opacitySlider.toolTip = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
- self.opacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
-
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- //边框颜色
- - (void)updateBorderOpacityView {
- CGFloat opacity = self.annotationModel.opacity;
- if(self.annotationModel.annotations.count > 1) {
- opacity = self.annotationModel.annotation.opacity;
- }
- self.borderOpacitySlider.floatValue = opacity;
- self.borderOpacitySlider.toolTip = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
- self.borderOpacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
-
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- - (void)updateBorderWidthView
- {
- CGFloat lineWidth = self.annotationModel.lineWidth;
- CPDFBorderStyle stype = self.annotationModel.style;
- if(self.annotationModel.annotations.count > 1) {
- lineWidth = self.annotationModel.annotation.borderWidth;
- stype = self.annotationModel.annotation.border.style;
- }
- self.borderWidthSlider.floatValue = lineWidth;
- self.borderWidthSlider.toolTip = [NSString stringWithFormat:@"%0.1f pt",lineWidth];
- self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",lineWidth];
-
- self.generalImageView.image = [self.annotationModel annotationImage];
-
- if (self.annotationModel.annotationType == CAnnotationTypeEraser) return;
- if (stype == CPDFBorderStyleDashed) {
- self.borderWidthStyleDotted.wantsLayer = YES;
- self.borderWidthStyleDotted.layer.backgroundColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6].CGColor;
- self.borderWidthStyleDotted.layer.borderWidth = 1.0;
- self.borderWidthStyleDotted.layer.cornerRadius = 4.0;
- self.borderWidthStyleDotted.layer.borderColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:1].CGColor;
- self.borderWidthStyleReal.wantsLayer = YES;
- self.borderWidthStyleReal.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.borderWidthStyleReal.layer.borderWidth = 0;
- self.borderWidthStyleReal.layer.cornerRadius = 0;
- self.borderWidthStyleReal.layer.borderColor = [NSColor clearColor].CGColor;
- } else if (stype == CPDFBorderStyleSolid) {
- self.borderWidthStyleReal.wantsLayer = YES;
- self.borderWidthStyleReal.layer.backgroundColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6].CGColor;
- self.borderWidthStyleReal.layer.borderWidth = 1.0;
- self.borderWidthStyleReal.layer.cornerRadius = 4.0;
- self.borderWidthStyleReal.layer.borderColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:1].CGColor;
- self.borderWidthStyleDotted.wantsLayer = YES;
- self.borderWidthStyleDotted.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.borderWidthStyleDotted.layer.borderWidth = 0;
- self.borderWidthStyleDotted.layer.cornerRadius = 0;
- self.borderWidthStyleDotted.layer.borderColor = [NSColor clearColor].CGColor;
- }
- }
- - (void)updateInkAction:(NSButton *)currentButton {
- self.addInkButton.wantsLayer =
- self.inkView.wantsLayer =
- self.clearInkButton.wantsLayer = YES;
- self.addInkButton.layer.cornerRadius =
- self.inkView.layer.cornerRadius =
- self.clearInkButton.layer.cornerRadius = 4.0;
- self.addInkButton.layer.backgroundColor =
- self.inkView.layer.backgroundColor =
- self.clearInkButton.layer.backgroundColor = [NSColor colorWithSRGBRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1].CGColor;
-
- if (currentButton == self.addInkButton) {
- self.addInkButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
- [self.addInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelADDSelect"]];
- [self.clearInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelClearNone"]];
- } else if (currentButton == self.clearInkButton) {
- self.clearInkButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
- [self.addInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelADDNone"]];
- [self.clearInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelClearSelect"]];
- }
- }
- - (void)updateFillColorPickerVC
- {
- if (self.annotationModel.annotations.count > 0) {
- if (self.annotationModel.annotations.count > 1) {
- NSMutableArray *colors = [NSMutableArray array];
- for (CPDFAnnotation *annotation in self.annotationModel.annotations) {
- NSColor *color = nil;
- if ([annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- if ([annotation isKindOfClass:[CPDFCircleAnnotation class]]) {
- color = ((CPDFCircleAnnotation *)annotation).interiorColor;
- } else {
- color = ((CPDFSquareAnnotation *)annotation).interiorColor;
- }
- if (!color) {
- color = annotation.color;
- }
- self.fillColorPickerVC.isFillColor = YES;
- } else {
- color = annotation.color;
- }
- if (color) {
- [colors addObject:color];
- }
- }
- self.fillColorPickerVC.selectColors = colors;
- } else {
- NSColor *color = nil;
- CPDFAnnotation *firstAnnotation = self.annotationModel.annotations.firstObject;
- if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [firstAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
- color = ((CPDFCircleAnnotation *)firstAnnotation).interiorColor;
- } else {
- color = ((CPDFSquareAnnotation *)firstAnnotation).interiorColor;
- }
- self.fillColorPickerVC.isFillColor = YES;
- } else {
- color = firstAnnotation.color;
- }
- self.fillColorPickerVC.color = color;
- }
- } else {
- NSColor *color = nil;
- if (CAnnotationTypeCircle == _annotationType ||
- CAnnotationTypeSquare == _annotationType) {
- color = self.annotationModel.interiorColor;
- self.fillColorPickerVC.isFillColor = YES;
- } else {
- color = self.annotationModel.color;
- }
-
- if (!color) {
- color = [NSColor clearColor];
- }
- self.fillColorPickerVC.color = color;
- }
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- - (void)updateBackgroundColorPickerVC
- {
- NSColor *color = nil;
- if (CAnnotationTypeSignDate == _annotationType) {
- color = self.annotationModel.color;
- if (color) {
- CGFloat red,green,blue,alpha;
- [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
- color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.opacity];
- }
- self.backgroundColorPickerVC.color = color;
- }
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- - (void)updateBorderColorPickerVC
- {
- NSColor *color = self.annotationModel.color;
- if (self.annotationModel.annotations.count > 1) {
- CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
- color = firstAnnotation.color;
- } else {
- color = self.annotationModel.color;
- }
- self.borderColorPickerVC.color = color;
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- - (void)updateDateView
- {
- [_datePopupButton removeAllItems];
- BOOL includeTime = self.annotationModel.includeTime;
- [_datePopupButton addItemsWithTitles:[KMSelfSignAnnotationFreeText fetchAllDateStringWithIncludeTime:includeTime]];
- NSInteger dateFormatIndex = self.annotationModel.dateFormatIndex;
- if (dateFormatIndex >= 0 && dateFormatIndex < _datePopupButton.numberOfItems) {
- [_datePopupButton selectItemAtIndex:dateFormatIndex];
- } else {
- [_datePopupButton selectItemAtIndex:0];
- }
- _dateButton.state = includeTime ? NSControlStateValueOn:NSControlStateValueOff;
- }
- - (void)typeSelected:(CAnnotationType)type
- {
- _falseTypeButton.layer.backgroundColor =
- _tureTypeButton.layer.backgroundColor =
- _circletypeButton.layer.backgroundColor =
- _lineTypeButton.layer.backgroundColor =
- _dotTypeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkNor"];
- _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickNor"];
- _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRoundedrecNor"];
- _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineNor"];
- // _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointNor"];
- if (type == CAnnotationTypeSignFalse) {
- self.falseTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
- _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkSel"];
- } else if (type == CAnnotationTypeSignTure) {
- self.tureTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
- _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickSel"];
- } else if (type == CAnnotationTypeSignCircle){
- self.circletypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
- _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRounderdrecSel"];
- } else if (type == CAnnotationTypeSignLine) {
- self.lineTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
- _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineSel"];
- } else if (type == CAnnotationTypeSignDot) {
- self.dotTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
- _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointSet"];
- }
- }
- - (void)updateAnnotation
- {
- CPDFAnnotation *annotation = self.annotationModel.annotation;
- if (annotation) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
- if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
- [self.pdfView commitEditAnnotationFreeText:textNote];
- }
-
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:self.pdfView.activeAnnotations];
- annotationModel.fontName = self.annotationModel.fontName;
- [self.pdfView setNeedsDisplayAnnotation:self.pdfView.activeAnnotation];
- }
-
- for (CPDFAnnotation *tAnnotation in self.annotationModel.annotations) {
- if([tAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
- [(KMSelfSignAnnotation *)tAnnotation updateAppearanceStream];
- }
-
- if ([tAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- [self.pdfView setNeedsDisplayForPage:tAnnotation.page];
- } else {
- [self.pdfView setNeedsDisplayAnnotationViewForPage:tAnnotation.page];
- }
- }
- }
-
- self.generalImageView.image = [self.annotationModel annotationImage];
- }
- - (NSDictionary *)freeTextPropertWithTitle:(NSInteger)integer {
- NSDictionary *model;
- NSArray *array = [CPDFAnnotationModel defaultFreeTextPropert];
- // if ([string isEqualToString:@"Customize"]) {
- // model = [array objectAtIndex:0];
- // } else if ([string isEqualToString:@"H1 Headline"]) {
- // model = [array objectAtIndex:1];
- // } else if ([string isEqualToString:@"H2 Title"]) {
- // model = [array objectAtIndex:2];
- // } else if ([string isEqualToString:@"H3 Subtitle"]) {
- // model = [array objectAtIndex:3];
- // } else if ([string isEqualToString:@"B1 Text"]) {
- // model = [array objectAtIndex:4];
- // } else if ([string isEqualToString:@"B2 Small Text"]) {
- // model = [array objectAtIndex:5];
- // } else if ([string isEqualToString:@"B3 Describtion"]) {
- // model = [array objectAtIndex:6];
- // }
- model = [array objectAtIndex:integer];
- return model;
- }
- #pragma mark MarkUp
- - (void)createMarkupProperties {
- [self hiddenSubviews];
-
- _fillColorBox.contentView = _fillColorPickerVC.view;
- __block typeof(self) blockSelf = self;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- blockSelf.annotationModel.color = color;
- blockSelf.annotationModel.opacity = color.alphaComponent;
-
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
-
- if (CAnnotationTypeHighlight == _annotationType) {
- self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupHighlightColors;
- } else {
- self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupOtherColors;
- }
- }
- #pragma mark SKLineNote
- - (void)createInkAndLineProperties {
- [self hiddenSubviews];
-
- _fillColorBox.contentView = _fillColorPickerVC.view;
- __block typeof(self) blockSelf = self;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- if (color) {
- CGFloat r, g, b, a = 0.0;
- [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
-
- blockSelf.annotationModel.color = color;
- blockSelf.annotationModel.opacity = a;
- } else {
- blockSelf.annotationModel.color = [NSColor blackColor];
- blockSelf.annotationModel.opacity = 0;
- }
-
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
-
- self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
- self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
-
- if (CAnnotationTypeLine == self.annotationModel.annotationType ||
- CAnnotationTypeArrow == self.annotationModel.annotationType) {
- self.fillColorPickerVC.annotationType = KMPropertiesColor_LineColors;
-
- } else if (CAnnotationTypeInk == self.annotationModel.annotationType) {
- self.fillColorPickerVC.annotationType = KMPropertiesColor_InkColors;
- }
- }
- - (void)updateFigureModel {
- if(self.pdfView.annotationType != CAnnotationTypeUnkown) {
- if (_annotationType == CAnnotationTypeSquare) {
- self.squareVC.state = KMDesignTokenStateSel;
- } else if (_annotationType == CAnnotationTypeCircle) {
- self.circleVC.state = KMDesignTokenStateSel;
- } else if (_annotationType == CAnnotationTypeArrow) {
- self.arrowVC.state = KMDesignTokenStateSel;
- } else if (_annotationType == CAnnotationTypeLine) {
- self.lineVC.state = KMDesignTokenStateSel;
- }
- }
- }
- #pragma mark - SquareNote、CircleNote、ArrowNote Properties
- - (void)createSquareAndCircleProperties {
- [self hiddenSubviews];
-
- __block typeof(self) blockSelf = self;
- _fillColorBox.contentView = _fillColorPickerVC.view;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- CGFloat red,green,blue,alpha;
- [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
- if (fabs(alpha - 0) < 0.001) {
- blockSelf.annotationModel.interiorColor = nil;
- } else {
- blockSelf.annotationModel.interiorColor = color;
- }
- [blockSelf updateAnnotation];
- };
- _borderColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- if (color) {
- blockSelf.annotationModel.color = color;
- blockSelf.annotationModel.opacity = 1;
- } else {
- //设置透明色必须要设一个颜色值
- blockSelf.annotationModel.color = [NSColor blackColor];
- blockSelf.annotationModel.opacity = 0;
- }
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
-
- self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
- self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
- self.fillColorPickerVC.annotationType = KMPropertiesColor_LineFillColors;
- self.fillColorPickerVC.isFillColor = YES;
- self.borderColorPickerVC.annotationType = KMPropertiesColor_CircleLineColors;
- }
- #pragma mark - FreeTextNote、KMPDFAnnotationFreeText Properties
- - (void)createFreeTextProperties {
- [self hiddenSubviews];
-
- __block typeof(self) blockSelf = self;
- _fillColorBox.contentView = _fillColorPickerVC.view;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- CGFloat red,green,blue,alpha;
- [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
- if(alpha == 0) {
- blockSelf.annotationModel.color = nil;
- } else {
- blockSelf.annotationModel.color = color;
- }
- [blockSelf updateOpacityView];
- CPDFAnnotation *annotation = blockSelf.annotationModel.annotation;
- if (annotation) {
- [blockSelf.pdfView setNeedsDisplayAnnotationViewForPage:annotation.page];
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
- if ([blockSelf.pdfView isEditWithCurrentFreeText:textNote]) {
- [blockSelf.pdfView setEditAnnotationFreeTextBackgroundColor:color freeText:textNote];
- } else {
- [blockSelf updateAnnotation];
- }
- }
- blockSelf.generalImageView.image = [blockSelf.annotationModel annotationImage];
- } else {
- [blockSelf updateAnnotation];
- }
-
- };
-
- if (CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeSignDate == _annotationType ||
- CAnnotationTypeSignText == _annotationType) {
- self.fontColorButton.color = self.annotationModel.fontColor;
- [self.fontColorButton setNeedsDisplay:YES];
- }
-
- self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
- self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
- self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
-
- self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
- self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
-
- self.fillColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
- }
- #pragma mark - FreeTextNote、SelfSignAnnotationFreeText Properties
- - (void)createSelfSignFreeTextProperties {
- [self hiddenSubviews];
-
- __block typeof(self) blockSelf = self;
-
- // NSArray *array = @[blockSelf.leftAlignBox,blockSelf.centerAlignBox,blockSelf.rightAlignBox];
- // for (KMBox *box in array) {
- // box.fillColor = [NSColor clearColor];
- // box.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
- // if (downEntered) {
- // box.fillColor = [NSColor colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
- // if (box == blockSelf.leftAlignBox) {
- // [blockSelf leftAlignButtonAction:box];
- // } else if (box == blockSelf.centerAlignBox) {
- // [blockSelf centerAlignButtonAction:box];
- // } else if (box == blockSelf.rightAlignBox) {
- // [blockSelf rightAlignButtonAction:box];
- // }
- // } else {
- // box.fillColor = [NSColor clearColor];
- // }
- // };
- // box.mouseMoveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
- // if (mouseEntered) {
- // box.fillColor = [NSColor lightGrayColor];
- // } else {
- // box.fillColor = [NSColor clearColor];
- // }
- // };
- // }
- _backgroundBox.contentView = _backgroundColorPickerVC.view;
- _backgroundColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- CGFloat r, g, b, a = 0.0;
- [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- if(a == 0) {
- blockSelf.annotationModel.color = nil;
- } else {
- blockSelf.annotationModel.color = color;
- }
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
-
- if ([self.annotationModel.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- self.fontColorButton.color = self.annotationModel.fontColor;
- [self.fontColorButton setNeedsDisplay:YES];
- }
- self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
- self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
- self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
-
- NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc]initWithAttributedString:[_dateButton attributedTitle]];
- NSUInteger len = [attrTitle length];
- NSRange range = NSMakeRange(0, len);
- [attrTitle addAttribute:NSForegroundColorAttributeName
- value:[NSColor lightGrayColor]
- range:range];
- [attrTitle fixAttributesInRange:range];
- [_dateButton setAttributedTitle:attrTitle];
-
- if ([self.annotationModel.annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
- if (self.annotationModel.annotation.contents.length <= 0) {
- self.annotationModel.annotation.contents = self.datePopupButton.title;
- }
- }
- self.backgroundColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
- }
- #pragma mark - KMSelfSignAnnotation
- - (void)createSelfSignProperties {
- [self hiddenSubviews];
-
- __block typeof(self) blockSelf = self;
- _fillColorBox.contentView = _fillColorPickerVC.view;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- CGFloat r, g, b, a = 0.0;
- [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- blockSelf.annotationModel.color = color;
- blockSelf.annotationModel.opacity = a;
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
- if (self.annotationModel.annotation) {
- CAnnotationType annotationType = [(KMSelfSignAnnotation *)self.annotationModel.annotation annotationType];
- [self typeSelected:annotationType];
- }
-
- NSColor *color = self.annotationModel.color;
- CGFloat r, g, b, a = 0.0;
- [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- CGFloat opacity = self.annotationModel.opacity;
- // [self.borderWidthComboBox removeAllItems];
- // NSMutableArray *titles = @[@"1 pt",@"3 pt",@"6 pt",@"9 pt",@"12 pt"].mutableCopy;
- // for (NSString *string in titles) {
- // [self.borderWidthComboBox addItemWithObjectValue:string];
- // }
-
- self.borderWidthSlider.maxValue = 12;
- self.fillColorPickerVC.color = [NSColor colorWithRed:r green:g blue:b alpha:opacity];
- self.opacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
- self.opacitySlider.floatValue = opacity;
- self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
- self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
-
- self.fillColorPickerVC.annotationType = KMPropertiesColor_SelfSignColors;
- }
- -(NSUInteger)setFontStyleWithFontName:(NSString *)fontName currentStyle:(NSString *)style
- {
- NSUInteger selectIndex = -1;
- // NSMenu *menu = [[NSMenu alloc] init];
- NSMutableArray *fontStyles = [NSMutableArray array];
- for (NSDictionary *dic in self.fonts) {
- NSString *familyString = dic.allKeys.firstObject;
- if ([familyString isEqual:fontName]) {
- NSArray *styles = [dic objectForKey:fontName];
- for (NSUInteger i = 0; i < styles.count; i++) {
- NSString * styleName = [styles objectAtIndex:i];
- if ([style isEqualToString:styleName]) {
- selectIndex = i;
- }
- NSFontDescriptor *attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName,NSFontFaceAttribute:styleName}];
- if ([styleName isEqualToString:@"Roman"]) {
- attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName}];
- selectIndex = 0;
- }
- // NSFont *font = [NSFont fontWithDescriptor:attributeFontDescriptor size:12.0];
- // NSDictionary *attrited = @{NSFontAttributeName:font};
- // NSAttributedString *string = [[NSAttributedString alloc] initWithString:styleName attributes:attrited];
- // NSMenuItem *item = [[NSMenuItem alloc] init];
- // item.attributedTitle = string;
- // [menu addItem:item];
- [fontStyles addObject:styleName];
- }
- break;
- }
- }
- if (!style) {
- selectIndex = 0;
- }
- // [self.fontStylePopUpButton setMenu:menu];
- return selectIndex;
- }
- - (void)resetTextPresuppositionButtonAction:(NSButton *)sender {
- NSArray *popViewDataArr = @[NSLocalizedString(@"Reset", nil), NSLocalizedString(@"Redefine", nil)];
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- // NSString *type = KMEditPDFTextFontTypeWrapper.allValues[index + 1];
- KMEditPDFTextFontModel *model = KMEditPDFTextManager.manager.fetchAllUserDefaultData[index];
- NSMutableArray *disItems = [NSMutableArray arrayWithArray:popViewDataArr];
-
- if (model.change || model.redefine) {
- [disItems removeObject:NSLocalizedString(@"Reset", nil)];
- }
-
- if (model.change) {
- [disItems removeObject:NSLocalizedString(@"Redefine", nil)];
- }
-
- KMHomePopViewController *popVC = [[KMHomePopViewController alloc] initWithNibName:@"KMHomePopViewController" bundle:nil];
- popVC.dataArr = popViewDataArr;
- popVC.disItems = disItems;
-
- NSPopover *createFilePopover = [[NSPopover alloc] init];
- createFilePopover.contentViewController = popVC;
- createFilePopover.animates = true;
- createFilePopover.behavior = NSPopoverBehaviorSemitransient;
- [createFilePopover setValue: @(YES) forKey: @"shouldHideAnchor"];
- [createFilePopover showRelativeToRect:CGRectMake(sender.bounds.origin.x, -10, sender.bounds.size.width, sender.bounds.size.height)
- ofView:sender
- preferredEdge:NSRectEdgeMaxY];
- popVC.downCallback = ^(BOOL downEntered, NSString * _Nonnull count) {
- if (downEntered) {
- if ([count isEqualToString:@"Reset"]) {
- [self resetTextPresuppositionData];
- } else if([count isEqualToString:@"Redefine"]) {
- [self reDefineTextPresuppositionData:YES];
- }
- [createFilePopover close];
- }
- };
- }
- #pragma mark annotation text
- - (void)createTextProperties {
- [self hiddenSubviews];
-
- __block typeof(self) blockSelf = self;
- _fillColorBox.contentView = _fillColorPickerVC.view;
- _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
- blockSelf.annotationModel.color = color;
- [blockSelf updateOpacityView];
- [blockSelf updateAnnotation];
- };
-
- self.fillColorPickerVC.annotationType = KMPropertiesColor_AnchoredNoteColors;
-
- self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOne"];
- self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStylenote"];
- self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWord"];
- self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStyleHelp"];
- self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStyleP"];
- self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsert"];
- self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNP"];
-
- CPDFTextAnnotationIconType type = CPDFTextAnnotationIconNote;
- if (self.annotationModel.annotations.count > 0) {
- CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
- if([firstAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
- type = [(CPDFTextAnnotation *)firstAnnotation iconType];
- }
- } else {
- type = self.annotationModel.anchoredIconType;
- }
- switch (type) {
- case CPDFTextAnnotationIconComment:
- self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOneSelect"];
- break;
- case CPDFTextAnnotationIconKey:
- self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWordSelect"];
- break;
- case CPDFTextAnnotationIconNote:
- self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStyleNoteSelect"];
- break;
- case CPDFTextAnnotationIconHelp:
- self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStylehelpSelect"];
- break;
- case CPDFTextAnnotationIconNewParagraph:
- self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNPSelect"];
- break;
- case CPDFTextAnnotationIconParagraph:
- self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStylePSelect"];
- break;
- case CPDFTextAnnotationIconInsert:
- self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsertSelect"];
- break;
- default:
- break;
- }
- }
- - (void)selectTextAnnotation {
- CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
- if ([firstAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)firstAnnotation;
- // if (_annotationModel.annotations.count > 1) {
- NSFont *currentFont = textNote.font;
- NSString *fontName = [KMEditPDFTextManager.manager fetchFontNameWithFontName:currentFont.fontName];
- NSString *fontStyle = [KMEditPDFTextManager.manager fetchFontStyleWithFontName:currentFont.fontName];
- NSInteger fontSize = currentFont.pointSize;
- NSColor *color = textNote.fontColor;
- NSTextAlignment alignment = textNote.alignment;
- [self alignmentTypeSelected:alignment];
-
- [self updateFontSize:fontSize needChangeListView:NO needSave:NO];
- [self updateFontNameAndStyle:fontName style:fontStyle needChangeListView:NO needSave:NO];
-
- [self updateTextTextPresuppositionState:currentFont.fontName size:fontSize];
- // }
- } else {
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
-
- NSString *fontName = [KMEditPDFTextManager.manager fetchFontNameWithFontName:model.fontName];
- if (![self.fontNameVC.items containsObject:fontName]) {
- fontName = self.fontNameVC.items.firstObject;
- }
- NSString *fontStyle = [KMEditPDFTextManager.manager fetchFontStyleWithFontName:model.fontName];
- if (![self.fontStyleVC.items containsObject:fontStyle]) {
- fontStyle = self.fontStyleVC.items.firstObject;
- }
- CGFloat size = model.fontSize;
-
- [self updateFontSize:size needChangeListView:NO needSave:NO];
- [self updateFontNameAndStyle:fontName style:fontStyle needChangeListView:NO needSave:NO];
-
- [self alignmentTypeSelected: NSTextAlignmentLeft];
- }
- }
- #pragma mark annotation Ink
- - (IBAction)updateInkStype:(NSButton *)sender {
- self.annotationModel.style = sender.tag;
- [self updateBorderWidthView];
- [self updateAnnotation];
- }
- - (IBAction)updateInkButton_click:(NSButton *)sender {
- [self updateInkAction:sender];
- if ((sender == self.addInkButton && _annotationType == CAnnotationTypeInk) || (sender == self.clearInkButton && _annotationType == CAnnotationTypeEraser)) {
- return;
- }
- if (sender != self.addInkButton) {
- self.pdfView.annotationType = CAnnotationTypeEraser;
- [self.borderWidthVC removeAllItems];
- [self.borderWidthVC addItemsWithObjectValues:@[@"5pt",@"10pt",@"15pt",@"20pt"]];
- } else {
- [self.borderWidthVC removeAllItems];
- [self.borderWidthVC addItemsWithObjectValues:@[@"1pt",@"2pt",@"4pt",@"6pt",@"8pt"]];
- self.pdfView.annotationType = CAnnotationTypeInk;
- }
- if (self.callBack) {
- self.callBack (self.pdfView.annotationType);
- }
- self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
- [self loadingUIAndLocalization];
- }
- #pragma mark annotation stamp
- - (IBAction)showOpacityView:(id)sender {
- KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
- vc.annotationModel = self.annotationModel;
- if (!_fillColorPopover) {
- _fillColorPopover = [[NSPopover alloc] init];
- _fillColorPopover.delegate = self;
- }
- _fillColorPopover.contentViewController = vc;
- _fillColorPopover.animates = YES;
- _fillColorPopover.behavior = NSPopoverBehaviorSemitransient;
- [_fillColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
- [_fillColorPopover showRelativeToRect:NSMakeRect(_fillColorView.bounds.origin.x, 57, _fillColorView.bounds.size.width, _fillColorView.bounds.size.height) ofView:_fillColorView preferredEdge:NSRectEdgeMinY];
- vc.type = AnnotationOpacityTypeInteriorOpacity;
- __block typeof(self) blockSelf = self;
- vc.callback = ^(CGFloat opacity) {
- [blockSelf updateFillColorPickerVC];
- [blockSelf updateAnnotation];
- };
- }
- - (IBAction)showBorderOpacityView:(id)sender {
- KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
- vc.annotationModel = self.annotationModel;
- if (!_borderColorPopover) {
- _borderColorPopover = [[NSPopover alloc] init];
- _borderColorPopover.delegate = self;
- }
- _borderColorPopover.contentViewController = vc;
- _borderColorPopover.animates = YES;
- _borderColorPopover.behavior = NSPopoverBehaviorSemitransient;
- [_borderColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
- [_borderColorPopover showRelativeToRect:NSMakeRect(_borderColorView.bounds.origin.x, 47, _borderColorView.bounds.size.width, _borderColorView.bounds.size.height) ofView:_borderColorView preferredEdge:NSRectEdgeMinY];
- if (_annotationModel.annotations.count > 0) {
- CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
- if ([firstAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
- vc.type = AnnotationOpacityTypeInteriorOpacity;
- } else {
- vc.type = AnnotationOpacityTypeOpacity;
- }
- } else {
- if (_annotationModel.annotationType == CAnnotationTypeLine ||
- _annotationModel.annotationType == CAnnotationTypeArrow) {
- vc.type = AnnotationOpacityTypeInteriorOpacity;
- } else {
- vc.type = AnnotationOpacityTypeOpacity;
- }
- }
- __block typeof(self) blockSelf = self;
- vc.callback = ^(CGFloat opacity) {
- [blockSelf updateBorderColorPickerVC];
- [blockSelf updateAnnotation];
- };
- }
- - (void)createStampProperties {
- [self hiddenSubviews];
- }
- #pragma mark - UI Action
- - (IBAction)opacitySliderAction:(id)sender
- {
- CGFloat opcity = self.opacitySlider.floatValue;
- if (self.opacitySlider.floatValue == 0) {
- opcity = 0.0001;
- }
-
- CAnnotationType annotationType = self.annotationModel.annotationType;
- if (CAnnotationTypeSignFalse == annotationType ||
- CAnnotationTypeSignTure == annotationType ||
- CAnnotationTypeSignDot == annotationType ||
- CAnnotationTypeSignCircle == annotationType ||
- CAnnotationTypeSignLine == annotationType) {
- self.annotationModel.opacity = opcity;
- [self updateFillColorPickerVC];
- } else if(CAnnotationTypeCircle == annotationType ||
- CAnnotationTypeSquare == annotationType){
- if(opcity !=0) {
- self.annotationModel.opacity = opcity;
- self.annotationModel.interiorOpacity= opcity;
- } else {
- self.annotationModel.color = nil;
- self.annotationModel.interiorColor= nil;
- }
- [self updateFillColorPickerVC];
- [self updateBorderColorPickerVC];
- } else if (CAnnotationTypeFreeText == annotationType ||
- CAnnotationTypeSignDate == annotationType ||
- CAnnotationTypeSignText == annotationType ) {
- self.annotationModel.opacity = opcity;
- [self updateBackgroundColorPickerVC];
- NSColor *color = self.annotationModel.fontColor;
- if (self.annotationModel.opacity != 0) {
- CGFloat red,green,blue,alpha;
- [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
- color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.interiorOpacity];
- } else {
- color = [NSColor clearColor];
- }
- self.fontColorButton.color = color;
- [self.fontColorButton setNeedsDisplay:YES];
- } else {
- self.annotationModel.opacity = opcity;
- [self updateFillColorPickerVC];
- }
-
- [self updateOpacityView];
- [self updateAnnotation];
- }
- - (IBAction)borderOpacitySliderAction:(id)sender
- {
- CGFloat opcity = self.borderOpacitySlider.floatValue;
- if (self.borderOpacitySlider.floatValue == 0) {
- opcity = 0.0001;
- }
-
- CAnnotationType annotationType = self.annotationModel.annotationType;
- if(CAnnotationTypeCircle == annotationType ||
- CAnnotationTypeSquare == annotationType){
- if(opcity !=0) {
- self.annotationModel.opacity = opcity;
- } else {
- self.annotationModel.color = nil;
- self.annotationModel.interiorColor= nil;
- }
- [self updateFillColorPickerVC];
- [self updateBorderColorPickerVC];
- }
-
- [self updateBorderOpacityView];
- [self updateAnnotation];
- }
- - (IBAction)opacityComboBoxAction:(id)sender
- {
- [self.opacitySlider setFloatValue:(CGFloat)[self.opacityComboBox intValue]/100];
- CGFloat opcity = self.opacitySlider.floatValue;
- if (self.opacitySlider.floatValue == 0) {
- opcity = 0.0001;
- }
- CAnnotationType annotationType = self.annotationModel.annotationType;
- if (CAnnotationTypeSignFalse == annotationType ||
- CAnnotationTypeSignTure == annotationType ||
- CAnnotationTypeSignDot == annotationType ||
- CAnnotationTypeSignCircle == annotationType ||
- CAnnotationTypeSignLine == annotationType) {
- self.annotationModel.opacity = opcity;
- [self updateFillColorPickerVC];
- } else if(CAnnotationTypeCircle == annotationType ||
- CAnnotationTypeSquare == annotationType){
- if(opcity !=0) {
- self.annotationModel.opacity = opcity;
- self.annotationModel.interiorOpacity= opcity;
- } else {
- self.annotationModel.color = nil;
- self.annotationModel.interiorColor= nil;
-
- }
- [self updateFillColorPickerVC];
- [self updateBorderColorPickerVC];
- } else if (CAnnotationTypeFreeText == annotationType ||
- CAnnotationTypeSignDate == annotationType ||
- CAnnotationTypeSignText == annotationType ) {
- self.annotationModel.interiorOpacity = opcity;
- [self updateBackgroundColorPickerVC];
- } else {
- self.annotationModel.opacity = opcity;
- [self updateFillColorPickerVC];
- }
-
- [self updateOpacityView];
- [self updateAnnotation];
- }
- - (IBAction)borderWidthSliderAction:(id)sender
- {
- self.annotationModel.lineWidth = self.borderWidthSlider.floatValue;
- [self updateBorderWidthView];
- [self updateAnnotation];
- }
- - (IBAction)leftAlignButtonAction:(NSBox *)sender {
- [self updateAnnotation];
- NSTextAlignment alignment = NSTextAlignmentLeft;
- self.annotationModel.alignment = alignment;
- [self alignmentTypeSelected:alignment];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
-
- [self updateAnnotation];
- }
- - (IBAction)centerAlignButtonAction:(NSBox *)sender {
- [self updateAnnotation];
-
- NSTextAlignment alignment = NSTextAlignmentCenter;
- self.annotationModel.alignment = alignment;
- [self alignmentTypeSelected:alignment];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
-
- [self updateAnnotation];
- }
- - (IBAction)rightAlignButtonAction:(NSBox *)sender {
- [self updateAnnotation];
-
- NSTextAlignment alignment = NSTextAlignmentRight;
- self.annotationModel.alignment = alignment;
- [self alignmentTypeSelected:alignment];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
-
- [self updateAnnotation];
- }
- - (IBAction)justifiedAlignButtonAction:(NSBox *)sender {
- [self updateAnnotation];
- NSTextAlignment alignment = NSTextAlignmentJustified;
- self.annotationModel.alignment = alignment;
- [self alignmentTypeSelected:alignment];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
-
- [self updateAnnotation];
- }
- - (IBAction)currentFontColorButtonAction:(NSButton *)sender {
- KMAnnotationFontWindowController *fontWindowController = [KMAnnotationFontWindowController sharedAnnotationFont];
- // fontWindowController.PDFListView = self.pdfView;
- NSWindow *window = [fontWindowController window];
- // fontWindowController.annotationModel = self.annotationModel;
- __block typeof(self) blockSelf = self;
- fontWindowController.annotationAlignCallback = ^(NSInteger selectedCount) {
- NSTextAlignment textAlignment = NSTextAlignmentLeft;
- if (selectedCount == 0) {
- textAlignment = NSTextAlignmentLeft;
- } else if (selectedCount == 2) {
- textAlignment = NSTextAlignmentCenter;
- } else if (selectedCount == 1) {
- textAlignment = NSTextAlignmentRight;
- } else if (selectedCount == 3) {
- textAlignment = NSTextAlignmentJustified;
- }
- [blockSelf alignmentTypeSelected:selectedCount];
- if(blockSelf.annotationModel) {
- blockSelf.annotationModel.alignment = textAlignment;
- [blockSelf updateAnnotation];
- }
- };
- fontWindowController.annotationCallback = ^(CPDFAnnotation *annotation) {
- // [blockSelf updateFontView];
- [blockSelf updateAnnotation];
- };
- [window orderFront:sender];
- }
- - (IBAction)fontCustomColorButtonAction:(NSButton *)sender {
- [[NSColorPanel sharedColorPanel] setTarget:self];
- [NSColorPanel sharedColorPanel].showsAlpha = YES;
- [[NSColorPanel sharedColorPanel] setAction:@selector(colorPanelAction:)];
- [[NSColorPanel sharedColorPanel] orderFront:nil];
- }
- - (IBAction)fontColorButtonAction:(NSButton *)sender {
- self.annotationModel.fontColor = _fontColorButton.color;
- [self updateAnnotation];
- }
- - (NSColor *)colorWithCGColor:(CGColorRef)CGColor
- {
- if (CGColor == NULL) return nil;
- return [NSColor colorWithCIColor:[CIColor colorWithCGColor:CGColor]];
- }
- - (void)colorPanelAction:(id)sender {
- if([NSColorPanel sharedColorPanel].visible) {
- NSColor *currentColor = [NSColorPanel sharedColorPanel].color;
- _fontColorButton.color = currentColor;
- [self.fontColorButton setNeedsDisplay:YES];
-
- CGFloat r, g, b, a = 0.0;
- [[currentColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- if (fabs(a - 0) < 0.001) {
- //设置透明色必须要设一个颜色值
- self.annotationModel.opacity = 0;
- self.annotationModel.fontColor = [NSColor blackColor];
- } else {
- self.annotationModel.opacity = a;
- self.annotationModel.fontColor = currentColor;
- }
-
- [self updateOpacityView];
- if (CAnnotationTypeFreeText == _annotationType ||
- CAnnotationTypeSignDate == _annotationType ||
- CAnnotationTypeSignText == _annotationType) {
- [[self.annotationModel.fontColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- self.fontColorButton.color = [NSColor colorWithRed:r green:g blue:b alpha:self.annotationModel.opacity];
- [_fontButton setNeedsDisplay:YES];
- }
- CPDFAnnotation *annotation = self.annotationModel.annotation;
- if (annotation) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
- if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
- [self.pdfView setEditAnnotationFreeTextColor:currentColor freeText:textNote];
- } else {
- [self updateAnnotation];
- }
- } else {
- [self updateAnnotation];
- }
- self.generalImageView.image = [self.annotationModel annotationImage];
- } else {
- [self updateAnnotation];
- }
- }
- }
- - (IBAction)buttonClicked_TypeAwitch:(NSButton *)sender {
- NSInteger tag = sender.tag;
- CAnnotationType annotationType = CAnnotationTypeSignLine;
- if (tag == 201) {
- annotationType = CAnnotationTypeSignTure;
- } else if (tag == 202) {
- annotationType = CAnnotationTypeSignFalse;
- } else {
- annotationType = tag;
- }
-
- self.selfSignType = annotationType;
- [self typeSelected:annotationType];
- if (self.callBack) {
- self.callBack (annotationType);
- }
-
- self.annotationModel.stampAnnotationType = annotationType;
-
- if (self.selfSignType == CAnnotationTypeSignDot) {
- self.borderWidthView.hidden = YES;
- self.borderWidthViewTopConstraint.constant = -(self.borderWidthView.bounds.size.height);
- } else {
- self.borderWidthView.hidden = NO;
- self.borderWidthViewTopConstraint.constant = 16.0f;
- }
-
- [self updateAnnotation];
- }
- - (IBAction)buttonClicked_SwitchIncludeTime:(NSButton *)sender
- {
- self.annotationModel.includeTime = sender.state == NSControlStateValueOn?YES:NO;
- [self updateDateView];
- [self updateAnnotation];
- }
- - (IBAction)dateCheckButtonAction:(NSPopUpButton *)sender
- {
- self.annotationModel.dateFormatIndex = sender.indexOfSelectedItem;
- [self updateAnnotation];
- }
- #pragma mark SqureAnnotation Style
- - (IBAction)updateFigurateModelAction:(NSButton *)sender {
- if ((sender == self.squareVC.button && _annotationType == CAnnotationTypeSquare) ||
- (sender == self.circleVC.button && _annotationType == CAnnotationTypeCircle) ||
- (sender == self.arrowVC.button && _annotationType == CAnnotationTypeArrow) ||
- (sender == self.lineVC.button && _annotationType == CAnnotationTypeLine)) {
- return;
- }
- self.squareVC.state = KMDesignTokenStateNorm;
- self.circleVC.state = KMDesignTokenStateNorm;
- self.arrowVC.state = KMDesignTokenStateNorm;
- self.lineVC.state = KMDesignTokenStateNorm;
- if (sender == self.squareVC.button) {
- self.pdfView.annotationType = CAnnotationTypeSquare;
- self.squareVC.state = KMDesignTokenStateSel;
- } else if (sender == self.circleVC.button) {
- self.pdfView.annotationType = CAnnotationTypeCircle;
- self.circleVC.state = KMDesignTokenStateSel;
- } else if (sender == self.arrowVC.button) {
- self.pdfView.annotationType = CAnnotationTypeArrow;
- self.arrowVC.state = KMDesignTokenStateSel;
- } else if (sender == self.lineVC.button) {
- self.pdfView.annotationType = CAnnotationTypeLine;
- self.lineVC.state = KMDesignTokenStateSel;
- }
-
- self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
- [self loadingUIAndLocalization];
- }
- #pragma mark CPDFTextAnnotation Action
- - (IBAction)textAnnotationStyleAction:(NSButton *)sender {
- [self.annotationModel setAnchoredIconType:sender.tag];
- [self loadingUIAndLocalization];
-
- [self updateAnnotation];
- }
- #pragma mark - NSNotification
- - (void)textDidChange:(NSNotification *)notification {
- NSObject *obj = notification.object;
- if ([obj isEqualTo:self.noteTextView]) {
- [self.annotationModel setContents:self.noteTextView.string?:@""];
- if (CAnnotationTypeHighlight == self.annotationModel.annotationType || CAnnotationTypeStrikeOut == self.annotationModel.annotationType || CAnnotationTypeUnderline == self.annotationModel.annotationType) {
- } else {
- [self updateAnnotation];
- }
- }
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
- if (![object isEqual:self.annotationModel.annotation]) {
- return;
- }
- id newValue = [change objectForKey:NSKeyValueChangeNewKey] ? : [NSNull null];
- id oldValue = [change objectForKey:NSKeyValueChangeOldKey] ? : [NSNull null];
- if ([newValue isEqual:oldValue]) {
- return;
- }
- if ([keyPath isEqualToString:@"contents"] || [keyPath isEqualToString:@"markupText"]) {
- if ([newValue isKindOfClass:[NSNull class]]) {
- return;
- }
- self.noteTextView.string = newValue ? : @"";
- }
- }
- - (void)alignmentTypeNotification:(NSNotification *)notification {
- NSString *count = notification.object;
-
- NSTextAlignment alignment = NSTextAlignmentLeft;
- if ([count isEqualToString:@"0"]) {
- alignment = NSTextAlignmentLeft;
- } else if ([count isEqualToString:@"1"]) {
- alignment = NSTextAlignmentRight;
- } else if ([count isEqualToString:@"2"]) {
- alignment = NSTextAlignmentCenter;
- }
- [self alignmentTypeSelected:alignment];
- }
- - (void)annotationChangeNotification:(NSNotification *)notification {
- if (notification.object != nil) {
- CPDFAnnotation *annotation = notification.object[@"object"];
- if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
- if (![notification.object[@"keyPath"] isEqualToString: CPDFAnnotationBoundsKey]) {
- [self configureUIView];
- }
- } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- if ([notification.object[@"keyPath"] isEqualToString: CPDFAnnotationContentKey]) {
- // [self configureUIView];
- // [self adjustFreetText];
- }
- }
- }
- }
- #pragma mark - NSPopoverDelegate
- - (void)popoverWillShow:(NSNotification *)notification {
- NSPopover *popover = notification.object;
- if ([popover isEqual:_fillColorPopover]) {
- self.fillButton.wantsLayer = YES;
- self.fillButton.layer.cornerRadius = 4.0;
- self.fillButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
- } else if ([popover isEqual:_borderColorPopover]) {
- self.showborderOpacityButton.wantsLayer = YES;
- self.showborderOpacityButton.layer.cornerRadius = 4.0;
- self.showborderOpacityButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
- }
- }
- - (void)popoverWillClose:(NSNotification *)notification {
- NSPopover *popover = notification.object;
- if ([popover isEqual:_fillColorPopover]) {
- self.fillButton.wantsLayer = YES;
- self.fillButton.layer.cornerRadius = 0.0;
- self.fillButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- } else if ([popover isEqual:_borderColorPopover]) {
- self.showborderOpacityButton.wantsLayer = YES;
- self.showborderOpacityButton.layer.cornerRadius = 0.0;
- self.showborderOpacityButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- }
- }
- #pragma mark - KMSelectPopButtonDelegate
- - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
- if ([self.fontNameVC isEqual:obj]) {
- [self updateFontNameAndStyle:obj.stringValue
- style:self.fontStyleVC.stringValue
- needChangeListView:YES
- needSave:YES];
- } else if ([self.fontStyleVC isEqual:obj]) {
- NSInteger index = self.fontStyleVC.indexOfSelectedItem;
- if (index < 0) {
- return;
- }
-
- NSString *fontName = self.fontNameVC.stringValue;
- NSString *fontStyle = self.fontStyleVC.stringValue;
-
- [self updateFontNameAndStyle:fontName
- style:fontStyle
- needChangeListView:YES
- needSave:YES];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
- } else if (self.fontSizeVC == obj) {
- NSInteger index = self.fontSizeVC.indexOfSelectedItem;
- if (index < 0) {
- return;
- }
- NSString *size = [self.fontSizeVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""];
- [self updateFontSize:size.intValue needChangeListView:YES needSave:YES];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
- [self adjustFreetText];
- } else if (self.borderWidthVC == obj) {
- CGFloat lineWidth = [[self.borderWidthVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""] floatValue];
- if (self.fillColorPickerVC.annotationType == KMPropertiesColor_SelfSignColors) {
- if (lineWidth > 8) {
- lineWidth = 8;
- }
- } else {
- if (_annotationType != CAnnotationTypeEraser) {
- if (lineWidth > 20) {
- lineWidth = 20;
- }
- }
- }
-
- self.annotationModel.lineWidth = lineWidth;
- [self updateBorderWidthView];
- [self updateAnnotation];
- [self adjustFreetText];
- } else if (obj == _textPresuppositionVC) {
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
- [self updateTextPresupposition:type needChangeListView:true];
- [self updateAnnotation];
- [self adjustFreetText];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
- }
- }
- -(void)adjustFreetText {
- if(self.annotationModel.annotation &&
- (CAnnotationTypeFreeText == self.annotationModel.annotationType ||
- CAnnotationTypeSignText == self.annotationModel.annotationType ||
- CAnnotationTypeSignDate == self.annotationModel.annotationType )) {
- for(CPDFAnnotation *an in self.annotationModel.annotations) {
- if([an isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *freeTextAn = (CPDFFreeTextAnnotation *)an;
- NSFont* font = freeTextAn.font;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
- [dictionary setObject:font forKey:NSFontAttributeName];
- NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
- [style setAlignment:freeTextAn.alignment];
- [dictionary setObject:style forKey:NSParagraphStyleAttributeName];
-
- CGSize textViewSize = [freeTextAn.contents?:@"" boundingRectWithSize:CGSizeMake(freeTextAn.bounds.size.width, MAXFLOAT)
- options:NSStringDrawingUsesLineFragmentOrigin
- attributes:dictionary].size;
-
- CGRect rect = freeTextAn.bounds;
- if(textViewSize.height != freeTextAn.bounds.size.height) {
- rect.origin.y -= (textViewSize.height - rect.size.height);
- rect.size.height = textViewSize.height;
- }
-
- if(textViewSize.width < freeTextAn.bounds.size.width) {
- rect.size.width = textViewSize.width;
- }
-
- freeTextAn.bounds = rect;
- }
- }
- }
- }
- - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj {
-
- }
- @end
- @interface KMGeneralAnnotationViewController (Font)
- - (void)updateAlignment:(NSTextAlignment)alignment;
- - (void)updateTextPresupposition:(NSString *)type needChangeListView:(BOOL) needChangeListView;
- - (void)updateTextPresupposition:(NSString *)fontName size:(CGFloat)size needChangeListView:(BOOL)needChangeListView;
- - (void)updateFontNameAndStyle:(NSString *)name style:(NSString *)style needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave;
- - (void)updateFontSize:(CGFloat)size needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave;
- - (void)updateTextTextPresuppositionState:(NSString *)name size:(CGFloat)size;
- - (void)resetTextPresuppositionData;
- - (void)reDefineTextPresuppositionData:(BOOL)redefine;
- @end
- @implementation KMGeneralAnnotationViewController (Font)
- - (void)updateAlignment:(NSTextAlignment)alignment {
- }
- - (void)updateTextTextPresuppositionState:(NSString *)name size:(CGFloat)size {
- NSString *fontName = [KMEditPDFTextManager.manager transformAreaTextFontNameWithFontName:name fontNames:self.fontNameVC.items];
- NSArray *dataArray = [KMEditPDFTextManager.manager fetchAllUserDefaultData];
-
- NSInteger index = 0;
- for (int i = 0; i < dataArray.count; i++) {
- KMEditPDFTextFontModel *model = dataArray[i];
- if ([model.fontName isEqualToString:fontName] && model.fontSize == size) {
- index = i;
- break;
- }
- }
-
- //刷新样式
- [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [self.textPresuppositionVC selectItemAt:index];
- }
- - (void)updateTextPresupposition:(NSString *)type needChangeListView:(BOOL) needChangeListView {
- NSInteger index = [KMEditPDFTextFontTypeWrapper.allValues indexOfObject:type];
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchAllUserDefaultData][index];
-
- NSString *fontName = model.fontName;
- CGFloat size = model.fontSize;
- [self updateTextPresupposition:fontName size:size needChangeListView:needChangeListView];
- }
- - (void)updateTextPresupposition:(NSString *)fontName size:(CGFloat)size needChangeListView:(BOOL)needChangeListView {
- NSArray *fontNameArray = [fontName componentsSeparatedByString:@"-"];
- NSString *name = @"";
- NSString *style = @"";
- if (fontNameArray.count > 0) {
- name = fontNameArray.firstObject;
- } else {
- name = @"Helvetica";
- }
-
- if (fontNameArray.count == 2) {
- style = fontNameArray.lastObject;
- } else {
- style = @"Regular";
- }
-
- [self updateFontNameAndStyle:name style:style needChangeListView:needChangeListView needSave:false];
- [self updateFontSize:size needChangeListView:needChangeListView needSave:false];
- }
- - (void)resetTextPresuppositionData {
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
- [KMEditPDFTextManager.manager resetTextPresuppositionWithType:type];
- [self updateTextPresupposition:type needChangeListView:YES];
-
- //刷新样式
- [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [self.textPresuppositionVC selectItemAt:index];
- }
- - (void)reDefineTextPresuppositionData:(BOOL)redefine {
- NSString *fontStyle = self.fontStyleVC.stringValue;
- NSString *fontName = self.fontNameVC.stringValue;
- CGFloat fontSize = [[self.fontSizeVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""] intValue];
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- NSString *type = KMEditPDFTextFontTypeWrapper.allValues[index];
-
- fontName = [NSString stringWithFormat:@"%@-%@",fontName, fontStyle];
- [KMEditPDFTextManager.manager reDefineTextPresuppositionWithFontName:fontName fontSize:fontSize type:type];
-
- [self updateTextPresupposition:type needChangeListView:YES];
-
- //刷新样式
- [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [self.textPresuppositionVC selectItemAt:index];
- }
- - (void)updateFontNameAndStyle:(NSString *)name style:(NSString *)style needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave {
- NSString *fontName = self.fontName;
- NSString *fontStyle = self.fontStyle;
- // if (fontName != name || fontStyle != style) {
- NSArray *styleArray = [KMEditPDFTextManager.manager fetchFontStyleWithFontNameWithFontName:name];
- NSString *styleString = [KMEditPDFTextManager.manager checkFontStyleWithStyle:style];
- if (![styleArray containsObject:style]) {
- [self.fontStyleVC addItemsWithObjectValues:styleArray];
- [self.fontStyleVC selectItemAt:0];
- styleString = [KMEditPDFTextManager.manager checkFontStyleWithStyle:self.fontStyleVC.stringValue];
- } else {
- [self.fontStyleVC selectItemAt: [styleArray indexOfObject:styleString]];
- }
-
- fontName = [NSString stringWithFormat:@"%@-%@",name, [styleString stringByReplacingOccurrencesOfString:@" " withString:@""]];
- if (styleString.length == 0) {
- fontName = name;
- }
-
- self.fontName = name;
- self.fontStyle = styleString;
- [self.fontNameVC selectItemAt:[self.fontNameVC.items indexOfObject:name] ? :0];
- if (self.annotationModel.annotations.count > 0) {
- if (needChangeListView) {
- self.annotationModel.fontName = fontName;
- [self updateAnnotation];
- }
- } else {
- self.annotationModel.fontName = fontName;
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
- [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:fontName fontSize:model.fontSize type:@"Commonly"];
- }
-
- if (needSave) {
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:type];
- [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:fontName fontSize:model.fontSize type:type];
- }
-
- //刷新样式
- [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [self.textPresuppositionVC selectItemAt:self.textPresuppositionVC.indexOfSelectedItem];
- // }
- }
- - (void)updateFontSize:(CGFloat)size needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave {
- if (self.fontSize != size) {
- self.fontSize = size;
- [self.fontSizeVC selectItemAt: [self.fontSizeVC.items indexOfObject: [NSString stringWithFormat:@"%.0fpt",size]]];
-
- if (self.annotationModel.annotations.count > 0) {
- if (needChangeListView) {
- self.annotationModel.fontSize = size;
- [self updateAnnotation];
- }
- } else {
- self.annotationModel.fontSize = size;
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
- [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:model.fontName fontSize:size type:@"Commonly"];
- }
-
- if (needSave) {
- NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
- NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
- KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:type];
- [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:model.fontName fontSize:size type:type];
- }
-
- //刷新样式
- [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
- [self.textPresuppositionVC selectItemAt:self.textPresuppositionVC.indexOfSelectedItem];
- }
- }
- @end
|