KMGeneralAnnotationViewController.m 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  1. //
  2. // KMGeneralAnnotationViewController.m
  3. // SignFlow
  4. //
  5. // Created by wanjun on 2021/6/15.
  6. //
  7. #import "KMGeneralAnnotationViewController.h"
  8. #import "KMColorPickerViewController.h"
  9. #import "KMPopUpButton.h"
  10. #import "KMAnnotationFontWindowController.h"
  11. #import "KMSelfSignAnnotation.h"
  12. #import "KMSelfSignAnnotationFreeText.h"
  13. #import "CPDFMarkupAnnotation+PDFListView.h"
  14. #import "CPDFLineAnnotation+PDFListView.h"
  15. #import "KMGeneralButton.h"
  16. #import "KMPropertiesViewPopController.h"
  17. #import <PDF_Master-Swift.h>
  18. @interface KMGeneralAnnotationViewController () <NSTextViewDelegate, NSPopoverDelegate, KMSelectPopButtonDelegate>
  19. @property (assign) IBOutlet NSView *generalImageBoxView;
  20. @property (assign) IBOutlet NSImageView *generalImageView;
  21. @property (weak) IBOutlet NSView *mianView;
  22. @property (weak) IBOutlet NSLayoutConstraint *generaImageTopLayoutConstraint;
  23. @property (weak) IBOutlet NSView *inkView;
  24. @property (weak) IBOutlet NSButton *addInkButton;
  25. @property (weak) IBOutlet NSButton *clearInkButton;
  26. @property (assign) IBOutlet NSView *fontView; //字体
  27. @property (assign) IBOutlet NSTextField *fontLabel;
  28. @property (assign) IBOutlet NSButton *fontButton;
  29. @property (assign) IBOutlet NSBox *fontNameBox;
  30. @property (assign) IBOutlet NSBox *fontSizeBox;
  31. @property (assign) IBOutlet NSBox *fontStyleBox;
  32. @property (assign) IBOutlet NSBox *leftAlignBox;
  33. @property (assign) IBOutlet NSBox *centerAlignBox;
  34. @property (assign) IBOutlet NSBox *rightAlignBox;
  35. @property (assign) IBOutlet NSBox *fontBox;
  36. @property (assign) IBOutlet KMGeneralButton *fontColorButton;
  37. @property (assign) IBOutlet NSButton *fontCustomColorButton;
  38. @property (assign) IBOutlet NSLayoutConstraint *fontViewTopConstraint;
  39. @property (weak) IBOutlet NSLayoutConstraint *fontDefaultTopConstraint;
  40. @property (weak) IBOutlet NSBox *moreBox;
  41. @property (weak) IBOutlet NSBox *textPresuppositionContentBox;
  42. @property (weak) IBOutlet NSView *defaultFontView;
  43. @property (assign) IBOutlet NSView *fillColorView; //填充颜色
  44. @property (assign) IBOutlet NSTextField *fillColorLabel;
  45. @property (assign) IBOutlet NSBox *fillColorBox;
  46. @property (assign) IBOutlet KMColorPickerViewController *fillColorPickerVC;
  47. @property (assign) IBOutlet NSLayoutConstraint *fillColorViewTopConstraint;
  48. @property (weak) IBOutlet NSButton *fillButton;
  49. //填充
  50. @property (assign) IBOutlet NSView *opacityView; //透明度
  51. @property (assign) IBOutlet NSSlider *opacitySlider;
  52. @property (assign) IBOutlet NSComboBox *opacityComboBox;
  53. @property (weak) IBOutlet NSButton *showOpacityButton;
  54. @property (assign) IBOutlet NSView *borderColorView; //边框颜色
  55. @property (assign) IBOutlet NSTextField *borderColorLabel;
  56. @property (assign) IBOutlet NSBox *borderColorBox;
  57. @property (assign) IBOutlet KMColorPickerViewController *borderColorPickerVC;
  58. @property (assign) IBOutlet NSLayoutConstraint *borderColorViewTopConstraint;
  59. @property (assign) IBOutlet NSView *borderOpacityView; //透明度
  60. @property (assign) IBOutlet NSSlider *borderOpacitySlider;
  61. @property (assign) IBOutlet NSComboBox *borderOpacityComboBox;
  62. @property (weak) IBOutlet NSButton *showborderOpacityButton;
  63. @property (assign) IBOutlet NSView *borderWidthView; //线段宽度
  64. @property (assign) IBOutlet NSTextField *borderWidthLabel;
  65. @property (assign) IBOutlet NSSlider *borderWidthSlider;
  66. @property (assign) IBOutlet NSBox *borderWidthBox;
  67. @property (assign) IBOutlet NSLayoutConstraint *borderWidthViewTopConstraint;
  68. @property (strong) IBOutlet NSView *boderWidthStyleView;
  69. @property (weak) IBOutlet NSButton *borderWidthStyleReal;
  70. @property (weak) IBOutlet NSButton *borderWidthStyleDotted;
  71. @property (assign) IBOutlet NSLayoutConstraint *boderWidthStyleViewTopConstraint;
  72. @property (assign) IBOutlet NSView *rotateView; //旋转
  73. @property (assign) IBOutlet NSTextField *rotateLabel;
  74. @property (assign) IBOutlet NSBox *leftRotateBox;
  75. @property (assign) IBOutlet NSBox *rightRotateBox;
  76. @property (assign) IBOutlet NSLayoutConstraint *rotateViewTopConstraint;
  77. @property (assign) IBOutlet NSView *noteView; //笔记
  78. @property (assign) IBOutlet NSTextField *noteViewLabel;
  79. @property (assign) IBOutlet NSBox *noteTextBox;
  80. @property (assign) IBOutlet NSTextView *noteTextView;
  81. @property (assign) IBOutlet NSLayoutConstraint *noteViewTopConstraint;
  82. @property (assign) IBOutlet NSView *backgroundView;
  83. @property (assign) IBOutlet NSTextField *backgroundLabel;
  84. @property (assign) IBOutlet NSBox *backgroundBox;
  85. @property (assign) IBOutlet KMColorPickerViewController *backgroundColorPickerVC;
  86. @property (assign) IBOutlet NSLayoutConstraint *backgroundTopConstraint;
  87. @property (weak) IBOutlet NSLayoutConstraint *figureTopConstraint;
  88. @property (weak) IBOutlet NSView *figureView;
  89. @property (weak) IBOutlet NSBox *squareBox;
  90. @property (weak) IBOutlet NSBox *circleBox;
  91. @property (weak) IBOutlet NSBox *arrowBox;
  92. @property (weak) IBOutlet NSBox *lineBox;
  93. @property (assign) IBOutlet NSView *typeView;
  94. @property (assign) IBOutlet NSTextField *typeLabel;
  95. @property (assign) IBOutlet NSButton *tureTypeButton;
  96. @property (assign) IBOutlet NSButton *falseTypeButton;
  97. @property (assign) IBOutlet NSButton *circletypeButton;
  98. @property (assign) IBOutlet NSButton *lineTypeButton;
  99. @property (assign) IBOutlet NSButton *dotTypeButton;
  100. @property (assign) IBOutlet NSLayoutConstraint *typeTopConstraint;
  101. @property (assign) IBOutlet NSView *dateView;
  102. @property (assign) IBOutlet NSTextField *dateLabel;
  103. @property (assign) IBOutlet KMPopUpButton *datePopupButton;
  104. @property (assign) IBOutlet NSButton *dateButton;
  105. @property (assign) IBOutlet NSLayoutConstraint *dateTopConstraint;
  106. @property (weak) IBOutlet NSView *noteStyleView;
  107. @property (weak) IBOutlet NSTextField *noteStyleTextField;
  108. @property (weak) IBOutlet NSLayoutConstraint *noteStyleTopConstraint;
  109. @property (weak) IBOutlet NSButton *noteStyleNoneButton;
  110. @property (weak) IBOutlet NSButton *noteStyleButton1;
  111. @property (weak) IBOutlet NSButton *noteStyleButton2;
  112. @property (weak) IBOutlet NSButton *noteStyleButton3;
  113. @property (weak) IBOutlet NSButton *noteStyleButton4;
  114. @property (weak) IBOutlet NSButton *noteStyleButton5;
  115. @property (weak) IBOutlet NSButton *noteStyleButton6;
  116. @property (nonatomic, assign) CAnnotationType selfSignType;
  117. @property (nonatomic, retain) NSMutableArray*fonts;
  118. @property (nonatomic, assign) CAnnotationType annotationType;
  119. @property (nonatomic, retain) KMGeneralAnnotationViewController * annotationViewController;
  120. @property (nonatomic, retain) NSPopover *fillColorPopover;
  121. @property (nonatomic, retain) NSPopover *borderColorPopover;
  122. @property (nonatomic, retain) KMDesignPropertySelector *leftAlignVC;
  123. @property (nonatomic, retain) KMDesignPropertySelector *centerAlignVC;
  124. @property (nonatomic, retain) KMDesignPropertySelector *rightAlignVC;
  125. @property (nonatomic, retain) KMDesignPropertySelector *leftRotateVC;
  126. @property (nonatomic, retain) KMDesignPropertySelector *rightRotateVC;
  127. @property (nonatomic, retain) KMDesignSelect *textPresuppositionVC;
  128. @property (nonatomic, retain) KMDesignPropertySelector *textPresuppositionResetVC;
  129. @property (nonatomic, retain) KMDesignSelect *fontNameVC;
  130. @property (nonatomic, retain) KMDesignSelect *fontSizeVC;
  131. @property (nonatomic, retain) KMDesignSelect *fontStyleVC;
  132. @property (nonatomic, retain) KMDesignSelect *borderWidthVC;
  133. @property (nonatomic, retain) KMDesignPropertySelector *squareVC;
  134. @property (nonatomic, retain) KMDesignPropertySelector *circleVC;
  135. @property (nonatomic, retain) KMDesignPropertySelector *arrowVC;
  136. @property (nonatomic, retain) KMDesignPropertySelector *lineVC;
  137. //文字缓存
  138. @property (nonatomic, assign) NSInteger fontSize;
  139. @property (nonatomic, strong) NSString *fontName;
  140. @property (nonatomic, strong) NSString *fontStyle;
  141. @end
  142. @implementation KMGeneralAnnotationViewController
  143. #pragma mark - init Method
  144. - (void)dealloc {
  145. if (_annotationModel.annotation &&
  146. _annotationModel.annotations.count == 1) {
  147. NSArray *keys = @[@"contents",@"markupText"];
  148. for (NSString *key in keys) {
  149. [_annotationModel.annotation removeObserver:self forKeyPath:key];
  150. }
  151. }
  152. [[NSColorPanel sharedColorPanel] setTarget:nil];
  153. [[NSColorPanel sharedColorPanel] setAction:nil];
  154. [[NSColorPanel sharedColorPanel] orderOut:nil];
  155. [[NSNotificationCenter defaultCenter] removeObserver:self];
  156. }
  157. -(void)viewDidAppear
  158. {
  159. [super viewDidAppear];
  160. BOOL showConvertDetails = [KMPropertiesViewPopController showChangeColorDetails];
  161. if (showConvertDetails && [(NSDocument *)self.view.window.windowController.document fileURL]) {
  162. [[KMPropertiesViewPopController defaultManager] showChangeColorDetailsView:self.fillColorPickerVC.firstBox];
  163. }
  164. }
  165. #pragma mark - View Methods
  166. - (void)loadView {
  167. [super loadView];
  168. dispatch_async(dispatch_get_main_queue(), ^{
  169. if([NSColorPanel sharedColorPanel].visible) {
  170. [[NSColorPanel sharedColorPanel] close];
  171. }
  172. });
  173. self.fonts = [CPDFAnnotationModel supportFonts];
  174. [self loadingUIAndLocalization];
  175. if (_annotationModel.annotation &&
  176. _annotationModel.annotations.count == 1) {
  177. CPDFAnnotation *annotation = _annotationModel.annotation;
  178. NSArray *keys = @[@"contents",@"markupText"];
  179. for (NSString *key in keys) {
  180. [annotation addObserver:self forKeyPath:key options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];
  181. }
  182. }
  183. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alignmentTypeNotification:) name:@"KMAnnotationAlignmentTypeNotification1" object:nil];
  184. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadingUIAndLocalization) name:@"KMPreferenceDidChangeNotificationName" object:nil];
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(annotationChangeNotification:) name:CPDFListViewAnnotationsAttributeHasChangeNotification object:nil];
  186. }
  187. - (void)loadingUIAndLocalization
  188. {
  189. self.view.wantsLayer = YES;
  190. self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
  191. self.annotationType = self.annotationModel.annotationType;
  192. _generalImageBoxView.wantsLayer = YES;
  193. _generalImageBoxView.layer.borderColor = [NSColor colorWithRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1].CGColor;
  194. _generalImageBoxView.layer.borderWidth = 1.0f;
  195. _generalImageBoxView.layer.cornerRadius = 4;
  196. NSColor *color = [NSColor whiteColor];
  197. if (CAnnotationTypeFreeText == _annotationType ||
  198. CAnnotationTypeSignDot == _annotationType ||
  199. CAnnotationTypeSignCircle == _annotationType ||
  200. CAnnotationTypeSignLine == _annotationType ||
  201. CAnnotationTypeSignTure == _annotationType ||
  202. CAnnotationTypeSignFalse == _annotationType) {
  203. if (@available(macOS 10.14, *)) {
  204. NSAppearanceName appearanceName = [[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
  205. if ([appearanceName isEqualToString:NSAppearanceNameDarkAqua]) {
  206. color = [NSColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.15];
  207. }
  208. }
  209. }
  210. _generalImageBoxView.layer.backgroundColor = color.CGColor;
  211. _generalImageBoxView.layer.cornerRadius = 6.0f;
  212. _fontLabel.stringValue = NSLocalizedString(@"Fonts", nil);
  213. _fillColorLabel.stringValue = NSLocalizedString(@"Fill", nil);
  214. _borderColorLabel.stringValue = NSLocalizedString(@"Border", nil);
  215. _borderWidthLabel.stringValue = NSLocalizedString(@"Line", nil);
  216. _rotateLabel.stringValue = NSLocalizedString(@"Rotate", nil);
  217. _noteViewLabel.stringValue = NSLocalizedString(@"Note", nil);
  218. _typeLabel.stringValue = NSLocalizedString(@"Type", nil);
  219. _dateLabel.stringValue = NSLocalizedString(@"Date", nil);
  220. _backgroundLabel.stringValue = NSLocalizedString(@"Background Color", nil);
  221. _dateButton.title = NSLocalizedString(@"Time", nil);
  222. _noteStyleTextField.stringValue = NSLocalizedString(@"Style", nil);
  223. _fontLabel.textColor =
  224. _fillColorLabel.textColor =
  225. _borderColorLabel.textColor =
  226. _borderWidthLabel.textColor =
  227. _rotateLabel.textColor =
  228. _noteViewLabel.textColor =
  229. _dateLabel.textColor =
  230. _typeLabel.textColor =
  231. _noteStyleTextField.textColor =
  232. _backgroundLabel.textColor = [NSColor colorWithRed:97.0/255.0 green:100.0/255.0 blue:105.0/255.0 alpha:1];
  233. _fillColorBox.contentView = _fillColorPickerVC.view;
  234. _borderColorBox.contentView = _borderColorPickerVC.view;
  235. _noteTextView.backgroundColor = [NSColor whiteColor];
  236. _opacityComboBox.wantsLayer =
  237. _borderOpacityComboBox.wantsLayer =
  238. _falseTypeButton.wantsLayer =
  239. _tureTypeButton.wantsLayer =
  240. _circletypeButton.wantsLayer =
  241. _lineTypeButton.wantsLayer =
  242. _dotTypeButton.wantsLayer = YES;
  243. _opacityComboBox.layer.backgroundColor =
  244. _borderOpacityComboBox.layer.backgroundColor = [NSColor clearColor].CGColor;
  245. _fontBox.borderColor = [NSColor colorWithRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1];
  246. _fontBox.fillColor = [NSColor clearColor];
  247. _opacityComboBox.layer.borderWidth =
  248. _noteTextBox.borderWidth = 0.5f;
  249. _opacityComboBox.layer.borderColor = [NSColor grayColor].CGColor;
  250. _noteTextBox.borderColor = [NSColor grayColor];
  251. _leftRotateBox.borderColor =
  252. _rightRotateBox.borderColor = [NSColor grayColor];
  253. _opacityComboBox.layer.cornerRadius =
  254. _falseTypeButton.layer.cornerRadius =
  255. _tureTypeButton.layer.cornerRadius =
  256. _circletypeButton.layer.cornerRadius =
  257. _lineTypeButton.layer.cornerRadius =
  258. _dotTypeButton.layer.cornerRadius= 5.0f;
  259. _leftAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  260. _centerAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  261. _rightAlignVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  262. _leftAlignBox.fillColor = [NSColor clearColor];
  263. _leftAlignBox.contentView = _leftAlignVC.view;
  264. _leftAlignVC.target = self;
  265. _leftAlignVC.action = @selector(leftAlignButtonAction:);
  266. _leftAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_left"];
  267. _centerAlignBox.fillColor = [NSColor clearColor];
  268. _centerAlignBox.contentView = _centerAlignVC.view;
  269. _centerAlignVC.target = self;
  270. _centerAlignVC.action = @selector(centerAlignButtonAction:);
  271. _centerAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_center"];
  272. _rightAlignBox.fillColor = [NSColor clearColor];
  273. _rightAlignBox.contentView = _rightAlignVC.view;
  274. _rightAlignVC.target = self;
  275. _rightAlignVC.action = @selector(rightAlignButtonAction:);
  276. _rightAlignVC.image = [NSImage imageNamed:@"icon_propertybar_fontAlign_right"];
  277. _leftRotateVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  278. _rightRotateVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  279. _leftRotateBox.fillColor = [NSColor clearColor];
  280. _leftRotateBox.contentView = _leftRotateVC.view;
  281. _rightRotateBox.fillColor = [NSColor clearColor];
  282. _rightRotateBox.contentView = _rightRotateVC.view;
  283. //textPresupposition
  284. _textPresuppositionVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
  285. _textPresuppositionContentBox.contentView = _textPresuppositionVC.view;
  286. _textPresuppositionContentBox.fillColor = [NSColor clearColor];
  287. [_textPresuppositionVC addItemsWithObjectValues: [KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  288. [_textPresuppositionVC selectItemAt:0];
  289. _textPresuppositionVC.delete = self;
  290. _textPresuppositionResetVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  291. _moreBox.contentView = _textPresuppositionResetVC.view;
  292. _moreBox.fillColor = [NSColor clearColor];
  293. _textPresuppositionResetVC.target = self;
  294. _textPresuppositionResetVC.action = @selector(resetTextPresuppositionButtonAction:);
  295. _textPresuppositionResetVC.image = [NSImage imageNamed:@"KMImagePropertPanelTextDefaultMore"];
  296. _fontNameVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
  297. _fontStyleVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
  298. _fontSizeVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
  299. NSMutableArray *fontNames = [NSMutableArray array];
  300. for (NSDictionary *font in [CPDFAnnotationModel supportFonts]) {
  301. NSString *fontName = font.allKeys.firstObject;
  302. [fontNames addObject:fontName];
  303. }
  304. _fontNameBox.fillColor = [NSColor clearColor];
  305. _fontNameBox.contentView = _fontNameVC.view;
  306. [_fontNameVC removeAllItems];
  307. [_fontNameVC addItemsWithObjectValues:fontNames];
  308. [_fontNameVC selectItemAt:0];
  309. _fontNameVC.delete = self;
  310. NSArray *fontnames = [_annotationModel.fontName componentsSeparatedByString:@"-"];
  311. NSFont *currentFont = [NSFont systemFontOfSize:12.0];
  312. if ([fontnames.lastObject isEqualToString:@"Regular"]) {
  313. currentFont = [NSFont fontWithName:fontnames.firstObject size:_annotationModel.fontSize];
  314. } else {
  315. currentFont = [NSFont fontWithName:_annotationModel.fontName size:_annotationModel.fontSize];
  316. }
  317. _fontStyleBox.fillColor = [NSColor clearColor];
  318. _fontStyleBox.contentView = _fontStyleVC.view;
  319. NSArray *styles = [currentFont km_styles];
  320. [_fontStyleVC addItemsWithObjectValues:styles];
  321. [_fontStyleVC selectItemAt:0];
  322. _fontStyleVC.delete = self;
  323. _fontSizeBox.fillColor = [NSColor clearColor];
  324. _fontSizeBox.contentView = _fontSizeVC.view;
  325. [_fontSizeVC removeAllItems];
  326. [_fontSizeVC addItemsWithObjectValues:@[@"8pt", @"9pt", @"10pt", @"11pt", @"12pt", @"14pt", @"16pt", @"18pt", @"20pt", @"22pt", @"24pt", @"26pt", @"28pt", @"36pt", @"48pt", @"72pt"]];
  327. [_fontSizeVC selectItemAt:0.0];
  328. _fontSizeVC.delete = self;
  329. _borderWidthVC = [[KMDesignSelect alloc] initWithType:SelectTypePopButton];
  330. _borderWidthBox.fillColor = [NSColor clearColor];
  331. _borderWidthBox.contentView = _borderWidthVC.view;
  332. [_borderWidthVC removeAllItems];
  333. if(_annotationModel.annotationType == CAnnotationTypeEraser) {
  334. self.borderWidthSlider.minValue = 5;
  335. [_borderWidthVC addItemsWithObjectValues:@[@"5pt", @"6pt", @"8pt", @"10pt", @"12pt"]];
  336. } else {
  337. [_borderWidthVC addItemsWithObjectValues:@[@"1pt", @"2pt", @"4pt", @"6pt", @"8pt"]];
  338. }
  339. [_borderWidthVC selectItemAt:0.0];
  340. _borderWidthVC.delete = self;
  341. _squareVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  342. _circleVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  343. _arrowVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  344. _lineVC = [[KMDesignPropertySelector alloc] initWithType:PropertySelectorTypeIcon_Btn];
  345. _squareBox.fillColor = [NSColor clearColor];
  346. _squareBox.contentView = _squareVC.view;
  347. _squareVC.target = self;
  348. _squareVC.action = @selector(updateFigurateModelAction:);
  349. _squareVC.image = [NSImage imageNamed:@"KMImageNameMainToolSquare"];
  350. _squareVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolSquareSelect"];
  351. _circleBox.fillColor = [NSColor clearColor];
  352. _circleBox.contentView = _circleVC.view;
  353. _circleVC.target = self;
  354. _circleVC.action = @selector(updateFigurateModelAction:);
  355. _circleVC.image = [NSImage imageNamed:@"KMImageNameMainToolRectangle"];
  356. _circleVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolRectangle"];
  357. _arrowBox.fillColor = [NSColor clearColor];
  358. _arrowBox.contentView = _arrowVC.view;
  359. _arrowVC.target = self;
  360. _arrowVC.action = @selector(updateFigurateModelAction:);
  361. _arrowVC.image = [NSImage imageNamed:@"KMImageNameMainToolShapes"];
  362. _arrowVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolShapesSelect"];
  363. _lineBox.fillColor = [NSColor clearColor];
  364. _lineBox.contentView = _lineVC.view;
  365. _lineVC.target = self;
  366. _lineVC.action = @selector(updateFigurateModelAction:);
  367. _lineVC.image = [NSImage imageNamed:@"KMImageNameMainToolStraightLine"];
  368. _lineVC.image_sel = [NSImage imageNamed:@"KMImageNameMainToolStraightLineSelect"];
  369. [self configureUIView];
  370. if (CAnnotationTypeFreeText == _annotationType ||
  371. CAnnotationTypeSignText == _annotationType ||
  372. CAnnotationTypeSignDate == _annotationType ) {
  373. self.fillColorPickerVC.isFreeText = YES;
  374. } else {
  375. self.fillColorPickerVC.isFreeText = NO;
  376. }
  377. _datePopupButton.type = KMPopUpButtonType_ArrowUpDown;
  378. self.generalImageView.image = [self.annotationModel annotationImage];
  379. if (CAnnotationTypeSignFalse != _annotationType &&
  380. CAnnotationTypeSignTure != _annotationType &&
  381. CAnnotationTypeSignDot != _annotationType &&
  382. CAnnotationTypeSignLine != _annotationType &&
  383. CAnnotationTypeSignCircle != _annotationType &&
  384. CAnnotationTypeSignDate != _annotationType) {
  385. if (CAnnotationTypeStamp == _annotationType ||
  386. CAnnotationTypeInk == _annotationType ||
  387. CAnnotationTypeSquare == _annotationType ||
  388. CAnnotationTypeCircle == _annotationType ||
  389. CAnnotationTypeArrow == _annotationType ||
  390. CAnnotationTypeLine == _annotationType ||
  391. CAnnotationTypeHighlight == _annotationType ||
  392. CAnnotationTypeUnderline == _annotationType ||
  393. CAnnotationTypeFreeText == _annotationType ||
  394. CAnnotationTypeStrikeOut == _annotationType) {
  395. self.noteView.hidden = YES;
  396. } else {
  397. self.noteView.hidden = self.annotationModel.annotation==nil;
  398. }
  399. }
  400. //全部便签都隐藏
  401. self.noteView.hidden = YES;
  402. if (self.annotationModel.annotations.count > 1) {
  403. self.noteView.hidden = YES;
  404. }
  405. self.noteTextView.wantsLayer = YES;
  406. if (self.annotationModel.annotation) {
  407. CPDFAnnotation *annotation = self.annotationModel.annotation;
  408. NSString *contextString = annotation.contents ? : @"";
  409. if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  410. contextString = [(CPDFMarkupAnnotation *)annotation markupContent];
  411. }
  412. self.noteTextView.string = contextString?:@"";
  413. self.noteTextView.textColor = [NSColor labelColor];
  414. self.noteTextView.delegate = self;
  415. }
  416. self.opacityView.wantsLayer = YES;
  417. self.opacityView.layer.backgroundColor = [NSColor clearColor].CGColor;
  418. self.opacityView.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.16].CGColor;
  419. self.opacityView.layer.shadowOffset = NSMakeSize(0, 2);
  420. self.opacityView.layer.cornerRadius = 5;
  421. self.borderOpacityView.wantsLayer = YES;
  422. self.borderOpacityView.layer.backgroundColor = [NSColor clearColor].CGColor;
  423. self.borderOpacityView.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.16].CGColor;
  424. self.borderOpacityView.layer.shadowOffset = NSMakeSize(0, 2);
  425. self.borderOpacityView.layer.cornerRadius = 5;
  426. }
  427. #pragma mark - private
  428. - (void)hiddenSubviews {
  429. if(self.generalImageBoxView.hidden) {
  430. self.generaImageTopLayoutConstraint.constant = -(self.generalImageBoxView.bounds.size.height) - (self.inkView.bounds.size.height);
  431. } else {
  432. self.generaImageTopLayoutConstraint.constant = self.inkView.hidden ? -(self.inkView.bounds.size.height) : 16.0f;
  433. }
  434. self.fontDefaultTopConstraint.constant = self.defaultFontView.hidden ? -(self.defaultFontView.bounds.size.height) : 16.0f;
  435. self.figureTopConstraint.constant = self.figureView.hidden ? -(self.figureView.bounds.size.height) : 8.0f;
  436. self.fontViewTopConstraint.constant = self.fontView.hidden ? -(self.fontView.bounds.size.height) : 8.0f;
  437. self.fillColorViewTopConstraint.constant = self.fillColorView.hidden ? -(self.fillColorView.bounds.size.height) : 8.0f;
  438. self.borderColorViewTopConstraint.constant = self.borderColorView.hidden ? -(self.borderColorView.bounds.size.height) : 8.0f;
  439. self.borderWidthViewTopConstraint.constant = self.borderWidthView.hidden ? -(self.borderWidthView.bounds.size.height) : 0.0f;
  440. self.boderWidthStyleViewTopConstraint.constant = self.boderWidthStyleView.hidden ? -(self.boderWidthStyleView.bounds.size.height) : 16.0f;
  441. self.rotateViewTopConstraint.constant = self.rotateView.hidden ? -(self.rotateView.bounds.size.height) : 16.0f;
  442. self.noteViewTopConstraint.constant = self.noteStyleView.hidden ? -(self.rotateView.bounds.size.height) : 16.0f;
  443. self.noteViewTopConstraint.constant = self.noteView.hidden ? -(self.noteView.bounds.size.height) : 16.0f;
  444. self.backgroundTopConstraint.constant = self.backgroundView.hidden ? -(self.backgroundView.bounds.size.height) : 16.0f;
  445. self.typeTopConstraint.constant = self.typeView.hidden ? -(self.typeView.bounds.size.height) : 16.0f;
  446. self.dateTopConstraint.constant = self.dateView.hidden ? -(self.dateView.bounds.size.height) : 16.0f;
  447. self.noteStyleTopConstraint.constant = self.noteStyleView.hidden ? -(self.noteStyleView.bounds.size.height) : 8.0f;
  448. }
  449. - (void)configureUIView
  450. {
  451. [self updateOpacityView];
  452. if (!self.annotationModel.annotation) {
  453. self.noteView.hidden = YES;
  454. }
  455. if (_annotationType == CAnnotationTypeInk || _annotationType == CAnnotationTypeEraser) {
  456. if (self.annotationModel.annotations.count > 0) {
  457. self.inkView.hidden = YES;
  458. [self updateInkAction:self.addInkButton];
  459. } else {
  460. self.inkView.hidden = NO;
  461. if (_annotationType == CAnnotationTypeInk) {
  462. [self updateInkAction:self.addInkButton];
  463. } else {
  464. [self updateInkAction:self.clearInkButton];
  465. }
  466. }
  467. } else {
  468. self.inkView.hidden = YES;
  469. }
  470. if (self.annotationModel.annotations.count > 1) {
  471. self.generalImageBoxView.hidden = YES;
  472. } else {
  473. self.generalImageBoxView.hidden = NO;
  474. }
  475. self.noteStyleView.hidden = YES;
  476. self.borderOpacityView.hidden = YES;
  477. switch (_annotationType) {
  478. case CAnnotationTypeHighlight:
  479. case CAnnotationTypeUnderline:
  480. case CAnnotationTypeStrikeOut:
  481. {
  482. self.fontView.hidden = YES;
  483. self.borderColorView.hidden = YES;
  484. self.borderWidthView.hidden = YES;
  485. self.boderWidthStyleView.hidden = YES;
  486. self.rotateView.hidden = YES;
  487. self.backgroundView.hidden = YES;
  488. self.typeView.hidden = YES;
  489. self.dateView.hidden = YES;
  490. self.defaultFontView.hidden = YES;
  491. self.figureView.hidden = YES;
  492. self.noteView.hidden = YES;
  493. [self createMarkupProperties];
  494. [self updateFillColorPickerVC];
  495. }
  496. break;
  497. case CAnnotationTypeInk:
  498. case CAnnotationTypeLine:
  499. case CAnnotationTypeArrow:
  500. {
  501. self.fontView.hidden = YES;
  502. self.borderColorView.hidden = YES;
  503. self.rotateView.hidden = YES;
  504. self.backgroundView.hidden = YES;
  505. self.typeView.hidden = YES;
  506. self.dateView.hidden = YES;
  507. self.fillColorView.hidden = NO;
  508. self.boderWidthStyleView.hidden = NO;
  509. self.defaultFontView.hidden = YES;
  510. self.noteView.hidden = YES;
  511. if(_annotationType != CAnnotationTypeInk && self.pdfView.annotationType != CAnnotationTypeUnkown) {
  512. self.figureView.hidden = NO;
  513. [self updateFigureModel];
  514. } else {
  515. self.figureView.hidden = YES;
  516. }
  517. if (_annotationType == CAnnotationTypeLine || _annotationType == CAnnotationTypeArrow) {
  518. _fillColorLabel.stringValue = NSLocalizedString(@"Border Style", nil);
  519. }
  520. [self createInkAndLineProperties];
  521. [self updateBorderWidthView];
  522. [self updateFillColorPickerVC];
  523. }
  524. break;
  525. case CAnnotationTypeEraser:
  526. {
  527. self.fontView.hidden = YES;
  528. self.borderColorView.hidden = YES;
  529. self.rotateView.hidden = YES;
  530. self.backgroundView.hidden = YES;
  531. self.typeView.hidden = YES;
  532. self.dateView.hidden = YES;
  533. self.fillColorView.hidden = YES;
  534. self.boderWidthStyleView.hidden = YES;
  535. self.defaultFontView.hidden = YES;
  536. self.figureView.hidden = YES;
  537. [self hiddenSubviews];
  538. [self updateBorderWidthView];
  539. }
  540. break;
  541. case CAnnotationTypeAnchored:
  542. {
  543. self.fontView.hidden = YES;
  544. self.borderColorView.hidden = YES;
  545. self.borderWidthView.hidden = YES;
  546. self.boderWidthStyleView.hidden = YES;
  547. self.rotateView.hidden = YES;
  548. self.backgroundView.hidden = YES;
  549. self.typeView.hidden = YES;
  550. self.dateView.hidden = YES;
  551. self.defaultFontView.hidden = YES;
  552. self.noteStyleView.hidden = NO;
  553. self.figureView.hidden = YES;
  554. _fillColorLabel.stringValue = NSLocalizedString(@"Color", nil);
  555. [self createTextProperties];
  556. [self updateFillColorPickerVC];
  557. }
  558. break;
  559. case CAnnotationTypeCircle:
  560. case CAnnotationTypeSquare:
  561. {
  562. self.fontView.hidden = YES;
  563. self.rotateView.hidden = YES;
  564. self.backgroundView.hidden = YES;
  565. self.typeView.hidden = YES;
  566. self.dateView.hidden = YES;
  567. self.defaultFontView.hidden = YES;
  568. if(self.pdfView.annotationType != CAnnotationTypeUnkown) {
  569. self.figureView.hidden = NO;
  570. [self updateFigureModel];
  571. } else {
  572. self.figureView.hidden = YES;
  573. }
  574. if (_annotationType == CAnnotationTypeCircle) {
  575. _borderColorLabel.stringValue = NSLocalizedString(@"Border Style", nil);
  576. }
  577. self.borderColorView.hidden = NO;
  578. self.borderOpacityView.hidden = NO;
  579. if ((_annotationType == CAnnotationTypeCircle || _annotationType == CAnnotationTypeSquare) && _annotationModel.annotations.count > 1) {
  580. BOOL otherType = NO;
  581. for (CPDFAnnotation *annotation in _annotationModel.annotations) {
  582. if ([annotation.type isEqualToString:@"Line"] || [annotation.type isEqualToString:@"Arrow"]) {
  583. otherType = YES;
  584. }
  585. }
  586. if (otherType) {
  587. self.fillColorView.hidden = YES;
  588. }
  589. }
  590. [self createSquareAndCircleProperties];
  591. [self updateBorderOpacityView];
  592. [self updateBorderWidthView];
  593. [self updateFillColorPickerVC];
  594. [self updateBorderColorPickerVC];
  595. [self updateFigureModel];
  596. }
  597. break;
  598. case CAnnotationTypeFreeText:
  599. case CAnnotationTypeSignText:
  600. {
  601. self.borderColorView.hidden = YES;
  602. self.borderWidthView.hidden = YES;
  603. self.boderWidthStyleView.hidden = YES;
  604. self.rotateView.hidden = YES;
  605. self.backgroundView.hidden = YES;
  606. self.typeView.hidden = YES;
  607. self.dateView.hidden = YES;
  608. self.figureView.hidden = YES;
  609. _fillColorLabel.stringValue = NSLocalizedString(@"Fill", nil);
  610. [self createFreeTextProperties];
  611. [self updateFillColorPickerVC];
  612. // [self updateFontView];
  613. [self selectTextAnnotation];
  614. }
  615. break;
  616. case CAnnotationTypeStamp:
  617. {
  618. self.fontView.hidden = YES;
  619. self.fillColorView.hidden = YES;
  620. self.borderColorView.hidden = YES;
  621. self.borderWidthView.hidden = YES;
  622. self.boderWidthStyleView.hidden = YES;
  623. self.backgroundView.hidden = YES;
  624. self.rotateView.hidden = YES;
  625. self.typeView.hidden = YES;
  626. self.dateView.hidden = YES;
  627. self.opacityView.hidden = YES;
  628. self.noteView.hidden = YES;
  629. self.defaultFontView.hidden = YES;
  630. self.figureView.hidden = YES;
  631. [self createStampProperties];
  632. }
  633. break;
  634. case CAnnotationTypeSignDate:
  635. self.fillColorView.hidden = YES;
  636. self.borderColorView.hidden = YES;
  637. self.borderWidthView.hidden = YES;
  638. self.boderWidthStyleView.hidden = YES;
  639. self.typeView.hidden = YES;
  640. self.rotateView.hidden = YES;
  641. self.noteView.hidden = YES;
  642. self.defaultFontView.hidden = YES;
  643. self.figureView.hidden = YES;
  644. [self createSelfSignFreeTextProperties];
  645. [self updateBackgroundColorPickerVC];
  646. // [self updateFontView];
  647. [self updateDateView];
  648. break;
  649. case CAnnotationTypeSignLine:
  650. case CAnnotationTypeSignDot:
  651. case CAnnotationTypeSignCircle:
  652. case CAnnotationTypeSignTure:
  653. case CAnnotationTypeSignFalse:
  654. self.fontView.hidden = YES;
  655. self.borderColorView.hidden = YES;
  656. self.backgroundView.hidden = YES;
  657. self.rotateView.hidden = YES;
  658. self.dateView.hidden = YES;
  659. self.noteView.hidden = YES;
  660. self.defaultFontView.hidden = YES;
  661. self.figureView.hidden = YES;
  662. if (_pdfView.annotationType == CAnnotationTypeSignDot) {
  663. self.borderWidthView.hidden = YES;
  664. self.boderWidthStyleView.hidden = YES;
  665. }
  666. self.typeView.hidden = self.annotationModel.annotation == nil;
  667. [self createSelfSignProperties];
  668. break;
  669. default:
  670. break;
  671. }
  672. }
  673. - (void)alignmentTypeSelected:(NSTextAlignment)type {
  674. self.leftAlignVC.state = KMDesignTokenStateNorm;
  675. self.centerAlignVC.state = KMDesignTokenStateNorm;
  676. self.rightAlignVC.state = KMDesignTokenStateNorm;
  677. if (type == NSTextAlignmentLeft) {
  678. self.leftAlignVC.state = KMDesignTokenStateSel;
  679. } else if (type == NSTextAlignmentCenter) {
  680. self.centerAlignVC.state = KMDesignTokenStateSel;
  681. } else if (type == NSTextAlignmentRight) {
  682. self.rightAlignVC.state = KMDesignTokenStateSel;
  683. }
  684. }
  685. - (void)updateOpacityView
  686. {
  687. CGFloat opacity = self.annotationModel.opacity;
  688. if(self.annotationModel.annotations.count > 1) {
  689. opacity = self.annotationModel.annotation.opacity;
  690. }
  691. if (CAnnotationTypeCircle == _annotationType ||
  692. CAnnotationTypeSquare == _annotationType) {
  693. opacity = self.annotationModel.interiorOpacity;
  694. } else if (CAnnotationTypeFreeText == _annotationType ||
  695. CAnnotationTypeSignDate == _annotationType ||
  696. CAnnotationTypeSignText == _annotationType ) {
  697. opacity = self.annotationModel.interiorOpacity;
  698. }
  699. self.opacitySlider.floatValue = opacity;
  700. self.opacitySlider.toolTip = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  701. self.opacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  702. self.generalImageView.image = [self.annotationModel annotationImage];
  703. }
  704. //边框颜色
  705. - (void)updateBorderOpacityView {
  706. CGFloat opacity = self.annotationModel.opacity;
  707. if(self.annotationModel.annotations.count > 1) {
  708. opacity = self.annotationModel.annotation.opacity;
  709. }
  710. self.borderOpacitySlider.floatValue = opacity;
  711. self.borderOpacitySlider.toolTip = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  712. self.borderOpacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  713. self.generalImageView.image = [self.annotationModel annotationImage];
  714. }
  715. - (void)updateBorderWidthView
  716. {
  717. CGFloat lineWidth = self.annotationModel.lineWidth;
  718. CPDFBorderStyle stype = self.annotationModel.style;
  719. if(self.annotationModel.annotations.count > 1) {
  720. lineWidth = self.annotationModel.annotation.borderWidth;
  721. stype = self.annotationModel.annotation.border.style;
  722. }
  723. self.borderWidthSlider.floatValue = lineWidth;
  724. self.borderWidthSlider.toolTip = [NSString stringWithFormat:@"%0.1f pt",lineWidth];
  725. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",lineWidth];
  726. self.generalImageView.image = [self.annotationModel annotationImage];
  727. if (self.annotationModel.annotationType == CAnnotationTypeEraser) return;
  728. if (stype == CPDFBorderStyleDashed) {
  729. self.borderWidthStyleDotted.wantsLayer = YES;
  730. self.borderWidthStyleDotted.layer.backgroundColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6].CGColor;
  731. self.borderWidthStyleDotted.layer.borderWidth = 1.0;
  732. self.borderWidthStyleDotted.layer.cornerRadius = 4.0;
  733. self.borderWidthStyleDotted.layer.borderColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:1].CGColor;
  734. self.borderWidthStyleReal.wantsLayer = YES;
  735. self.borderWidthStyleReal.layer.backgroundColor = [NSColor clearColor].CGColor;
  736. self.borderWidthStyleReal.layer.borderWidth = 0;
  737. self.borderWidthStyleReal.layer.cornerRadius = 0;
  738. self.borderWidthStyleReal.layer.borderColor = [NSColor clearColor].CGColor;
  739. } else if (stype == CPDFBorderStyleSolid) {
  740. self.borderWidthStyleReal.wantsLayer = YES;
  741. self.borderWidthStyleReal.layer.backgroundColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6].CGColor;
  742. self.borderWidthStyleReal.layer.borderWidth = 1.0;
  743. self.borderWidthStyleReal.layer.cornerRadius = 4.0;
  744. self.borderWidthStyleReal.layer.borderColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:1].CGColor;
  745. self.borderWidthStyleDotted.wantsLayer = YES;
  746. self.borderWidthStyleDotted.layer.backgroundColor = [NSColor clearColor].CGColor;
  747. self.borderWidthStyleDotted.layer.borderWidth = 0;
  748. self.borderWidthStyleDotted.layer.cornerRadius = 0;
  749. self.borderWidthStyleDotted.layer.borderColor = [NSColor clearColor].CGColor;
  750. }
  751. }
  752. - (void)updateInkAction:(NSButton *)currentButton {
  753. self.addInkButton.wantsLayer =
  754. self.inkView.wantsLayer =
  755. self.clearInkButton.wantsLayer = YES;
  756. self.addInkButton.layer.cornerRadius =
  757. self.inkView.layer.cornerRadius =
  758. self.clearInkButton.layer.cornerRadius = 4.0;
  759. self.addInkButton.layer.backgroundColor =
  760. self.inkView.layer.backgroundColor =
  761. self.clearInkButton.layer.backgroundColor = [NSColor colorWithSRGBRed:223.0/255.0 green:225.0/255.0 blue:229.0/255.0 alpha:1].CGColor;
  762. if (currentButton == self.addInkButton) {
  763. self.addInkButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  764. [self.addInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelADDSelect"]];
  765. [self.clearInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelClearNone"]];
  766. } else if (currentButton == self.clearInkButton) {
  767. self.clearInkButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  768. [self.addInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelADDNone"]];
  769. [self.clearInkButton setImage:[NSImage imageNamed:@"KMImagePropertPanelClearSelect"]];
  770. }
  771. }
  772. - (void)updateFillColorPickerVC
  773. {
  774. if (self.annotationModel.annotations.count > 0) {
  775. if (self.annotationModel.annotations.count > 1) {
  776. NSMutableArray *colors = [NSMutableArray array];
  777. for (CPDFAnnotation *annotation in self.annotationModel.annotations) {
  778. NSColor *color = nil;
  779. if ([annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
  780. [annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  781. if ([annotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  782. color = ((CPDFCircleAnnotation *)annotation).interiorColor;
  783. } else {
  784. color = ((CPDFSquareAnnotation *)annotation).interiorColor;
  785. }
  786. if (!color) {
  787. color = annotation.color;
  788. }
  789. self.fillColorPickerVC.isFillColor = YES;
  790. } else {
  791. color = annotation.color;
  792. }
  793. if (color) {
  794. [colors addObject:color];
  795. }
  796. }
  797. self.fillColorPickerVC.selectColors = colors;
  798. } else {
  799. NSColor *color = nil;
  800. CPDFAnnotation *firstAnnotation = self.annotationModel.annotations.firstObject;
  801. if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]] ||
  802. [firstAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  803. if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  804. color = ((CPDFCircleAnnotation *)firstAnnotation).interiorColor;
  805. } else {
  806. color = ((CPDFSquareAnnotation *)firstAnnotation).interiorColor;
  807. }
  808. self.fillColorPickerVC.isFillColor = YES;
  809. } else {
  810. color = firstAnnotation.color;
  811. }
  812. self.fillColorPickerVC.color = color;
  813. }
  814. } else {
  815. NSColor *color = nil;
  816. if (CAnnotationTypeCircle == _annotationType ||
  817. CAnnotationTypeSquare == _annotationType) {
  818. color = self.annotationModel.interiorColor;
  819. self.fillColorPickerVC.isFillColor = YES;
  820. } else {
  821. color = self.annotationModel.color;
  822. }
  823. if (!color) {
  824. color = [NSColor clearColor];
  825. }
  826. self.fillColorPickerVC.color = color;
  827. }
  828. self.generalImageView.image = [self.annotationModel annotationImage];
  829. }
  830. - (void)updateBackgroundColorPickerVC
  831. {
  832. NSColor *color = nil;
  833. if (CAnnotationTypeSignDate == _annotationType) {
  834. color = self.annotationModel.color;
  835. if (color) {
  836. CGFloat red,green,blue,alpha;
  837. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  838. color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.opacity];
  839. }
  840. self.backgroundColorPickerVC.color = color;
  841. }
  842. self.generalImageView.image = [self.annotationModel annotationImage];
  843. }
  844. - (void)updateBorderColorPickerVC
  845. {
  846. NSColor *color = self.annotationModel.color;
  847. if (self.annotationModel.annotations.count > 1) {
  848. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  849. color = firstAnnotation.color;
  850. } else {
  851. color = self.annotationModel.color;
  852. }
  853. self.borderColorPickerVC.color = color;
  854. self.generalImageView.image = [self.annotationModel annotationImage];
  855. }
  856. - (void)updateDateView
  857. {
  858. [_datePopupButton removeAllItems];
  859. BOOL includeTime = self.annotationModel.includeTime;
  860. [_datePopupButton addItemsWithTitles:[KMSelfSignAnnotationFreeText fetchAllDateString:includeTime]];
  861. NSInteger dateFormatIndex = self.annotationModel.dateFormatIndex;
  862. if (dateFormatIndex >= 0 && dateFormatIndex < _datePopupButton.numberOfItems) {
  863. [_datePopupButton selectItemAtIndex:dateFormatIndex];
  864. } else {
  865. [_datePopupButton selectItemAtIndex:0];
  866. }
  867. _dateButton.state = includeTime ? NSControlStateValueOn:NSControlStateValueOff;
  868. }
  869. - (void)typeSelected:(CAnnotationType)type
  870. {
  871. _falseTypeButton.layer.backgroundColor =
  872. _tureTypeButton.layer.backgroundColor =
  873. _circletypeButton.layer.backgroundColor =
  874. _lineTypeButton.layer.backgroundColor =
  875. _dotTypeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  876. _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkNor"];
  877. _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickNor"];
  878. _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRoundedrecNor"];
  879. _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineNor"];
  880. // _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointNor"];
  881. if (type == CAnnotationTypeSignFalse) {
  882. self.falseTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  883. _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkSel"];
  884. } else if (type == CAnnotationTypeSignTure) {
  885. self.tureTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  886. _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickSel"];
  887. } else if (type == CAnnotationTypeSignCircle){
  888. self.circletypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  889. _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRounderdrecSel"];
  890. } else if (type == CAnnotationTypeSignLine) {
  891. self.lineTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  892. _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineSel"];
  893. } else if (type == CAnnotationTypeSignDot) {
  894. self.dotTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  895. _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointSet"];
  896. }
  897. }
  898. - (void)updateAnnotation
  899. {
  900. CPDFAnnotation *annotation = self.annotationModel.annotation;
  901. if (annotation) {
  902. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  903. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  904. if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
  905. [self.pdfView commitEditAnnotationFreeText:textNote];
  906. }
  907. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:self.pdfView.activeAnnotations];
  908. annotationModel.fontName = self.annotationModel.fontName;
  909. [self.pdfView setNeedsDisplayAnnotation:self.pdfView.activeAnnotation];
  910. }
  911. for (CPDFAnnotation *tAnnotation in self.annotationModel.annotations) {
  912. if([tAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  913. [(KMSelfSignAnnotation *)tAnnotation updateAppearanceStream];
  914. }
  915. if ([tAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  916. [self.pdfView setNeedsDisplayForPage:tAnnotation.page];
  917. } else {
  918. [self.pdfView setNeedsDisplayAnnotationViewForPage:tAnnotation.page];
  919. }
  920. }
  921. }
  922. self.generalImageView.image = [self.annotationModel annotationImage];
  923. }
  924. - (NSDictionary *)freeTextPropertWithTitle:(NSInteger)integer {
  925. NSDictionary *model;
  926. NSArray *array = [CPDFAnnotationModel defaultFreeTextPropert];
  927. // if ([string isEqualToString:@"Customize"]) {
  928. // model = [array objectAtIndex:0];
  929. // } else if ([string isEqualToString:@"H1 Headline"]) {
  930. // model = [array objectAtIndex:1];
  931. // } else if ([string isEqualToString:@"H2 Title"]) {
  932. // model = [array objectAtIndex:2];
  933. // } else if ([string isEqualToString:@"H3 Subtitle"]) {
  934. // model = [array objectAtIndex:3];
  935. // } else if ([string isEqualToString:@"B1 Text"]) {
  936. // model = [array objectAtIndex:4];
  937. // } else if ([string isEqualToString:@"B2 Small Text"]) {
  938. // model = [array objectAtIndex:5];
  939. // } else if ([string isEqualToString:@"B3 Describtion"]) {
  940. // model = [array objectAtIndex:6];
  941. // }
  942. model = [array objectAtIndex:integer];
  943. return model;
  944. }
  945. #pragma mark MarkUp
  946. - (void)createMarkupProperties {
  947. [self hiddenSubviews];
  948. _fillColorBox.contentView = _fillColorPickerVC.view;
  949. __block typeof(self) blockSelf = self;
  950. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  951. blockSelf.annotationModel.color = color;
  952. blockSelf.annotationModel.opacity = color.alphaComponent;
  953. [blockSelf updateOpacityView];
  954. [blockSelf updateAnnotation];
  955. };
  956. if (CAnnotationTypeHighlight == _annotationType) {
  957. self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupHighlightColors;
  958. } else {
  959. self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupOtherColors;
  960. }
  961. }
  962. #pragma mark SKLineNote
  963. - (void)createInkAndLineProperties {
  964. [self hiddenSubviews];
  965. _fillColorBox.contentView = _fillColorPickerVC.view;
  966. __block typeof(self) blockSelf = self;
  967. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  968. if (color) {
  969. CGFloat r, g, b, a = 0.0;
  970. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  971. blockSelf.annotationModel.color = color;
  972. blockSelf.annotationModel.opacity = a;
  973. } else {
  974. blockSelf.annotationModel.color = [NSColor blackColor];
  975. blockSelf.annotationModel.opacity = 0;
  976. }
  977. [blockSelf updateOpacityView];
  978. [blockSelf updateAnnotation];
  979. };
  980. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  981. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  982. if (CAnnotationTypeLine == self.annotationModel.annotationType ||
  983. CAnnotationTypeArrow == self.annotationModel.annotationType) {
  984. self.fillColorPickerVC.annotationType = KMPropertiesColor_LineColors;
  985. } else if (CAnnotationTypeInk == self.annotationModel.annotationType) {
  986. self.fillColorPickerVC.annotationType = KMPropertiesColor_InkColors;
  987. }
  988. }
  989. - (void)updateFigureModel {
  990. if(self.pdfView.annotationType != CAnnotationTypeUnkown) {
  991. if (_annotationType == CAnnotationTypeSquare) {
  992. self.squareVC.state = KMDesignTokenStateSel;
  993. } else if (_annotationType == CAnnotationTypeCircle) {
  994. self.circleVC.state = KMDesignTokenStateSel;
  995. } else if (_annotationType == CAnnotationTypeArrow) {
  996. self.arrowVC.state = KMDesignTokenStateSel;
  997. } else if (_annotationType == CAnnotationTypeLine) {
  998. self.lineVC.state = KMDesignTokenStateSel;
  999. }
  1000. }
  1001. }
  1002. #pragma mark - SquareNote、CircleNote、ArrowNote Properties
  1003. - (void)createSquareAndCircleProperties {
  1004. [self hiddenSubviews];
  1005. __block typeof(self) blockSelf = self;
  1006. _fillColorBox.contentView = _fillColorPickerVC.view;
  1007. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1008. CGFloat red,green,blue,alpha;
  1009. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1010. if (fabs(alpha - 0) < 0.001) {
  1011. blockSelf.annotationModel.interiorColor = nil;
  1012. } else {
  1013. blockSelf.annotationModel.interiorColor = color;
  1014. }
  1015. [blockSelf updateAnnotation];
  1016. };
  1017. _borderColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1018. if (color) {
  1019. blockSelf.annotationModel.color = color;
  1020. blockSelf.annotationModel.opacity = 1;
  1021. } else {
  1022. //设置透明色必须要设一个颜色值
  1023. blockSelf.annotationModel.color = [NSColor blackColor];
  1024. blockSelf.annotationModel.opacity = 0;
  1025. }
  1026. [blockSelf updateOpacityView];
  1027. [blockSelf updateAnnotation];
  1028. };
  1029. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1030. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1031. self.fillColorPickerVC.annotationType = KMPropertiesColor_LineFillColors;
  1032. self.fillColorPickerVC.isFillColor = YES;
  1033. self.borderColorPickerVC.annotationType = KMPropertiesColor_CircleLineColors;
  1034. }
  1035. #pragma mark - FreeTextNote、KMPDFAnnotationFreeText Properties
  1036. - (void)createFreeTextProperties {
  1037. [self hiddenSubviews];
  1038. __block typeof(self) blockSelf = self;
  1039. _fillColorBox.contentView = _fillColorPickerVC.view;
  1040. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1041. CGFloat red,green,blue,alpha;
  1042. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1043. if(alpha == 0) {
  1044. blockSelf.annotationModel.color = nil;
  1045. } else {
  1046. blockSelf.annotationModel.color = color;
  1047. }
  1048. [blockSelf updateOpacityView];
  1049. CPDFAnnotation *annotation = blockSelf.annotationModel.annotation;
  1050. if (annotation) {
  1051. [blockSelf.pdfView setNeedsDisplayAnnotationViewForPage:annotation.page];
  1052. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1053. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  1054. if ([blockSelf.pdfView isEditWithCurrentFreeText:textNote]) {
  1055. [blockSelf.pdfView setEditAnnotationFreeTextBackgroundColor:color freeText:textNote];
  1056. } else {
  1057. [blockSelf updateAnnotation];
  1058. }
  1059. }
  1060. blockSelf.generalImageView.image = [blockSelf.annotationModel annotationImage];
  1061. } else {
  1062. [blockSelf updateAnnotation];
  1063. }
  1064. };
  1065. if (CAnnotationTypeFreeText == _annotationType ||
  1066. CAnnotationTypeSignDate == _annotationType ||
  1067. CAnnotationTypeSignText == _annotationType) {
  1068. self.fontColorButton.color = self.annotationModel.fontColor;
  1069. [self.fontColorButton setNeedsDisplay:YES];
  1070. }
  1071. self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
  1072. self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
  1073. self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
  1074. // NSArray *array = @[blockSelf.leftAlignBox,blockSelf.centerAlignBox,blockSelf.rightAlignBox];
  1075. // for (KMBox *box in array) {
  1076. // box.fillColor = [NSColor clearColor];
  1077. // box.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
  1078. // if (downEntered) {
  1079. // box.fillColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6];
  1080. // if (box == blockSelf.leftAlignBox) {
  1081. // [blockSelf leftAlignButtonAction:box];
  1082. // } else if (box == blockSelf.centerAlignBox) {
  1083. // [blockSelf centerAlignButtonAction:box];
  1084. // } else if (box == blockSelf.rightAlignBox) {
  1085. // [blockSelf rightAlignButtonAction:box];
  1086. // }
  1087. // } else {
  1088. // box.fillColor = [NSColor clearColor];
  1089. // }
  1090. // };
  1091. // box.mouseMoveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
  1092. // if (mouseEntered) {
  1093. // box.fillColor = [NSColor colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
  1094. // } else {
  1095. // box.fillColor = [NSColor clearColor];
  1096. // }
  1097. // };
  1098. // }
  1099. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1100. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1101. self.fillColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
  1102. }
  1103. #pragma mark - FreeTextNote、SelfSignAnnotationFreeText Properties
  1104. - (void)createSelfSignFreeTextProperties {
  1105. [self hiddenSubviews];
  1106. __block typeof(self) blockSelf = self;
  1107. // NSArray *array = @[blockSelf.leftAlignBox,blockSelf.centerAlignBox,blockSelf.rightAlignBox];
  1108. // for (KMBox *box in array) {
  1109. // box.fillColor = [NSColor clearColor];
  1110. // box.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
  1111. // if (downEntered) {
  1112. // box.fillColor = [NSColor colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
  1113. // if (box == blockSelf.leftAlignBox) {
  1114. // [blockSelf leftAlignButtonAction:box];
  1115. // } else if (box == blockSelf.centerAlignBox) {
  1116. // [blockSelf centerAlignButtonAction:box];
  1117. // } else if (box == blockSelf.rightAlignBox) {
  1118. // [blockSelf rightAlignButtonAction:box];
  1119. // }
  1120. // } else {
  1121. // box.fillColor = [NSColor clearColor];
  1122. // }
  1123. // };
  1124. // box.mouseMoveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
  1125. // if (mouseEntered) {
  1126. // box.fillColor = [NSColor lightGrayColor];
  1127. // } else {
  1128. // box.fillColor = [NSColor clearColor];
  1129. // }
  1130. // };
  1131. // }
  1132. _backgroundBox.contentView = _backgroundColorPickerVC.view;
  1133. _backgroundColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1134. CGFloat r, g, b, a = 0.0;
  1135. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1136. if(a == 0) {
  1137. blockSelf.annotationModel.color = nil;
  1138. } else {
  1139. blockSelf.annotationModel.color = color;
  1140. }
  1141. [blockSelf updateOpacityView];
  1142. [blockSelf updateAnnotation];
  1143. };
  1144. if ([self.annotationModel.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1145. self.fontColorButton.color = self.annotationModel.fontColor;
  1146. [self.fontColorButton setNeedsDisplay:YES];
  1147. }
  1148. self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
  1149. self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
  1150. self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
  1151. NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc]initWithAttributedString:[_dateButton attributedTitle]];
  1152. NSUInteger len = [attrTitle length];
  1153. NSRange range = NSMakeRange(0, len);
  1154. [attrTitle addAttribute:NSForegroundColorAttributeName
  1155. value:[NSColor lightGrayColor]
  1156. range:range];
  1157. [attrTitle fixAttributesInRange:range];
  1158. [_dateButton setAttributedTitle:attrTitle];
  1159. if ([self.annotationModel.annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  1160. if (self.annotationModel.annotation.contents.length <= 0) {
  1161. self.annotationModel.annotation.contents = self.datePopupButton.title;
  1162. }
  1163. }
  1164. self.backgroundColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
  1165. }
  1166. #pragma mark - KMSelfSignAnnotation
  1167. - (void)createSelfSignProperties {
  1168. [self hiddenSubviews];
  1169. __block typeof(self) blockSelf = self;
  1170. _fillColorBox.contentView = _fillColorPickerVC.view;
  1171. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1172. CGFloat r, g, b, a = 0.0;
  1173. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1174. blockSelf.annotationModel.color = color;
  1175. blockSelf.annotationModel.opacity = a;
  1176. [blockSelf updateOpacityView];
  1177. [blockSelf updateAnnotation];
  1178. };
  1179. if (self.annotationModel.annotation) {
  1180. CAnnotationType annotationType = [(KMSelfSignAnnotation *)self.annotationModel.annotation annotationType];
  1181. [self typeSelected:annotationType];
  1182. }
  1183. NSColor *color = self.annotationModel.color;
  1184. CGFloat r, g, b, a = 0.0;
  1185. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1186. CGFloat opacity = self.annotationModel.opacity;
  1187. // [self.borderWidthComboBox removeAllItems];
  1188. // NSMutableArray *titles = @[@"1 pt",@"3 pt",@"6 pt",@"9 pt",@"12 pt"].mutableCopy;
  1189. // for (NSString *string in titles) {
  1190. // [self.borderWidthComboBox addItemWithObjectValue:string];
  1191. // }
  1192. self.borderWidthSlider.maxValue = 12;
  1193. self.fillColorPickerVC.color = [NSColor colorWithRed:r green:g blue:b alpha:opacity];
  1194. self.opacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  1195. self.opacitySlider.floatValue = opacity;
  1196. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1197. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1198. self.fillColorPickerVC.annotationType = KMPropertiesColor_SelfSignColors;
  1199. }
  1200. -(NSUInteger)setFontStyleWithFontName:(NSString *)fontName currentStyle:(NSString *)style
  1201. {
  1202. NSUInteger selectIndex = -1;
  1203. // NSMenu *menu = [[NSMenu alloc] init];
  1204. NSMutableArray *fontStyles = [NSMutableArray array];
  1205. for (NSDictionary *dic in self.fonts) {
  1206. NSString *familyString = dic.allKeys.firstObject;
  1207. if ([familyString isEqual:fontName]) {
  1208. NSArray *styles = [dic objectForKey:fontName];
  1209. for (NSUInteger i = 0; i < styles.count; i++) {
  1210. NSString * styleName = [styles objectAtIndex:i];
  1211. if ([style isEqualToString:styleName]) {
  1212. selectIndex = i;
  1213. }
  1214. NSFontDescriptor *attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName,NSFontFaceAttribute:styleName}];
  1215. if ([styleName isEqualToString:@"Roman"]) {
  1216. attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName}];
  1217. selectIndex = 0;
  1218. }
  1219. // NSFont *font = [NSFont fontWithDescriptor:attributeFontDescriptor size:12.0];
  1220. // NSDictionary *attrited = @{NSFontAttributeName:font};
  1221. // NSAttributedString *string = [[NSAttributedString alloc] initWithString:styleName attributes:attrited];
  1222. // NSMenuItem *item = [[NSMenuItem alloc] init];
  1223. // item.attributedTitle = string;
  1224. // [menu addItem:item];
  1225. [fontStyles addObject:styleName];
  1226. }
  1227. break;
  1228. }
  1229. }
  1230. if (!style) {
  1231. selectIndex = 0;
  1232. }
  1233. // [self.fontStylePopUpButton setMenu:menu];
  1234. return selectIndex;
  1235. }
  1236. - (void)resetTextPresuppositionButtonAction:(NSButton *)sender {
  1237. NSArray *popViewDataArr = @[NSLocalizedString(@"Reset", nil), NSLocalizedString(@"Redefine", nil)];
  1238. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  1239. // NSString *type = KMEditPDFTextFontTypeWrapper.allValues[index + 1];
  1240. KMEditPDFTextFontModel *model = KMEditPDFTextManager.manager.fetchAllUserDefaultData[index];
  1241. NSMutableArray *disItems = [NSMutableArray arrayWithArray:popViewDataArr];
  1242. if (model.change || model.redefine) {
  1243. [disItems removeObject:NSLocalizedString(@"Reset", nil)];
  1244. }
  1245. if (model.change) {
  1246. [disItems removeObject:NSLocalizedString(@"Redefine", nil)];
  1247. }
  1248. KMHomePopViewController *popVC = [[KMHomePopViewController alloc] initWithNibName:@"KMHomePopViewController" bundle:nil];
  1249. popVC.dataArr = popViewDataArr;
  1250. popVC.disItems = disItems;
  1251. NSPopover *createFilePopover = [[NSPopover alloc] init];
  1252. createFilePopover.contentViewController = popVC;
  1253. createFilePopover.animates = true;
  1254. createFilePopover.behavior = NSPopoverBehaviorSemitransient;
  1255. [createFilePopover setValue: @(YES) forKey: @"shouldHideAnchor"];
  1256. [createFilePopover showRelativeToRect:CGRectMake(sender.bounds.origin.x, -10, sender.bounds.size.width, sender.bounds.size.height)
  1257. ofView:sender
  1258. preferredEdge:NSRectEdgeMaxY];
  1259. popVC.downCallback = ^(BOOL downEntered, NSString * _Nonnull count) {
  1260. if (downEntered) {
  1261. if ([count isEqualToString:@"Reset"]) {
  1262. [self resetTextPresuppositionData];
  1263. } else if([count isEqualToString:@"Redefine"]) {
  1264. [self reDefineTextPresuppositionData:YES];
  1265. }
  1266. [createFilePopover close];
  1267. }
  1268. };
  1269. }
  1270. #pragma mark annotation text
  1271. - (void)createTextProperties {
  1272. [self hiddenSubviews];
  1273. __block typeof(self) blockSelf = self;
  1274. _fillColorBox.contentView = _fillColorPickerVC.view;
  1275. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1276. blockSelf.annotationModel.color = color;
  1277. [blockSelf updateOpacityView];
  1278. [blockSelf updateAnnotation];
  1279. };
  1280. self.fillColorPickerVC.annotationType = KMPropertiesColor_AnchoredNoteColors;
  1281. self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOne"];
  1282. self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStylenote"];
  1283. self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWord"];
  1284. self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStyleHelp"];
  1285. self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStyleP"];
  1286. self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsert"];
  1287. self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNP"];
  1288. CPDFTextAnnotationIconType type = CPDFTextAnnotationIconNote;
  1289. if (self.annotationModel.annotations.count > 0) {
  1290. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1291. if([firstAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  1292. type = [(CPDFTextAnnotation *)firstAnnotation iconType];
  1293. }
  1294. } else {
  1295. type = self.annotationModel.anchoredIconType;
  1296. }
  1297. switch (type) {
  1298. case CPDFTextAnnotationIconComment:
  1299. self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOneSelect"];
  1300. break;
  1301. case CPDFTextAnnotationIconKey:
  1302. self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWordSelect"];
  1303. break;
  1304. case CPDFTextAnnotationIconNote:
  1305. self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStyleNoteSelect"];
  1306. break;
  1307. case CPDFTextAnnotationIconHelp:
  1308. self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStylehelpSelect"];
  1309. break;
  1310. case CPDFTextAnnotationIconNewParagraph:
  1311. self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNPSelect"];
  1312. break;
  1313. case CPDFTextAnnotationIconParagraph:
  1314. self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStylePSelect"];
  1315. break;
  1316. case CPDFTextAnnotationIconInsert:
  1317. self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsertSelect"];
  1318. break;
  1319. default:
  1320. break;
  1321. }
  1322. }
  1323. - (void)selectTextAnnotation {
  1324. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1325. if ([firstAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1326. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)firstAnnotation;
  1327. // if (_annotationModel.annotations.count > 1) {
  1328. NSFont *currentFont = textNote.font;
  1329. NSString *fontName = [KMEditPDFTextManager.manager fetchFontNameWithFontName:currentFont.fontName];
  1330. NSString *fontStyle = [KMEditPDFTextManager.manager fetchFontStyleWithFontName:currentFont.fontName];
  1331. NSInteger fontSize = currentFont.pointSize;
  1332. NSColor *color = textNote.fontColor;
  1333. NSTextAlignment alignment = textNote.alignment;
  1334. [self alignmentTypeSelected:alignment];
  1335. [self updateFontSize:fontSize needChangeListView:NO needSave:NO];
  1336. [self updateFontNameAndStyle:fontName style:fontStyle needChangeListView:NO needSave:NO];
  1337. [self updateTextTextPresuppositionState:currentFont.fontName size:fontSize];
  1338. // }
  1339. } else {
  1340. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
  1341. NSString *fontName = [KMEditPDFTextManager.manager fetchFontNameWithFontName:model.fontName];
  1342. if (![self.fontNameVC.items containsObject:fontName]) {
  1343. fontName = self.fontNameVC.items.firstObject;
  1344. }
  1345. NSString *fontStyle = [KMEditPDFTextManager.manager fetchFontStyleWithFontName:model.fontName];
  1346. if (![self.fontStyleVC.items containsObject:fontStyle]) {
  1347. fontStyle = self.fontStyleVC.items.firstObject;
  1348. }
  1349. CGFloat size = model.fontSize;
  1350. [self updateFontSize:size needChangeListView:NO needSave:NO];
  1351. [self updateFontNameAndStyle:fontName style:fontStyle needChangeListView:NO needSave:NO];
  1352. [self alignmentTypeSelected: NSTextAlignmentLeft];
  1353. }
  1354. }
  1355. #pragma mark annotation Ink
  1356. - (IBAction)updateInkStype:(NSButton *)sender {
  1357. self.annotationModel.style = sender.tag;
  1358. [self updateBorderWidthView];
  1359. [self updateAnnotation];
  1360. }
  1361. - (IBAction)updateInkButton_click:(NSButton *)sender {
  1362. [self updateInkAction:sender];
  1363. if ((sender == self.addInkButton && _annotationType == CAnnotationTypeInk) || (sender == self.clearInkButton && _annotationType == CAnnotationTypeEraser)) {
  1364. return;
  1365. }
  1366. if (sender != self.addInkButton) {
  1367. self.pdfView.annotationType = CAnnotationTypeEraser;
  1368. [self.borderWidthVC removeAllItems];
  1369. [self.borderWidthVC addItemsWithObjectValues:@[@"5pt",@"10pt",@"15pt",@"20pt"]];
  1370. } else {
  1371. [self.borderWidthVC removeAllItems];
  1372. [self.borderWidthVC addItemsWithObjectValues:@[@"1pt",@"2pt",@"4pt",@"6pt",@"8pt"]];
  1373. self.pdfView.annotationType = CAnnotationTypeInk;
  1374. }
  1375. if (self.callBack) {
  1376. self.callBack (self.pdfView.annotationType);
  1377. }
  1378. self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
  1379. [self loadingUIAndLocalization];
  1380. }
  1381. #pragma mark annotation stamp
  1382. - (IBAction)showOpacityView:(id)sender {
  1383. KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
  1384. vc.annotationModel = self.annotationModel;
  1385. if (!_fillColorPopover) {
  1386. _fillColorPopover = [[NSPopover alloc] init];
  1387. _fillColorPopover.delegate = self;
  1388. }
  1389. _fillColorPopover.contentViewController = vc;
  1390. _fillColorPopover.animates = YES;
  1391. _fillColorPopover.behavior = NSPopoverBehaviorSemitransient;
  1392. [_fillColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
  1393. [_fillColorPopover showRelativeToRect:NSMakeRect(_fillColorView.bounds.origin.x, 57, _fillColorView.bounds.size.width, _fillColorView.bounds.size.height) ofView:_fillColorView preferredEdge:NSRectEdgeMinY];
  1394. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1395. __block typeof(self) blockSelf = self;
  1396. vc.callback = ^(CGFloat opacity) {
  1397. [blockSelf updateFillColorPickerVC];
  1398. [blockSelf updateAnnotation];
  1399. };
  1400. }
  1401. - (IBAction)showBorderOpacityView:(id)sender {
  1402. KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
  1403. vc.annotationModel = self.annotationModel;
  1404. if (!_borderColorPopover) {
  1405. _borderColorPopover = [[NSPopover alloc] init];
  1406. _borderColorPopover.delegate = self;
  1407. }
  1408. _borderColorPopover.contentViewController = vc;
  1409. _borderColorPopover.animates = YES;
  1410. _borderColorPopover.behavior = NSPopoverBehaviorSemitransient;
  1411. [_borderColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
  1412. [_borderColorPopover showRelativeToRect:NSMakeRect(_borderColorView.bounds.origin.x, 47, _borderColorView.bounds.size.width, _borderColorView.bounds.size.height) ofView:_borderColorView preferredEdge:NSRectEdgeMinY];
  1413. if (_annotationModel.annotations.count > 0) {
  1414. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1415. if ([firstAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  1416. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1417. } else {
  1418. vc.type = AnnotationOpacityTypeOpacity;
  1419. }
  1420. } else {
  1421. if (_annotationModel.annotationType == CAnnotationTypeLine ||
  1422. _annotationModel.annotationType == CAnnotationTypeArrow) {
  1423. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1424. } else {
  1425. vc.type = AnnotationOpacityTypeOpacity;
  1426. }
  1427. }
  1428. __block typeof(self) blockSelf = self;
  1429. vc.callback = ^(CGFloat opacity) {
  1430. [blockSelf updateBorderColorPickerVC];
  1431. [blockSelf updateAnnotation];
  1432. };
  1433. }
  1434. - (void)createStampProperties {
  1435. [self hiddenSubviews];
  1436. }
  1437. #pragma mark - UI Action
  1438. - (IBAction)opacitySliderAction:(id)sender
  1439. {
  1440. CGFloat opcity = self.opacitySlider.floatValue;
  1441. if (self.opacitySlider.floatValue == 0) {
  1442. opcity = 0.0001;
  1443. }
  1444. CAnnotationType annotationType = self.annotationModel.annotationType;
  1445. if (CAnnotationTypeSignFalse == annotationType ||
  1446. CAnnotationTypeSignTure == annotationType ||
  1447. CAnnotationTypeSignDot == annotationType ||
  1448. CAnnotationTypeSignCircle == annotationType ||
  1449. CAnnotationTypeSignLine == annotationType) {
  1450. self.annotationModel.opacity = opcity;
  1451. [self updateFillColorPickerVC];
  1452. } else if(CAnnotationTypeCircle == annotationType ||
  1453. CAnnotationTypeSquare == annotationType){
  1454. if(opcity !=0) {
  1455. self.annotationModel.opacity = opcity;
  1456. self.annotationModel.interiorOpacity= opcity;
  1457. } else {
  1458. self.annotationModel.color = nil;
  1459. self.annotationModel.interiorColor= nil;
  1460. }
  1461. [self updateFillColorPickerVC];
  1462. [self updateBorderColorPickerVC];
  1463. } else if (CAnnotationTypeFreeText == annotationType ||
  1464. CAnnotationTypeSignDate == annotationType ||
  1465. CAnnotationTypeSignText == annotationType ) {
  1466. self.annotationModel.opacity = opcity;
  1467. [self updateBackgroundColorPickerVC];
  1468. NSColor *color = self.annotationModel.fontColor;
  1469. if (self.annotationModel.opacity != 0) {
  1470. CGFloat red,green,blue,alpha;
  1471. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1472. color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.interiorOpacity];
  1473. } else {
  1474. color = [NSColor clearColor];
  1475. }
  1476. self.fontColorButton.color = color;
  1477. [self.fontColorButton setNeedsDisplay:YES];
  1478. } else {
  1479. self.annotationModel.opacity = opcity;
  1480. [self updateFillColorPickerVC];
  1481. }
  1482. [self updateOpacityView];
  1483. [self updateAnnotation];
  1484. }
  1485. - (IBAction)borderOpacitySliderAction:(id)sender
  1486. {
  1487. CGFloat opcity = self.borderOpacitySlider.floatValue;
  1488. if (self.borderOpacitySlider.floatValue == 0) {
  1489. opcity = 0.0001;
  1490. }
  1491. CAnnotationType annotationType = self.annotationModel.annotationType;
  1492. if(CAnnotationTypeCircle == annotationType ||
  1493. CAnnotationTypeSquare == annotationType){
  1494. if(opcity !=0) {
  1495. self.annotationModel.opacity = opcity;
  1496. } else {
  1497. self.annotationModel.color = nil;
  1498. self.annotationModel.interiorColor= nil;
  1499. }
  1500. [self updateFillColorPickerVC];
  1501. [self updateBorderColorPickerVC];
  1502. }
  1503. [self updateBorderOpacityView];
  1504. [self updateAnnotation];
  1505. }
  1506. - (IBAction)opacityComboBoxAction:(id)sender
  1507. {
  1508. [self.opacitySlider setFloatValue:(CGFloat)[self.opacityComboBox intValue]/100];
  1509. CGFloat opcity = self.opacitySlider.floatValue;
  1510. if (self.opacitySlider.floatValue == 0) {
  1511. opcity = 0.0001;
  1512. }
  1513. CAnnotationType annotationType = self.annotationModel.annotationType;
  1514. if (CAnnotationTypeSignFalse == annotationType ||
  1515. CAnnotationTypeSignTure == annotationType ||
  1516. CAnnotationTypeSignDot == annotationType ||
  1517. CAnnotationTypeSignCircle == annotationType ||
  1518. CAnnotationTypeSignLine == annotationType) {
  1519. self.annotationModel.opacity = opcity;
  1520. [self updateFillColorPickerVC];
  1521. } else if(CAnnotationTypeCircle == annotationType ||
  1522. CAnnotationTypeSquare == annotationType){
  1523. if(opcity !=0) {
  1524. self.annotationModel.opacity = opcity;
  1525. self.annotationModel.interiorOpacity= opcity;
  1526. } else {
  1527. self.annotationModel.color = nil;
  1528. self.annotationModel.interiorColor= nil;
  1529. }
  1530. [self updateFillColorPickerVC];
  1531. [self updateBorderColorPickerVC];
  1532. } else if (CAnnotationTypeFreeText == annotationType ||
  1533. CAnnotationTypeSignDate == annotationType ||
  1534. CAnnotationTypeSignText == annotationType ) {
  1535. self.annotationModel.interiorOpacity = opcity;
  1536. [self updateBackgroundColorPickerVC];
  1537. } else {
  1538. self.annotationModel.opacity = opcity;
  1539. [self updateFillColorPickerVC];
  1540. }
  1541. [self updateOpacityView];
  1542. [self updateAnnotation];
  1543. }
  1544. - (IBAction)borderWidthSliderAction:(id)sender
  1545. {
  1546. self.annotationModel.lineWidth = self.borderWidthSlider.floatValue;
  1547. [self updateBorderWidthView];
  1548. [self updateAnnotation];
  1549. }
  1550. - (IBAction)leftAlignButtonAction:(NSBox *)sender {
  1551. [self updateAnnotation];
  1552. NSTextAlignment alignment = NSTextAlignmentLeft;
  1553. self.annotationModel.alignment = alignment;
  1554. [self alignmentTypeSelected:alignment];
  1555. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1556. [self updateAnnotation];
  1557. }
  1558. - (IBAction)centerAlignButtonAction:(NSBox *)sender {
  1559. [self updateAnnotation];
  1560. NSTextAlignment alignment = NSTextAlignmentCenter;
  1561. self.annotationModel.alignment = alignment;
  1562. [self alignmentTypeSelected:alignment];
  1563. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1564. [self updateAnnotation];
  1565. }
  1566. - (IBAction)rightAlignButtonAction:(NSBox *)sender {
  1567. [self updateAnnotation];
  1568. NSTextAlignment alignment = NSTextAlignmentRight;
  1569. self.annotationModel.alignment = alignment;
  1570. [self alignmentTypeSelected:alignment];
  1571. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1572. [self updateAnnotation];
  1573. }
  1574. - (IBAction)justifiedAlignButtonAction:(NSBox *)sender {
  1575. [self updateAnnotation];
  1576. NSTextAlignment alignment = NSTextAlignmentJustified;
  1577. self.annotationModel.alignment = alignment;
  1578. [self alignmentTypeSelected:alignment];
  1579. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1580. [self updateAnnotation];
  1581. }
  1582. - (IBAction)currentFontColorButtonAction:(NSButton *)sender {
  1583. KMAnnotationFontWindowController *fontWindowController = [KMAnnotationFontWindowController sharedAnnotationFont];
  1584. fontWindowController.PDFListView = self.pdfView;
  1585. NSWindow *window = [fontWindowController window];
  1586. fontWindowController.annotationModel = self.annotationModel;
  1587. __block typeof(self) blockSelf = self;
  1588. fontWindowController.annotationAlignCallback = ^(NSInteger selectedCount) {
  1589. NSTextAlignment textAlignment = NSTextAlignmentLeft;
  1590. if (selectedCount == 0) {
  1591. textAlignment = NSTextAlignmentLeft;
  1592. } else if (selectedCount == 2) {
  1593. textAlignment = NSTextAlignmentCenter;
  1594. } else if (selectedCount == 1) {
  1595. textAlignment = NSTextAlignmentRight;
  1596. } else if (selectedCount == 3) {
  1597. textAlignment = NSTextAlignmentJustified;
  1598. }
  1599. [blockSelf alignmentTypeSelected:selectedCount];
  1600. if(blockSelf.annotationModel) {
  1601. blockSelf.annotationModel.alignment = textAlignment;
  1602. [blockSelf updateAnnotation];
  1603. }
  1604. };
  1605. fontWindowController.annotationCallback = ^(CPDFAnnotation *annotation) {
  1606. // [blockSelf updateFontView];
  1607. [blockSelf updateAnnotation];
  1608. };
  1609. [window orderFront:sender];
  1610. }
  1611. - (IBAction)fontCustomColorButtonAction:(NSButton *)sender {
  1612. [[NSColorPanel sharedColorPanel] setTarget:self];
  1613. [NSColorPanel sharedColorPanel].showsAlpha = YES;
  1614. [[NSColorPanel sharedColorPanel] setAction:@selector(colorPanelAction:)];
  1615. [[NSColorPanel sharedColorPanel] orderFront:nil];
  1616. }
  1617. - (IBAction)fontColorButtonAction:(NSButton *)sender {
  1618. self.annotationModel.fontColor = _fontColorButton.color;
  1619. [self updateAnnotation];
  1620. }
  1621. - (NSColor *)colorWithCGColor:(CGColorRef)CGColor
  1622. {
  1623. if (CGColor == NULL) return nil;
  1624. return [NSColor colorWithCIColor:[CIColor colorWithCGColor:CGColor]];
  1625. }
  1626. - (void)colorPanelAction:(id)sender {
  1627. if([NSColorPanel sharedColorPanel].visible) {
  1628. NSColor *currentColor = [NSColorPanel sharedColorPanel].color;
  1629. _fontColorButton.color = currentColor;
  1630. [self.fontColorButton setNeedsDisplay:YES];
  1631. CGFloat r, g, b, a = 0.0;
  1632. [[currentColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1633. if (fabs(a - 0) < 0.001) {
  1634. //设置透明色必须要设一个颜色值
  1635. self.annotationModel.opacity = 0;
  1636. self.annotationModel.fontColor = [NSColor blackColor];
  1637. } else {
  1638. self.annotationModel.opacity = a;
  1639. self.annotationModel.fontColor = currentColor;
  1640. }
  1641. [self updateOpacityView];
  1642. if (CAnnotationTypeFreeText == _annotationType ||
  1643. CAnnotationTypeSignDate == _annotationType ||
  1644. CAnnotationTypeSignText == _annotationType) {
  1645. [[self.annotationModel.fontColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1646. self.fontColorButton.color = [NSColor colorWithRed:r green:g blue:b alpha:self.annotationModel.opacity];
  1647. [_fontButton setNeedsDisplay:YES];
  1648. }
  1649. CPDFAnnotation *annotation = self.annotationModel.annotation;
  1650. if (annotation) {
  1651. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1652. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  1653. if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
  1654. [self.pdfView setEditAnnotationFreeTextColor:currentColor freeText:textNote];
  1655. } else {
  1656. [self updateAnnotation];
  1657. }
  1658. } else {
  1659. [self updateAnnotation];
  1660. }
  1661. self.generalImageView.image = [self.annotationModel annotationImage];
  1662. } else {
  1663. [self updateAnnotation];
  1664. }
  1665. }
  1666. }
  1667. - (IBAction)buttonClicked_TypeAwitch:(NSButton *)sender {
  1668. NSInteger tag = sender.tag;
  1669. CAnnotationType annotationType = CAnnotationTypeSignLine;
  1670. if (tag == 201) {
  1671. annotationType = CAnnotationTypeSignTure;
  1672. } else if (tag == 202) {
  1673. annotationType = CAnnotationTypeSignFalse;
  1674. } else {
  1675. annotationType = tag;
  1676. }
  1677. self.selfSignType = annotationType;
  1678. [self typeSelected:annotationType];
  1679. if (self.callBack) {
  1680. self.callBack (annotationType);
  1681. }
  1682. self.annotationModel.stampAnnotationType = annotationType;
  1683. if (self.selfSignType == CAnnotationTypeSignDot) {
  1684. self.borderWidthView.hidden = YES;
  1685. self.borderWidthViewTopConstraint.constant = -(self.borderWidthView.bounds.size.height);
  1686. } else {
  1687. self.borderWidthView.hidden = NO;
  1688. self.borderWidthViewTopConstraint.constant = 16.0f;
  1689. }
  1690. [self updateAnnotation];
  1691. }
  1692. - (IBAction)buttonClicked_SwitchIncludeTime:(NSButton *)sender
  1693. {
  1694. self.annotationModel.includeTime = sender.state == NSControlStateValueOn?YES:NO;
  1695. [self updateDateView];
  1696. [self updateAnnotation];
  1697. }
  1698. - (IBAction)dateCheckButtonAction:(NSPopUpButton *)sender
  1699. {
  1700. self.annotationModel.dateFormatIndex = sender.indexOfSelectedItem;
  1701. [self updateAnnotation];
  1702. }
  1703. #pragma mark SqureAnnotation Style
  1704. - (IBAction)updateFigurateModelAction:(NSButton *)sender {
  1705. if ((sender == self.squareVC.button && _annotationType == CAnnotationTypeSquare) ||
  1706. (sender == self.circleVC.button && _annotationType == CAnnotationTypeCircle) ||
  1707. (sender == self.arrowVC.button && _annotationType == CAnnotationTypeArrow) ||
  1708. (sender == self.lineVC.button && _annotationType == CAnnotationTypeLine)) {
  1709. return;
  1710. }
  1711. self.squareVC.state = KMDesignTokenStateNorm;
  1712. self.circleVC.state = KMDesignTokenStateNorm;
  1713. self.arrowVC.state = KMDesignTokenStateNorm;
  1714. self.lineVC.state = KMDesignTokenStateNorm;
  1715. if (sender == self.squareVC.button) {
  1716. self.pdfView.annotationType = CAnnotationTypeSquare;
  1717. self.squareVC.state = KMDesignTokenStateSel;
  1718. } else if (sender == self.circleVC.button) {
  1719. self.pdfView.annotationType = CAnnotationTypeCircle;
  1720. self.circleVC.state = KMDesignTokenStateSel;
  1721. } else if (sender == self.arrowVC.button) {
  1722. self.pdfView.annotationType = CAnnotationTypeArrow;
  1723. self.arrowVC.state = KMDesignTokenStateSel;
  1724. } else if (sender == self.lineVC.button) {
  1725. self.pdfView.annotationType = CAnnotationTypeLine;
  1726. self.lineVC.state = KMDesignTokenStateSel;
  1727. }
  1728. self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
  1729. [self loadingUIAndLocalization];
  1730. }
  1731. #pragma mark CPDFTextAnnotation Action
  1732. - (IBAction)textAnnotationStyleAction:(NSButton *)sender {
  1733. [self.annotationModel setAnchoredIconType:sender.tag];
  1734. [self loadingUIAndLocalization];
  1735. [self updateAnnotation];
  1736. }
  1737. #pragma mark - NSNotification
  1738. - (void)textDidChange:(NSNotification *)notification {
  1739. NSObject *obj = notification.object;
  1740. if ([obj isEqualTo:self.noteTextView]) {
  1741. [self.annotationModel setContents:self.noteTextView.string?:@""];
  1742. if (CAnnotationTypeHighlight == self.annotationModel.annotationType || CAnnotationTypeStrikeOut == self.annotationModel.annotationType || CAnnotationTypeUnderline == self.annotationModel.annotationType) {
  1743. } else {
  1744. [self updateAnnotation];
  1745. }
  1746. }
  1747. }
  1748. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  1749. if (![object isEqual:self.annotationModel.annotation]) {
  1750. return;
  1751. }
  1752. id newValue = [change objectForKey:NSKeyValueChangeNewKey] ? : [NSNull null];
  1753. id oldValue = [change objectForKey:NSKeyValueChangeOldKey] ? : [NSNull null];
  1754. if ([newValue isEqual:oldValue]) {
  1755. return;
  1756. }
  1757. if ([keyPath isEqualToString:@"contents"] || [keyPath isEqualToString:@"markupText"]) {
  1758. if ([newValue isKindOfClass:[NSNull class]]) {
  1759. return;
  1760. }
  1761. self.noteTextView.string = newValue ? : @"";
  1762. }
  1763. }
  1764. - (void)alignmentTypeNotification:(NSNotification *)notification {
  1765. NSString *count = notification.object;
  1766. NSTextAlignment alignment = NSTextAlignmentLeft;
  1767. if ([count isEqualToString:@"0"]) {
  1768. alignment = NSTextAlignmentLeft;
  1769. } else if ([count isEqualToString:@"1"]) {
  1770. alignment = NSTextAlignmentRight;
  1771. } else if ([count isEqualToString:@"2"]) {
  1772. alignment = NSTextAlignmentCenter;
  1773. }
  1774. [self alignmentTypeSelected:alignment];
  1775. }
  1776. - (void)annotationChangeNotification:(NSNotification *)notification {
  1777. if (notification.object != nil) {
  1778. CPDFAnnotation *annotation = notification.object[@"object"];
  1779. if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
  1780. if (![notification.object[@"keyPath"] isEqualToString: CPDFAnnotationBoundsKey]) {
  1781. [self configureUIView];
  1782. }
  1783. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1784. if ([notification.object[@"keyPath"] isEqualToString: CPDFAnnotationContentKey]) {
  1785. // [self configureUIView];
  1786. // [self adjustFreetText];
  1787. }
  1788. }
  1789. }
  1790. }
  1791. #pragma mark - NSPopoverDelegate
  1792. - (void)popoverWillShow:(NSNotification *)notification {
  1793. NSPopover *popover = notification.object;
  1794. if ([popover isEqual:_fillColorPopover]) {
  1795. self.fillButton.wantsLayer = YES;
  1796. self.fillButton.layer.cornerRadius = 4.0;
  1797. self.fillButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
  1798. } else if ([popover isEqual:_borderColorPopover]) {
  1799. self.showborderOpacityButton.wantsLayer = YES;
  1800. self.showborderOpacityButton.layer.cornerRadius = 4.0;
  1801. self.showborderOpacityButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
  1802. }
  1803. }
  1804. - (void)popoverWillClose:(NSNotification *)notification {
  1805. NSPopover *popover = notification.object;
  1806. if ([popover isEqual:_fillColorPopover]) {
  1807. self.fillButton.wantsLayer = YES;
  1808. self.fillButton.layer.cornerRadius = 0.0;
  1809. self.fillButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  1810. } else if ([popover isEqual:_borderColorPopover]) {
  1811. self.showborderOpacityButton.wantsLayer = YES;
  1812. self.showborderOpacityButton.layer.cornerRadius = 0.0;
  1813. self.showborderOpacityButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  1814. }
  1815. }
  1816. #pragma mark - KMSelectPopButtonDelegate
  1817. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  1818. if ([self.fontNameVC isEqual:obj]) {
  1819. [self updateFontNameAndStyle:obj.stringValue
  1820. style:self.fontStyleVC.stringValue
  1821. needChangeListView:YES
  1822. needSave:YES];
  1823. } else if ([self.fontStyleVC isEqual:obj]) {
  1824. NSInteger index = self.fontStyleVC.indexOfSelectedItem;
  1825. if (index < 0) {
  1826. return;
  1827. }
  1828. NSString *fontName = self.fontNameVC.stringValue;
  1829. NSString *fontStyle = self.fontStyleVC.stringValue;
  1830. [self updateFontNameAndStyle:fontName
  1831. style:fontStyle
  1832. needChangeListView:YES
  1833. needSave:YES];
  1834. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  1835. } else if (self.fontSizeVC == obj) {
  1836. NSInteger index = self.fontSizeVC.indexOfSelectedItem;
  1837. if (index < 0) {
  1838. return;
  1839. }
  1840. NSString *size = [self.fontSizeVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""];
  1841. [self updateFontSize:size.intValue needChangeListView:YES needSave:YES];
  1842. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  1843. [self adjustFreetText];
  1844. } else if (self.borderWidthVC == obj) {
  1845. CGFloat lineWidth = [[self.borderWidthVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""] floatValue];
  1846. if (self.fillColorPickerVC.annotationType == KMPropertiesColor_SelfSignColors) {
  1847. if (lineWidth > 8) {
  1848. lineWidth = 8;
  1849. }
  1850. } else {
  1851. if (_annotationType != CAnnotationTypeEraser) {
  1852. if (lineWidth > 20) {
  1853. lineWidth = 20;
  1854. }
  1855. }
  1856. }
  1857. self.annotationModel.lineWidth = lineWidth;
  1858. [self updateBorderWidthView];
  1859. [self updateAnnotation];
  1860. [self adjustFreetText];
  1861. } else if (obj == _textPresuppositionVC) {
  1862. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  1863. NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
  1864. [self updateTextPresupposition:type needChangeListView:true];
  1865. [self updateAnnotation];
  1866. [self adjustFreetText];
  1867. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  1868. }
  1869. }
  1870. -(void)adjustFreetText {
  1871. if(self.annotationModel.annotation &&
  1872. (CAnnotationTypeFreeText == self.annotationModel.annotationType ||
  1873. CAnnotationTypeSignText == self.annotationModel.annotationType ||
  1874. CAnnotationTypeSignDate == self.annotationModel.annotationType )) {
  1875. for(CPDFAnnotation *an in self.annotationModel.annotations) {
  1876. if([an isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1877. CPDFFreeTextAnnotation *freeTextAn = (CPDFFreeTextAnnotation *)an;
  1878. NSFont* font = freeTextAn.font;
  1879. NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
  1880. [dictionary setObject:font forKey:NSFontAttributeName];
  1881. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  1882. [style setAlignment:freeTextAn.alignment];
  1883. [dictionary setObject:style forKey:NSParagraphStyleAttributeName];
  1884. CGSize textViewSize = [freeTextAn.contents?:@"" boundingRectWithSize:CGSizeMake(freeTextAn.bounds.size.width, MAXFLOAT)
  1885. options:NSStringDrawingUsesLineFragmentOrigin
  1886. attributes:dictionary].size;
  1887. CGRect rect = freeTextAn.bounds;
  1888. if(textViewSize.height != freeTextAn.bounds.size.height) {
  1889. rect.origin.y -= (textViewSize.height - rect.size.height);
  1890. rect.size.height = textViewSize.height;
  1891. }
  1892. if(textViewSize.width < freeTextAn.bounds.size.width) {
  1893. rect.size.width = textViewSize.width;
  1894. }
  1895. freeTextAn.bounds = rect;
  1896. }
  1897. }
  1898. }
  1899. }
  1900. - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj {
  1901. }
  1902. @end
  1903. @interface KMGeneralAnnotationViewController (Font)
  1904. - (void)updateAlignment:(NSTextAlignment)alignment;
  1905. - (void)updateTextPresupposition:(NSString *)type needChangeListView:(BOOL) needChangeListView;
  1906. - (void)updateTextPresupposition:(NSString *)fontName size:(CGFloat)size needChangeListView:(BOOL)needChangeListView;
  1907. - (void)updateFontNameAndStyle:(NSString *)name style:(NSString *)style needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave;
  1908. - (void)updateFontSize:(CGFloat)size needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave;
  1909. - (void)updateTextTextPresuppositionState:(NSString *)name size:(CGFloat)size;
  1910. - (void)resetTextPresuppositionData;
  1911. - (void)reDefineTextPresuppositionData:(BOOL)redefine;
  1912. @end
  1913. @implementation KMGeneralAnnotationViewController (Font)
  1914. - (void)updateAlignment:(NSTextAlignment)alignment {
  1915. }
  1916. - (void)updateTextTextPresuppositionState:(NSString *)name size:(CGFloat)size {
  1917. NSString *fontName = [KMEditPDFTextManager.manager transformAreaTextFontNameWithFontName:name fontNames:self.fontNameVC.items];
  1918. NSArray *dataArray = [KMEditPDFTextManager.manager fetchAllUserDefaultData];
  1919. NSInteger index = 0;
  1920. for (int i = 0; i < dataArray.count; i++) {
  1921. KMEditPDFTextFontModel *model = dataArray[i];
  1922. if ([model.fontName isEqualToString:fontName] && model.fontSize == size) {
  1923. index = i;
  1924. break;
  1925. }
  1926. }
  1927. //刷新样式
  1928. [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  1929. [self.textPresuppositionVC selectItemAt:index];
  1930. }
  1931. - (void)updateTextPresupposition:(NSString *)type needChangeListView:(BOOL) needChangeListView {
  1932. NSInteger index = [KMEditPDFTextFontTypeWrapper.allValues indexOfObject:type];
  1933. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchAllUserDefaultData][index];
  1934. NSString *fontName = model.fontName;
  1935. CGFloat size = model.fontSize;
  1936. [self updateTextPresupposition:fontName size:size needChangeListView:needChangeListView];
  1937. }
  1938. - (void)updateTextPresupposition:(NSString *)fontName size:(CGFloat)size needChangeListView:(BOOL)needChangeListView {
  1939. NSArray *fontNameArray = [fontName componentsSeparatedByString:@"-"];
  1940. NSString *name = @"";
  1941. NSString *style = @"";
  1942. if (fontNameArray.count > 0) {
  1943. name = fontNameArray.firstObject;
  1944. } else {
  1945. name = @"Helvetica";
  1946. }
  1947. if (fontNameArray.count == 2) {
  1948. style = fontNameArray.lastObject;
  1949. } else {
  1950. style = @"Regular";
  1951. }
  1952. [self updateFontNameAndStyle:name style:style needChangeListView:needChangeListView needSave:false];
  1953. [self updateFontSize:size needChangeListView:needChangeListView needSave:false];
  1954. }
  1955. - (void)resetTextPresuppositionData {
  1956. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  1957. NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
  1958. [KMEditPDFTextManager.manager resetTextPresuppositionWithType:type];
  1959. [self updateTextPresupposition:type needChangeListView:YES];
  1960. //刷新样式
  1961. [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  1962. [self.textPresuppositionVC selectItemAt:index];
  1963. }
  1964. - (void)reDefineTextPresuppositionData:(BOOL)redefine {
  1965. NSString *fontStyle = self.fontStyleVC.stringValue;
  1966. NSString *fontName = self.fontNameVC.stringValue;
  1967. CGFloat fontSize = [[self.fontSizeVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""] intValue];
  1968. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  1969. NSString *type = KMEditPDFTextFontTypeWrapper.allValues[index];
  1970. fontName = [NSString stringWithFormat:@"%@-%@",fontName, fontStyle];
  1971. [KMEditPDFTextManager.manager reDefineTextPresuppositionWithFontName:fontName fontSize:fontSize type:type];
  1972. [self updateTextPresupposition:type needChangeListView:YES];
  1973. //刷新样式
  1974. [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  1975. [self.textPresuppositionVC selectItemAt:index];
  1976. }
  1977. - (void)updateFontNameAndStyle:(NSString *)name style:(NSString *)style needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave {
  1978. NSString *fontName = self.fontName;
  1979. NSString *fontStyle = self.fontStyle;
  1980. // if (fontName != name || fontStyle != style) {
  1981. NSArray *styleArray = [KMEditPDFTextManager.manager fetchFontStyleWithFontNameWithFontName:name];
  1982. NSString *styleString = [KMEditPDFTextManager.manager checkFontStyleWithStyle:style];
  1983. if (![styleArray containsObject:style]) {
  1984. [self.fontStyleVC addItemsWithObjectValues:styleArray];
  1985. [self.fontStyleVC selectItemAt:0];
  1986. styleString = [KMEditPDFTextManager.manager checkFontStyleWithStyle:self.fontStyleVC.stringValue];
  1987. } else {
  1988. [self.fontStyleVC selectItemAt: [styleArray indexOfObject:styleString]];
  1989. }
  1990. fontName = [NSString stringWithFormat:@"%@-%@",name, [styleString stringByReplacingOccurrencesOfString:@" " withString:@""]];
  1991. if (styleString.length == 0) {
  1992. fontName = name;
  1993. }
  1994. self.fontName = name;
  1995. self.fontStyle = styleString;
  1996. [self.fontNameVC selectItemAt:[self.fontNameVC.items indexOfObject:name] ? :0];
  1997. if (self.annotationModel.annotations.count > 0) {
  1998. if (needChangeListView) {
  1999. self.annotationModel.fontName = fontName;
  2000. [self updateAnnotation];
  2001. }
  2002. } else {
  2003. self.annotationModel.fontName = fontName;
  2004. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
  2005. [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:fontName fontSize:model.fontSize type:@"Commonly"];
  2006. }
  2007. if (needSave) {
  2008. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  2009. NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
  2010. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:type];
  2011. [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:fontName fontSize:model.fontSize type:type];
  2012. }
  2013. //刷新样式
  2014. [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  2015. [self.textPresuppositionVC selectItemAt:self.textPresuppositionVC.indexOfSelectedItem];
  2016. // }
  2017. }
  2018. - (void)updateFontSize:(CGFloat)size needChangeListView:(BOOL)needChangeListView needSave:(BOOL)needSave {
  2019. if (self.fontSize != size) {
  2020. self.fontSize = size;
  2021. [self.fontSizeVC selectItemAt: [self.fontSizeVC.items indexOfObject: [NSString stringWithFormat:@"%.0fpt",size]]];
  2022. if (self.annotationModel.annotations.count > 0) {
  2023. if (needChangeListView) {
  2024. self.annotationModel.fontSize = size;
  2025. [self updateAnnotation];
  2026. }
  2027. } else {
  2028. self.annotationModel.fontSize = size;
  2029. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:@"Commonly"];
  2030. [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:model.fontName fontSize:size type:@"Commonly"];
  2031. }
  2032. if (needSave) {
  2033. NSInteger index = self.textPresuppositionVC.indexOfSelectedItem;
  2034. NSString *type = [KMEditPDFTextFontTypeWrapper allValues][index];
  2035. KMEditPDFTextFontModel *model = [KMEditPDFTextManager.manager fetchUserDefaultDataWithTypeStringWithType:type];
  2036. [KMEditPDFTextManager.manager changeTextPresuppositionWithFontName:model.fontName fontSize:size type:type];
  2037. }
  2038. //刷新样式
  2039. [self.textPresuppositionVC addItemsWithObjectValues:[KMEditPDFTextManager.manager updateTextPresuppositionFontNameArray]];
  2040. [self.textPresuppositionVC selectItemAt:self.textPresuppositionVC.indexOfSelectedItem];
  2041. }
  2042. }
  2043. @end