KMGeneralAnnotationViewController.m 101 KB

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