KMGeneralAnnotationViewController.m 113 KB

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