12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345 |
- //
- // KMGeneralAnnotationViewController.m
- // SignFlow
- //
- // Created by wanjun on 2021/6/15.
- //
- #import "KMGeneralAnnotationViewController.h"
- #import "KMColorPickerViewController.h"
- #import "KMPopUpButton.h"
- #import "KMAnnotationFontWindowController.h"
- #import "KMSelfSignAnnotation.h"
- #import "KMSelfSignAnnotationFreeText.h"
- #import "CPDFMarkupAnnotation+PDFListView.h"
- #import "CPDFLineAnnotation+PDFListView.h"
- #import "KMGeneralButton.h"
- #import "NSFont_SKExtensions.h"
- #import "NSMenu+Category.h"
- #import "KMPropertiesViewPopController.h"
- #if VERSION_DMG
- #import <PDF_Master-Swift.h>
- #else
- #import <PDF_Master-Swift.h>
- #endif
- @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 = KMPopUpButtonType_ArrowUpDown;
-
- 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 fetchAllDateString: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);
-
- // 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:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6];
- // 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 colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
- // } else {
- // box.fillColor = [NSColor clearColor];
- // }
- // };
- // }
-
- 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
|