KMGeneralAnnotationViewController.m 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487
  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. if (self.annotationModel.annotations.count > 1) {
  757. NSMutableArray *colors = [NSMutableArray array];
  758. for (CPDFAnnotation *annotation in self.annotationModel.annotations) {
  759. NSColor *color = nil;
  760. if ([annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
  761. [annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  762. if ([annotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  763. color = ((CPDFCircleAnnotation *)annotation).interiorColor;
  764. } else {
  765. color = ((CPDFSquareAnnotation *)annotation).interiorColor;
  766. }
  767. self.fillColorPickerVC.isFillColor = YES;
  768. } else {
  769. color = annotation.color;
  770. }
  771. [colors addObject:color];
  772. }
  773. self.fillColorPickerVC.selectColors = colors;
  774. } else {
  775. NSColor *color = nil;
  776. CPDFAnnotation *firstAnnotation = self.annotationModel.annotations.firstObject;
  777. if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]] ||
  778. [firstAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  779. if ([firstAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  780. color = ((CPDFCircleAnnotation *)firstAnnotation).interiorColor;
  781. } else {
  782. color = ((CPDFSquareAnnotation *)firstAnnotation).interiorColor;
  783. }
  784. self.fillColorPickerVC.isFillColor = YES;
  785. } else {
  786. color = firstAnnotation.color;
  787. }
  788. self.fillColorPickerVC.color = color;
  789. }
  790. } else {
  791. NSColor *color = nil;
  792. if (CAnnotationTypeCircle == _annotationType ||
  793. CAnnotationTypeSquare == _annotationType) {
  794. color = self.annotationModel.interiorColor;
  795. self.fillColorPickerVC.isFillColor = YES;
  796. } else {
  797. color = self.annotationModel.color;
  798. }
  799. if (!color) {
  800. color = [NSColor clearColor];
  801. }
  802. self.fillColorPickerVC.color = color;
  803. }
  804. self.generalImageView.image = [self.annotationModel annotationImage];
  805. }
  806. - (void)updateBackgroundColorPickerVC
  807. {
  808. NSColor *color = nil;
  809. if (CAnnotationTypeSignDate == _annotationType) {
  810. color = self.annotationModel.color;
  811. if (color) {
  812. CGFloat red,green,blue,alpha;
  813. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  814. color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.opacity];
  815. }
  816. self.backgroundColorPickerVC.color = color;
  817. }
  818. self.generalImageView.image = [self.annotationModel annotationImage];
  819. }
  820. - (void)updateFontView {
  821. if (_annotationModel.annotations.count > 0) {
  822. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  823. if ([firstAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  824. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)firstAnnotation;
  825. if (_annotationModel.annotations.count > 1) {
  826. NSFont *currentFont = textNote.font;
  827. NSArray *fonts = [CPDFAnnotationModel supportFonts];
  828. NSDictionary * dic = nil;
  829. NSMutableArray *mutableArr = [NSMutableArray array];
  830. for (NSUInteger i=0; i<fonts.count; i++) {
  831. NSDictionary *fontDic = fonts[i];
  832. NSString * fontName = fontDic.allKeys.firstObject?:@"Helvetica";
  833. NSFont *font = [NSFont fontWithName:fontName size:12.0];
  834. NSDictionary *attrited = @{NSFontAttributeName:font};
  835. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  836. [mutableArr addObject:string];
  837. NSString * family = [currentFont.fontDescriptor objectForKey:NSFontFamilyAttribute];
  838. if ([family isEqualToString:fontName]) {
  839. dic = fontDic;
  840. }
  841. }
  842. NSString * style = [currentFont.fontDescriptor objectForKey:NSFontFaceAttribute];
  843. if (dic) {
  844. NSInteger selectedIndex = [fonts indexOfObject:dic];
  845. [self.fontNameVC selectItemAt:selectedIndex];
  846. NSString * fontName = dic.allKeys.firstObject;
  847. NSInteger selectIndex = [self setFontStyleWithFontName:fontName currentStyle:style];
  848. if (selectIndex != -1) {
  849. [self.fontStyleVC selectItemAt:selectIndex];
  850. } else {
  851. self.fontStyleVC.stringValue = @"";
  852. }
  853. NSNumber *sizeString = [textNote.font.fontDescriptor objectForKey:NSFontSizeAttribute];
  854. self.fontSizeVC.stringValue = [NSString stringWithFormat:@"%@pt",sizeString.stringValue];
  855. NSDictionary *model = [self freeTextPropertWithTitle:self.defaultPopUpButton.indexOfSelectedItem];
  856. if (model) {
  857. NSArray *modelFontNames = [model[@"fontName"] componentsSeparatedByString:@"-"];
  858. if ([self.fontStyleVC.stringValue isEqualToString:@"Regular"] && (modelFontNames.count == 1)) {
  859. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  860. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  861. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  862. [self.defaultPopUpButton removeAllItems];
  863. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  864. NSString *defaultString = defaultArr[defaultCount];
  865. for(NSString* title in defaultArr){
  866. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  867. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  868. } else {
  869. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  870. }
  871. }
  872. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  873. }
  874. } else {
  875. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  876. ![self.fontStyleVC.stringValue isEqualToString:modelFontNames.lastObject] ||
  877. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  878. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  879. [self.defaultPopUpButton removeAllItems];
  880. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  881. NSString *defaultString = defaultArr[defaultCount];
  882. for(NSString* title in defaultArr){
  883. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  884. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  885. } else {
  886. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  887. }
  888. }
  889. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  890. } else {
  891. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  892. [self.defaultPopUpButton removeAllItems];
  893. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  894. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  895. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  896. }
  897. }
  898. } else {
  899. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  900. [self.defaultPopUpButton removeAllItems];
  901. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  902. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  903. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  904. }
  905. } else {
  906. self.fontNameVC.stringValue = @"";
  907. self.fontStyleVC.stringValue = @"";
  908. }
  909. // NSString *familyString = [textNote.font.fontDescriptor objectForKey:NSFontFamilyAttribute];
  910. // NSString *faceString = [textNote.font.fontDescriptor objectForKey:NSFontFaceAttribute];
  911. // NSNumber *sizeString = [textNote.font.fontDescriptor objectForKey:NSFontSizeAttribute];
  912. // _fontNameVC.stringValue = familyString;
  913. // _fontStyleVC.stringValue = faceString;
  914. // _fontSizeVC.stringValue = sizeString.stringValue;
  915. if (textNote.alignment == NSTextAlignmentLeft) {
  916. self.leftAlignVC.state = KMDesignTokenStateSel;
  917. } else if (textNote.alignment == NSTextAlignmentCenter) {
  918. self.centerAlignVC.state = KMDesignTokenStateSel;
  919. } else if (textNote.alignment == NSTextAlignmentRight) {
  920. self.rightAlignVC.state = KMDesignTokenStateSel;
  921. }
  922. self.fontColorButton.color = textNote.fontColor ? : [NSColor blackColor];
  923. [self.fontColorButton setNeedsDisplay:YES];
  924. } else {
  925. NSFont *currentFont = textNote.font;
  926. NSArray *fonts = [CPDFAnnotationModel supportFonts];
  927. NSDictionary * dic = nil;
  928. NSMutableArray *mutableArr = [NSMutableArray array];
  929. for (NSUInteger i=0; i<fonts.count; i++) {
  930. NSDictionary *fontDic = fonts[i];
  931. NSString * fontName = fontDic.allKeys.firstObject?:@"Helvetica";
  932. NSFont *font = [NSFont fontWithName:fontName size:12.0];
  933. NSDictionary *attrited = @{NSFontAttributeName:font};
  934. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  935. [mutableArr addObject:string];
  936. NSString * family = [currentFont.fontDescriptor objectForKey:NSFontFamilyAttribute];
  937. if ([family isEqualToString:fontName]) {
  938. dic = fontDic;
  939. }
  940. }
  941. NSString * style = [currentFont.fontDescriptor objectForKey:NSFontFaceAttribute];
  942. if (dic) {
  943. NSInteger selectedIndex = [fonts indexOfObject:dic];
  944. [self.fontNameVC selectItemAt:selectedIndex];
  945. NSString * fontName = dic.allKeys.firstObject;
  946. NSInteger selectIndex = [self setFontStyleWithFontName:fontName currentStyle:style];
  947. if (selectIndex != -1) {
  948. [self.fontStyleVC selectItemAt:selectIndex];
  949. } else {
  950. self.fontStyleVC.stringValue = @"";
  951. }
  952. } else {
  953. self.fontNameVC.stringValue = @"";
  954. self.fontStyleVC.stringValue = @"";
  955. }
  956. NSNumber *sizeString = [textNote.font.fontDescriptor objectForKey:NSFontSizeAttribute];
  957. self.fontSizeVC.stringValue = [NSString stringWithFormat:@"%@pt",sizeString.stringValue];
  958. NSDictionary *model = [self freeTextPropertWithTitle:self.defaultPopUpButton.indexOfSelectedItem];
  959. if (model) {
  960. NSArray *modelFontNames = [model[@"fontName"] componentsSeparatedByString:@"-"];
  961. if ([self.fontStyleVC.stringValue isEqualToString:@"Regular"] && (modelFontNames.count == 1)) {
  962. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  963. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  964. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  965. [self.defaultPopUpButton removeAllItems];
  966. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  967. NSString *defaultString = defaultArr[defaultCount];
  968. for(NSString* title in defaultArr){
  969. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  970. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  971. } else {
  972. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  973. }
  974. }
  975. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  976. }
  977. } else {
  978. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  979. ![self.fontStyleVC.stringValue isEqualToString:modelFontNames.lastObject] ||
  980. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  981. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  982. [self.defaultPopUpButton removeAllItems];
  983. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  984. NSString *defaultString = defaultArr[defaultCount];
  985. for(NSString* title in defaultArr){
  986. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  987. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  988. } else {
  989. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  990. }
  991. }
  992. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  993. } else {
  994. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  995. [self.defaultPopUpButton removeAllItems];
  996. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  997. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  998. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  999. }
  1000. }
  1001. } else {
  1002. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  1003. [self.defaultPopUpButton removeAllItems];
  1004. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1005. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  1006. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  1007. }
  1008. // NSString *familyString = [textNote.font.fontDescriptor objectForKey:NSFontFamilyAttribute];
  1009. // NSString *faceString = [textNote.font.fontDescriptor objectForKey:NSFontFaceAttribute];
  1010. // NSNumber *sizeString = [textNote.font.fontDescriptor objectForKey:NSFontSizeAttribute];
  1011. // _fontNameVC.stringValue = familyString;
  1012. // _fontStyleVC.stringValue = faceString;
  1013. // _fontSizeVC.stringValue = sizeString.stringValue;
  1014. if (textNote.alignment == NSTextAlignmentLeft) {
  1015. self.leftAlignVC.state = KMDesignTokenStateSel;
  1016. } else if (textNote.alignment == NSTextAlignmentCenter) {
  1017. self.centerAlignVC.state = KMDesignTokenStateSel;
  1018. } else if (textNote.alignment == NSTextAlignmentRight) {
  1019. self.rightAlignVC.state = KMDesignTokenStateSel;
  1020. }
  1021. self.fontColorButton.color = textNote.fontColor ? : [NSColor blackColor];
  1022. [self.fontColorButton setNeedsDisplay:YES];
  1023. }
  1024. }
  1025. } else {
  1026. NSArray *fontnames = [_annotationModel.fontName componentsSeparatedByString:@"-"];
  1027. NSFont *currentFont = [NSFont systemFontOfSize:12.0];
  1028. if ([fontnames.lastObject isEqualToString:@"Regular"] || [fontnames.lastObject isEqualToString:@"Roman"]) {
  1029. currentFont = [NSFont fontWithName:fontnames.firstObject size:_annotationModel.fontSize];
  1030. } else {
  1031. currentFont = [NSFont fontWithName:_annotationModel.fontName size:_annotationModel.fontSize];
  1032. }
  1033. NSArray *fonts = [CPDFAnnotationModel supportFonts];
  1034. NSDictionary * dic = nil;
  1035. NSMutableArray *mutableArr = [NSMutableArray array];
  1036. for (NSUInteger i=0; i<fonts.count; i++) {
  1037. NSDictionary *fontDic = fonts[i];
  1038. NSString * fontName = fontDic.allKeys.firstObject?:@"Helvetica";
  1039. NSFont *font = [NSFont fontWithName:fontName size:12.0];
  1040. NSDictionary *attrited = @{NSFontAttributeName:font};
  1041. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  1042. [mutableArr addObject:string];
  1043. NSString * family = [currentFont.fontDescriptor objectForKey:NSFontFamilyAttribute];
  1044. if ([family isEqualToString:fontName]) {
  1045. dic = fontDic;
  1046. }
  1047. }
  1048. NSString * style = [currentFont.fontDescriptor objectForKey:NSFontFaceAttribute];
  1049. if (dic) {
  1050. NSInteger selectedIndex = [fonts indexOfObject:dic];
  1051. [self.fontNameVC selectItemAt:selectedIndex];
  1052. NSString * fontName = dic.allKeys.firstObject;
  1053. NSInteger selectIndex = [self setFontStyleWithFontName:fontName currentStyle:style];
  1054. if (selectIndex != -1) {
  1055. [self.fontStyleVC selectItemAt:selectIndex];
  1056. } else {
  1057. self.fontStyleVC.stringValue = @"";
  1058. }
  1059. } else {
  1060. self.fontNameVC.stringValue = @"";
  1061. self.fontStyleVC.stringValue = @"";
  1062. }
  1063. NSNumber *sizeString = [currentFont.fontDescriptor objectForKey:NSFontSizeAttribute];
  1064. self.fontSizeVC.stringValue = [NSString stringWithFormat:@"%@pt",sizeString.stringValue];
  1065. NSDictionary *model = [self freeTextPropertWithTitle:self.defaultPopUpButton.indexOfSelectedItem];
  1066. if (model) {
  1067. NSArray *modelFontNames = [model[@"fontName"] componentsSeparatedByString:@"-"];
  1068. if ([self.fontStyleVC.stringValue isEqualToString:@"Regular"] && (modelFontNames.count == 1)) {
  1069. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  1070. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  1071. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  1072. [self.defaultPopUpButton removeAllItems];
  1073. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1074. NSString *defaultString = defaultArr[defaultCount];
  1075. for(NSString* title in defaultArr){
  1076. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  1077. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  1078. } else {
  1079. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  1080. }
  1081. }
  1082. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  1083. }
  1084. } else {
  1085. if (![self.fontNameVC.stringValue isEqualToString:modelFontNames.firstObject] ||
  1086. ![self.fontStyleVC.stringValue isEqualToString:modelFontNames.lastObject] ||
  1087. _annotationModel.fontSize != [model[@"fontSize"] floatValue]) {
  1088. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  1089. [self.defaultPopUpButton removeAllItems];
  1090. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1091. NSString *defaultString = defaultArr[defaultCount];
  1092. for(NSString* title in defaultArr){
  1093. if ([title isEqualToString:defaultString] && ![title isEqualToString:@"Customize"]) {
  1094. [self.defaultPopUpButton addItemWithTitle:[NSString stringWithFormat:@"*%@", NSLocalizedString(title, nil)]];
  1095. } else {
  1096. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  1097. }
  1098. }
  1099. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  1100. } else {
  1101. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  1102. [self.defaultPopUpButton removeAllItems];
  1103. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1104. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  1105. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  1106. }
  1107. }
  1108. } else {
  1109. NSInteger defaultCount = self.defaultPopUpButton.indexOfSelectedItem;
  1110. [self.defaultPopUpButton removeAllItems];
  1111. NSArray *defaultArr = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1112. [self.defaultPopUpButton addItemsWithTitles:defaultArr];
  1113. [self.defaultPopUpButton selectItemAtIndex:defaultCount];
  1114. }
  1115. // NSString *familyString = [currentFont.fontDescriptor objectForKey:NSFontFamilyAttribute];
  1116. // NSString *faceString = [currentFont.fontDescriptor objectForKey:NSFontFaceAttribute];
  1117. // NSNumber *sizeString = [currentFont.fontDescriptor objectForKey:NSFontSizeAttribute];
  1118. // _fontNameVC.stringValue = familyString;
  1119. // _fontStyleVC.stringValue = faceString;
  1120. // _fontSizeVC.stringValue = sizeString.stringValue;
  1121. if (_annotationModel.alignment == NSTextAlignmentLeft) {
  1122. self.leftAlignVC.state = KMDesignTokenStateSel;
  1123. } else if (_annotationModel.alignment == NSTextAlignmentCenter) {
  1124. self.centerAlignVC.state = KMDesignTokenStateSel;
  1125. } else if (_annotationModel.alignment == NSTextAlignmentRight) {
  1126. self.rightAlignVC.state = KMDesignTokenStateSel;
  1127. }
  1128. self.fontColorButton.color = _annotationModel.fontColor ? : [NSColor blackColor];
  1129. [self.fontColorButton setNeedsDisplay:YES];
  1130. }
  1131. self.generalImageView.image = [self.annotationModel annotationImage];
  1132. }
  1133. - (void)updateBorderColorPickerVC
  1134. {
  1135. NSColor *color = self.annotationModel.color;
  1136. if (self.annotationModel.annotations.count > 1) {
  1137. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1138. color = firstAnnotation.color;
  1139. } else {
  1140. color = self.annotationModel.color;
  1141. }
  1142. self.borderColorPickerVC.color = color;
  1143. self.generalImageView.image = [self.annotationModel annotationImage];
  1144. }
  1145. - (void)updateDateView
  1146. {
  1147. [_datePopupButton removeAllItems];
  1148. BOOL includeTime = self.annotationModel.includeTime;
  1149. [_datePopupButton addItemsWithTitles:[KMSelfSignAnnotationFreeText fetchAllDateString:includeTime]];
  1150. NSInteger dateFormatIndex = self.annotationModel.dateFormatIndex;
  1151. if (dateFormatIndex >= 0 && dateFormatIndex < _datePopupButton.numberOfItems) {
  1152. [_datePopupButton selectItemAtIndex:dateFormatIndex];
  1153. } else {
  1154. [_datePopupButton selectItemAtIndex:0];
  1155. }
  1156. _dateButton.state = includeTime ? NSControlStateValueOn:NSControlStateValueOff;
  1157. }
  1158. - (void)typeSelected:(CAnnotationType)type
  1159. {
  1160. _falseTypeButton.layer.backgroundColor =
  1161. _tureTypeButton.layer.backgroundColor =
  1162. _circletypeButton.layer.backgroundColor =
  1163. _lineTypeButton.layer.backgroundColor =
  1164. _dotTypeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  1165. _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkNor"];
  1166. _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickNor"];
  1167. _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRoundedrecNor"];
  1168. _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineNor"];
  1169. // _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointNor"];
  1170. if (type == CAnnotationTypeSignFalse) {
  1171. self.falseTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  1172. _falseTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignForkSel"];
  1173. } else if (type == CAnnotationTypeSignTure) {
  1174. self.tureTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  1175. _tureTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignTickSel"];
  1176. } else if (type == CAnnotationTypeSignCircle){
  1177. self.circletypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  1178. _circletypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignRounderdrecSel"];
  1179. } else if (type == CAnnotationTypeSignLine) {
  1180. self.lineTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  1181. _lineTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignLineSel"];
  1182. } else if (type == CAnnotationTypeSignDot) {
  1183. self.dotTypeButton.layer.backgroundColor = [NSColor grayColor].CGColor;
  1184. _dotTypeButton.image = [NSImage imageNamed:@"KMImageNamePropertybarFillsignPointSet"];
  1185. }
  1186. }
  1187. - (void)updateAnnotation
  1188. {
  1189. CPDFAnnotation *annotation = self.annotationModel.annotation;
  1190. if (annotation) {
  1191. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1192. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  1193. if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
  1194. [self.pdfView commitEditAnnotationFreeText:textNote];
  1195. }
  1196. }
  1197. for (CPDFAnnotation *tAnnotation in self.annotationModel.annotations) {
  1198. if([tAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  1199. [(KMSelfSignAnnotation *)tAnnotation updateAppearanceStream];
  1200. }
  1201. if ([tAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  1202. [self.pdfView setNeedsDisplayForPage:tAnnotation.page];
  1203. } else {
  1204. [self.pdfView setNeedsDisplayAnnotationViewForPage:tAnnotation.page];
  1205. }
  1206. }
  1207. }
  1208. self.generalImageView.image = [self.annotationModel annotationImage];
  1209. }
  1210. - (NSDictionary *)freeTextPropertWithTitle:(NSInteger)integer {
  1211. NSDictionary *model;
  1212. NSArray *array = [CPDFAnnotationModel defaultFreeTextPropert];
  1213. // if ([string isEqualToString:@"Customize"]) {
  1214. // model = [array objectAtIndex:0];
  1215. // } else if ([string isEqualToString:@"H1 Headline"]) {
  1216. // model = [array objectAtIndex:1];
  1217. // } else if ([string isEqualToString:@"H2 Title"]) {
  1218. // model = [array objectAtIndex:2];
  1219. // } else if ([string isEqualToString:@"H3 Subtitle"]) {
  1220. // model = [array objectAtIndex:3];
  1221. // } else if ([string isEqualToString:@"B1 Text"]) {
  1222. // model = [array objectAtIndex:4];
  1223. // } else if ([string isEqualToString:@"B2 Small Text"]) {
  1224. // model = [array objectAtIndex:5];
  1225. // } else if ([string isEqualToString:@"B3 Describtion"]) {
  1226. // model = [array objectAtIndex:6];
  1227. // }
  1228. model = [array objectAtIndex:integer];
  1229. return model;
  1230. }
  1231. #pragma mark MarkUp
  1232. - (void)createMarkupProperties {
  1233. [self hiddenSubviews];
  1234. _fillColorBox.contentView = _fillColorPickerVC.view;
  1235. __block typeof(self) blockSelf = self;
  1236. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1237. blockSelf.annotationModel.color = color;
  1238. blockSelf.annotationModel.opacity = color.alphaComponent;
  1239. [blockSelf updateOpacityView];
  1240. [blockSelf updateAnnotation];
  1241. };
  1242. if (CAnnotationTypeHighlight == _annotationType) {
  1243. self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupHighlightColors;
  1244. } else {
  1245. self.fillColorPickerVC.annotationType = KMPropertiesColor_MarkupOtherColors;
  1246. }
  1247. }
  1248. #pragma mark SKLineNote
  1249. - (void)createInkAndLineProperties {
  1250. [self hiddenSubviews];
  1251. _fillColorBox.contentView = _fillColorPickerVC.view;
  1252. __block typeof(self) blockSelf = self;
  1253. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1254. if (color) {
  1255. CGFloat r, g, b, a = 0.0;
  1256. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1257. blockSelf.annotationModel.color = color;
  1258. blockSelf.annotationModel.opacity = a;
  1259. } else {
  1260. blockSelf.annotationModel.color = [NSColor blackColor];
  1261. blockSelf.annotationModel.opacity = 0;
  1262. }
  1263. [blockSelf updateOpacityView];
  1264. [blockSelf updateAnnotation];
  1265. };
  1266. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1267. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1268. if (CAnnotationTypeLine == self.annotationModel.annotationType ||
  1269. CAnnotationTypeArrow == self.annotationModel.annotationType) {
  1270. self.fillColorPickerVC.annotationType = KMPropertiesColor_LineColors;
  1271. } else if (CAnnotationTypeInk == self.annotationModel.annotationType) {
  1272. self.fillColorPickerVC.annotationType = KMPropertiesColor_InkColors;
  1273. }
  1274. }
  1275. - (void)createDefultFontPropert {
  1276. NSArray *defaultSting = @[@"Customize",@"H1 Headline",@"H2 Title",@"H3 Subtitle",@"B1 Text",@"B2 Small Text",@"B3 Describtion"];
  1277. for(NSString* title in defaultSting){
  1278. [self.defaultPopUpButton addItemWithTitle:NSLocalizedString(title, nil)];
  1279. }
  1280. [self.defaultPopUpButton selectItemAtIndex:0];
  1281. }
  1282. - (void)updateFigureModel {
  1283. if(self.pdfView.annotationType != CAnnotationTypeUnkown) {
  1284. if (_annotationType == CAnnotationTypeSquare) {
  1285. self.squareVC.state = KMDesignTokenStateSel;
  1286. } else if (_annotationType == CAnnotationTypeCircle) {
  1287. self.circleVC.state = KMDesignTokenStateSel;
  1288. } else if (_annotationType == CAnnotationTypeArrow) {
  1289. self.arrowVC.state = KMDesignTokenStateSel;
  1290. } else if (_annotationType == CAnnotationTypeLine) {
  1291. self.lineVC.state = KMDesignTokenStateSel;
  1292. }
  1293. }
  1294. }
  1295. - (void)updateCurrentDefaultFont:(NSMenuItem *)item {
  1296. if (item.tag == 0) {
  1297. NSDictionary *newdic = @{@"fontName":self.annotationModel.fontName,@"fontSize":[NSString stringWithFormat:@"%.f",self.annotationModel.fontSize]};
  1298. switch (self.defaultPopUpButton.indexOfSelectedItem) {
  1299. case 1:
  1300. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H1"];
  1301. break;
  1302. case 2:
  1303. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H2"];
  1304. break;
  1305. case 3:
  1306. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H3"];
  1307. break;
  1308. case 4:
  1309. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B1"];
  1310. break;
  1311. case 5:
  1312. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B2"];
  1313. break;
  1314. case 6:
  1315. [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B3"];
  1316. break;
  1317. default:
  1318. break;
  1319. }
  1320. [self updateFontView];
  1321. } else if (item.tag == 1) {
  1322. switch (self.defaultPopUpButton.indexOfSelectedItem) {
  1323. case 1:
  1324. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"36"} forKey:@"CPDFFreeTextDefaultFontObjects_H1"];
  1325. break;
  1326. case 2:
  1327. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"24"} forKey:@"CPDFFreeTextDefaultFontObjects_H2"];
  1328. break;
  1329. case 3:
  1330. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"18"} forKey:@"CPDFFreeTextDefaultFontObjects_H3"];
  1331. break;
  1332. case 4:
  1333. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"14"} forKey:@"CPDFFreeTextDefaultFontObjects_B1"];
  1334. break;
  1335. case 5:
  1336. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"12"} forKey:@"CPDFFreeTextDefaultFontObjects_B2"];
  1337. break;
  1338. case 6:
  1339. [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"11"} forKey:@"CPDFFreeTextDefaultFontObjects_B3"];
  1340. break;
  1341. default:
  1342. break;
  1343. }
  1344. [self defaultFontPopUpButtonAction:nil];
  1345. }
  1346. }
  1347. #pragma mark - SquareNote、CircleNote、ArrowNote Properties
  1348. - (void)createSquareAndCircleProperties {
  1349. [self hiddenSubviews];
  1350. __block typeof(self) blockSelf = self;
  1351. _fillColorBox.contentView = _fillColorPickerVC.view;
  1352. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1353. CGFloat red,green,blue,alpha;
  1354. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1355. if (fabs(alpha - 0) < 0.001) {
  1356. blockSelf.annotationModel.interiorColor = nil;
  1357. } else {
  1358. blockSelf.annotationModel.interiorColor = color;
  1359. }
  1360. [blockSelf updateAnnotation];
  1361. };
  1362. _borderColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1363. if (color) {
  1364. blockSelf.annotationModel.color = color;
  1365. blockSelf.annotationModel.opacity = 1;
  1366. } else {
  1367. //设置透明色必须要设一个颜色值
  1368. blockSelf.annotationModel.color = [NSColor blackColor];
  1369. blockSelf.annotationModel.opacity = 0;
  1370. }
  1371. [blockSelf updateOpacityView];
  1372. [blockSelf updateAnnotation];
  1373. };
  1374. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1375. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1376. self.fillColorPickerVC.annotationType = KMPropertiesColor_LineFillColors;
  1377. self.fillColorPickerVC.isFillColor = YES;
  1378. self.borderColorPickerVC.annotationType = KMPropertiesColor_CircleLineColors;
  1379. }
  1380. #pragma mark - FreeTextNote、KMPDFAnnotationFreeText Properties
  1381. - (void)createFreeTextProperties {
  1382. [self hiddenSubviews];
  1383. __block typeof(self) blockSelf = self;
  1384. _fillColorBox.contentView = _fillColorPickerVC.view;
  1385. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1386. CGFloat red,green,blue,alpha;
  1387. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1388. if(alpha == 0) {
  1389. blockSelf.annotationModel.color = nil;
  1390. } else {
  1391. blockSelf.annotationModel.color = color;
  1392. }
  1393. [blockSelf updateOpacityView];
  1394. CPDFAnnotation *annotation = blockSelf.annotationModel.annotation;
  1395. if (annotation) {
  1396. [blockSelf.pdfView setNeedsDisplayAnnotationViewForPage:annotation.page];
  1397. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1398. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  1399. if ([blockSelf.pdfView isEditWithCurrentFreeText:textNote]) {
  1400. [blockSelf.pdfView setEditAnnotationFreeTextBackgroundColor:color freeText:textNote];
  1401. } else {
  1402. [blockSelf updateAnnotation];
  1403. }
  1404. }
  1405. blockSelf.generalImageView.image = [blockSelf.annotationModel annotationImage];
  1406. } else {
  1407. [blockSelf updateAnnotation];
  1408. }
  1409. };
  1410. if (CAnnotationTypeFreeText == _annotationType ||
  1411. CAnnotationTypeSignDate == _annotationType ||
  1412. CAnnotationTypeSignText == _annotationType) {
  1413. self.fontColorButton.color = self.annotationModel.fontColor;
  1414. [self.fontColorButton setNeedsDisplay:YES];
  1415. }
  1416. self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
  1417. self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
  1418. self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
  1419. // NSArray *array = @[blockSelf.leftAlignBox,blockSelf.centerAlignBox,blockSelf.rightAlignBox];
  1420. // for (KMBox *box in array) {
  1421. // box.fillColor = [NSColor clearColor];
  1422. // box.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
  1423. // if (downEntered) {
  1424. // box.fillColor = [NSColor colorWithRed:206.0/255.0 green:208.0/255.0 blue:212.0/255.0 alpha:0.6];
  1425. // if (box == blockSelf.leftAlignBox) {
  1426. // [blockSelf leftAlignButtonAction:box];
  1427. // } else if (box == blockSelf.centerAlignBox) {
  1428. // [blockSelf centerAlignButtonAction:box];
  1429. // } else if (box == blockSelf.rightAlignBox) {
  1430. // [blockSelf rightAlignButtonAction:box];
  1431. // }
  1432. // } else {
  1433. // box.fillColor = [NSColor clearColor];
  1434. // }
  1435. // };
  1436. // box.mouseMoveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
  1437. // if (mouseEntered) {
  1438. // box.fillColor = [NSColor colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
  1439. // } else {
  1440. // box.fillColor = [NSColor clearColor];
  1441. // }
  1442. // };
  1443. // }
  1444. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1445. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1446. self.fillColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
  1447. }
  1448. #pragma mark - FreeTextNote、SelfSignAnnotationFreeText Properties
  1449. - (void)createSelfSignFreeTextProperties {
  1450. [self hiddenSubviews];
  1451. __block typeof(self) blockSelf = self;
  1452. // NSArray *array = @[blockSelf.leftAlignBox,blockSelf.centerAlignBox,blockSelf.rightAlignBox];
  1453. // for (KMBox *box in array) {
  1454. // box.fillColor = [NSColor clearColor];
  1455. // box.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
  1456. // if (downEntered) {
  1457. // box.fillColor = [NSColor colorWithRed:237.0/255.0 green:238.0/255.0 blue:240.0/255.0 alpha:1];
  1458. // if (box == blockSelf.leftAlignBox) {
  1459. // [blockSelf leftAlignButtonAction:box];
  1460. // } else if (box == blockSelf.centerAlignBox) {
  1461. // [blockSelf centerAlignButtonAction:box];
  1462. // } else if (box == blockSelf.rightAlignBox) {
  1463. // [blockSelf rightAlignButtonAction:box];
  1464. // }
  1465. // } else {
  1466. // box.fillColor = [NSColor clearColor];
  1467. // }
  1468. // };
  1469. // box.mouseMoveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
  1470. // if (mouseEntered) {
  1471. // box.fillColor = [NSColor lightGrayColor];
  1472. // } else {
  1473. // box.fillColor = [NSColor clearColor];
  1474. // }
  1475. // };
  1476. // }
  1477. _backgroundBox.contentView = _backgroundColorPickerVC.view;
  1478. _backgroundColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1479. CGFloat r, g, b, a = 0.0;
  1480. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1481. if(a == 0) {
  1482. blockSelf.annotationModel.color = nil;
  1483. } else {
  1484. blockSelf.annotationModel.color = color;
  1485. }
  1486. [blockSelf updateOpacityView];
  1487. [blockSelf updateAnnotation];
  1488. };
  1489. if ([self.annotationModel.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1490. self.fontColorButton.color = self.annotationModel.fontColor;
  1491. [self.fontColorButton setNeedsDisplay:YES];
  1492. }
  1493. self.leftAlignVC.button.toolTip = NSLocalizedString(@"Left Alignment", nil);
  1494. self.centerAlignVC.button.toolTip = NSLocalizedString(@"Center", nil);
  1495. self.rightAlignVC.button.toolTip = NSLocalizedString(@"Right Alignment", nil);
  1496. NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc]initWithAttributedString:[_dateButton attributedTitle]];
  1497. NSUInteger len = [attrTitle length];
  1498. NSRange range = NSMakeRange(0, len);
  1499. [attrTitle addAttribute:NSForegroundColorAttributeName
  1500. value:[NSColor lightGrayColor]
  1501. range:range];
  1502. [attrTitle fixAttributesInRange:range];
  1503. [_dateButton setAttributedTitle:attrTitle];
  1504. if ([self.annotationModel.annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  1505. if (self.annotationModel.annotation.contents.length <= 0) {
  1506. self.annotationModel.annotation.contents = self.datePopupButton.title;
  1507. }
  1508. }
  1509. self.backgroundColorPickerVC.annotationType = KMPropertiesColor_FreeTextFillColors;
  1510. }
  1511. #pragma mark - KMSelfSignAnnotation
  1512. - (void)createSelfSignProperties {
  1513. [self hiddenSubviews];
  1514. __block typeof(self) blockSelf = self;
  1515. _fillColorBox.contentView = _fillColorPickerVC.view;
  1516. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1517. CGFloat r, g, b, a = 0.0;
  1518. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1519. blockSelf.annotationModel.color = color;
  1520. blockSelf.annotationModel.opacity = a;
  1521. [blockSelf updateOpacityView];
  1522. [blockSelf updateAnnotation];
  1523. };
  1524. if (self.annotationModel.annotation) {
  1525. CAnnotationType annotationType = [(KMSelfSignAnnotation *)self.annotationModel.annotation annotationType];
  1526. [self typeSelected:annotationType];
  1527. }
  1528. NSColor *color = self.annotationModel.color;
  1529. CGFloat r, g, b, a = 0.0;
  1530. [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1531. CGFloat opacity = self.annotationModel.opacity;
  1532. // [self.borderWidthComboBox removeAllItems];
  1533. // NSMutableArray *titles = @[@"1 pt",@"3 pt",@"6 pt",@"9 pt",@"12 pt"].mutableCopy;
  1534. // for (NSString *string in titles) {
  1535. // [self.borderWidthComboBox addItemWithObjectValue:string];
  1536. // }
  1537. self.borderWidthSlider.maxValue = 12;
  1538. self.fillColorPickerVC.color = [NSColor colorWithRed:r green:g blue:b alpha:opacity];
  1539. self.opacityComboBox.stringValue = [NSString stringWithFormat:@"%@%%",@((int)(opacity*100))];
  1540. self.opacitySlider.floatValue = opacity;
  1541. self.borderWidthSlider.floatValue = self.annotationModel.lineWidth;
  1542. self.borderWidthVC.stringValue = [NSString stringWithFormat:@"%0.1f pt",self.annotationModel.lineWidth];
  1543. self.fillColorPickerVC.annotationType = KMPropertiesColor_SelfSignColors;
  1544. }
  1545. -(NSUInteger)setFontStyleWithFontName:(NSString *)fontName currentStyle:(NSString *)style
  1546. {
  1547. NSUInteger selectIndex = -1;
  1548. // NSMenu *menu = [[NSMenu alloc] init];
  1549. NSMutableArray *fontStyles = [NSMutableArray array];
  1550. for (NSDictionary *dic in self.fonts) {
  1551. NSString *familyString = dic.allKeys.firstObject;
  1552. if ([familyString isEqual:fontName]) {
  1553. NSArray *styles = [dic objectForKey:fontName];
  1554. for (NSUInteger i = 0; i < styles.count; i++) {
  1555. NSString * styleName = [styles objectAtIndex:i];
  1556. if ([style isEqualToString:styleName]) {
  1557. selectIndex = i;
  1558. }
  1559. NSFontDescriptor *attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName,NSFontFaceAttribute:styleName}];
  1560. if ([styleName isEqualToString:@"Roman"]) {
  1561. attributeFontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute:fontName}];
  1562. selectIndex = 0;
  1563. }
  1564. // NSFont *font = [NSFont fontWithDescriptor:attributeFontDescriptor size:12.0];
  1565. // NSDictionary *attrited = @{NSFontAttributeName:font};
  1566. // NSAttributedString *string = [[NSAttributedString alloc] initWithString:styleName attributes:attrited];
  1567. // NSMenuItem *item = [[NSMenuItem alloc] init];
  1568. // item.attributedTitle = string;
  1569. // [menu addItem:item];
  1570. [fontStyles addObject:styleName];
  1571. }
  1572. break;
  1573. }
  1574. }
  1575. if (!style) {
  1576. selectIndex = 0;
  1577. }
  1578. // [self.fontStylePopUpButton setMenu:menu];
  1579. return selectIndex;
  1580. }
  1581. #pragma mark annotation text
  1582. - (void)createTextProperties {
  1583. [self hiddenSubviews];
  1584. __block typeof(self) blockSelf = self;
  1585. _fillColorBox.contentView = _fillColorPickerVC.view;
  1586. _fillColorPickerVC.colorChangeCallback = ^(NSColor *color) {
  1587. blockSelf.annotationModel.color = color;
  1588. [blockSelf updateOpacityView];
  1589. [blockSelf updateAnnotation];
  1590. };
  1591. self.fillColorPickerVC.annotationType = KMPropertiesColor_AnchoredNoteColors;
  1592. self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOne"];
  1593. self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStylenote"];
  1594. self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWord"];
  1595. self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStyleHelp"];
  1596. self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStyleP"];
  1597. self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsert"];
  1598. self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNP"];
  1599. CPDFTextAnnotationIconType type = CPDFTextAnnotationIconNote;
  1600. if (self.annotationModel.annotations.count > 0) {
  1601. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1602. if([firstAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  1603. type = [(CPDFTextAnnotation *)firstAnnotation iconType];
  1604. }
  1605. } else {
  1606. type = self.annotationModel.anchoredIconType;
  1607. }
  1608. switch (type) {
  1609. case CPDFTextAnnotationIconComment:
  1610. self.noteStyleNoneButton.image = [NSImage imageNamed:@"KMImagePropertTextStyleOneSelect"];
  1611. break;
  1612. case CPDFTextAnnotationIconKey:
  1613. self.noteStyleButton2.image = [NSImage imageNamed:@"KMImagePropertTextStyleKeyWordSelect"];
  1614. break;
  1615. case CPDFTextAnnotationIconNote:
  1616. self.noteStyleButton1.image = [NSImage imageNamed:@"KMImagePropertTextStyleNoteSelect"];
  1617. break;
  1618. case CPDFTextAnnotationIconHelp:
  1619. self.noteStyleButton3.image = [NSImage imageNamed:@"KMImagePropertTextStylehelpSelect"];
  1620. break;
  1621. case CPDFTextAnnotationIconNewParagraph:
  1622. self.noteStyleButton6.image = [NSImage imageNamed:@"KMImagePropertTextStyleNPSelect"];
  1623. break;
  1624. case CPDFTextAnnotationIconParagraph:
  1625. self.noteStyleButton4.image = [NSImage imageNamed:@"KMImagePropertTextStylePSelect"];
  1626. break;
  1627. case CPDFTextAnnotationIconInsert:
  1628. self.noteStyleButton5.image = [NSImage imageNamed:@"KMImagePropertTextStyleInsertSelect"];
  1629. break;
  1630. default:
  1631. break;
  1632. }
  1633. }
  1634. #pragma mark annotation Ink
  1635. - (IBAction)updateInkStype:(NSButton *)sender {
  1636. self.annotationModel.style = sender.tag;
  1637. [self updateBorderWidthView];
  1638. [self updateAnnotation];
  1639. }
  1640. - (IBAction)updateInkButton_click:(NSButton *)sender {
  1641. [self updateInkAction:sender];
  1642. if ((sender == self.addInkButton && _annotationType == CAnnotationTypeInk) || (sender == self.clearInkButton && _annotationType == CAnnotationTypeEraser)) {
  1643. return;
  1644. }
  1645. if (sender != self.addInkButton) {
  1646. self.pdfView.annotationType = CAnnotationTypeEraser;
  1647. [self.borderWidthVC removeAllItems];
  1648. [self.borderWidthVC addItemsWithObjectValues:@[@"5pt",@"10pt",@"15pt",@"20pt"]];
  1649. } else {
  1650. [self.borderWidthVC removeAllItems];
  1651. [self.borderWidthVC addItemsWithObjectValues:@[@"1pt",@"2pt",@"4pt",@"6pt",@"8pt"]];
  1652. self.pdfView.annotationType = CAnnotationTypeInk;
  1653. }
  1654. if (self.callBack) {
  1655. self.callBack (self.pdfView.annotationType);
  1656. }
  1657. self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
  1658. [self loadingUIAndLocalization];
  1659. }
  1660. #pragma mark annotation stamp
  1661. - (IBAction)showOpacityView:(id)sender {
  1662. KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
  1663. vc.annotationModel = self.annotationModel;
  1664. if (!_fillColorPopover) {
  1665. _fillColorPopover = [[NSPopover alloc] init];
  1666. _fillColorPopover.delegate = self;
  1667. }
  1668. _fillColorPopover.contentViewController = vc;
  1669. _fillColorPopover.animates = YES;
  1670. _fillColorPopover.behavior = NSPopoverBehaviorSemitransient;
  1671. [_fillColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
  1672. [_fillColorPopover showRelativeToRect:NSMakeRect(_fillColorView.bounds.origin.x, 57, _fillColorView.bounds.size.width, _fillColorView.bounds.size.height) ofView:_fillColorView preferredEdge:NSRectEdgeMinY];
  1673. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1674. __block typeof(self) blockSelf = self;
  1675. vc.callback = ^(CGFloat opacity) {
  1676. [blockSelf updateFillColorPickerVC];
  1677. [blockSelf updateAnnotation];
  1678. };
  1679. }
  1680. - (IBAction)showBorderOpacityView:(id)sender {
  1681. KMOpacityPanel *vc = [[KMOpacityPanel alloc] initWithNibName:@"KMOpacityPanel" bundle:nil];
  1682. vc.annotationModel = self.annotationModel;
  1683. if (!_borderColorPopover) {
  1684. _borderColorPopover = [[NSPopover alloc] init];
  1685. _borderColorPopover.delegate = self;
  1686. }
  1687. _borderColorPopover.contentViewController = vc;
  1688. _borderColorPopover.animates = YES;
  1689. _borderColorPopover.behavior = NSPopoverBehaviorSemitransient;
  1690. [_borderColorPopover setValue:@(YES) forKey:@"shouldHideAnchor"];
  1691. [_borderColorPopover showRelativeToRect:NSMakeRect(_borderColorView.bounds.origin.x, 47, _borderColorView.bounds.size.width, _borderColorView.bounds.size.height) ofView:_borderColorView preferredEdge:NSRectEdgeMinY];
  1692. if (_annotationModel.annotations.count > 0) {
  1693. CPDFAnnotation *firstAnnotation = _annotationModel.annotations.firstObject;
  1694. if ([firstAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  1695. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1696. } else {
  1697. vc.type = AnnotationOpacityTypeOpacity;
  1698. }
  1699. } else {
  1700. if (_annotationModel.annotationType == CAnnotationTypeLine ||
  1701. _annotationModel.annotationType == CAnnotationTypeArrow) {
  1702. vc.type = AnnotationOpacityTypeInteriorOpacity;
  1703. } else {
  1704. vc.type = AnnotationOpacityTypeOpacity;
  1705. }
  1706. }
  1707. __block typeof(self) blockSelf = self;
  1708. vc.callback = ^(CGFloat opacity) {
  1709. [blockSelf updateBorderColorPickerVC];
  1710. [blockSelf updateAnnotation];
  1711. };
  1712. }
  1713. - (void)createStampProperties {
  1714. [self hiddenSubviews];
  1715. }
  1716. #pragma mark - UI Action
  1717. - (IBAction)opacitySliderAction:(id)sender
  1718. {
  1719. CGFloat opcity = self.opacitySlider.floatValue;
  1720. if (self.opacitySlider.floatValue == 0) {
  1721. opcity = 0.0001;
  1722. }
  1723. CAnnotationType annotationType = self.annotationModel.annotationType;
  1724. if (CAnnotationTypeSignFalse == annotationType ||
  1725. CAnnotationTypeSignTure == annotationType ||
  1726. CAnnotationTypeSignDot == annotationType ||
  1727. CAnnotationTypeSignCircle == annotationType ||
  1728. CAnnotationTypeSignLine == annotationType) {
  1729. self.annotationModel.opacity = opcity;
  1730. [self updateFillColorPickerVC];
  1731. } else if(CAnnotationTypeCircle == annotationType ||
  1732. CAnnotationTypeSquare == annotationType){
  1733. if(opcity !=0) {
  1734. self.annotationModel.opacity = opcity;
  1735. self.annotationModel.interiorOpacity= opcity;
  1736. } else {
  1737. self.annotationModel.color = nil;
  1738. self.annotationModel.interiorColor= nil;
  1739. }
  1740. [self updateFillColorPickerVC];
  1741. [self updateBorderColorPickerVC];
  1742. } else if (CAnnotationTypeFreeText == annotationType ||
  1743. CAnnotationTypeSignDate == annotationType ||
  1744. CAnnotationTypeSignText == annotationType ) {
  1745. self.annotationModel.opacity = opcity;
  1746. [self updateBackgroundColorPickerVC];
  1747. NSColor *color = self.annotationModel.fontColor;
  1748. if (self.annotationModel.opacity != 0) {
  1749. CGFloat red,green,blue,alpha;
  1750. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  1751. color = [NSColor colorWithRed:red green:green blue:blue alpha:self.annotationModel.interiorOpacity];
  1752. } else {
  1753. color = [NSColor clearColor];
  1754. }
  1755. self.fontColorButton.color = color;
  1756. [self.fontColorButton setNeedsDisplay:YES];
  1757. } else {
  1758. self.annotationModel.opacity = opcity;
  1759. [self updateFillColorPickerVC];
  1760. }
  1761. [self updateOpacityView];
  1762. [self updateAnnotation];
  1763. }
  1764. - (IBAction)borderOpacitySliderAction:(id)sender
  1765. {
  1766. CGFloat opcity = self.borderOpacitySlider.floatValue;
  1767. if (self.borderOpacitySlider.floatValue == 0) {
  1768. opcity = 0.0001;
  1769. }
  1770. CAnnotationType annotationType = self.annotationModel.annotationType;
  1771. if(CAnnotationTypeCircle == annotationType ||
  1772. CAnnotationTypeSquare == annotationType){
  1773. if(opcity !=0) {
  1774. self.annotationModel.opacity = opcity;
  1775. } else {
  1776. self.annotationModel.color = nil;
  1777. self.annotationModel.interiorColor= nil;
  1778. }
  1779. [self updateFillColorPickerVC];
  1780. [self updateBorderColorPickerVC];
  1781. }
  1782. [self updateBorderOpacityView];
  1783. [self updateAnnotation];
  1784. }
  1785. - (IBAction)opacityComboBoxAction:(id)sender
  1786. {
  1787. [self.opacitySlider setFloatValue:(CGFloat)[self.opacityComboBox intValue]/100];
  1788. CGFloat opcity = self.opacitySlider.floatValue;
  1789. if (self.opacitySlider.floatValue == 0) {
  1790. opcity = 0.0001;
  1791. }
  1792. CAnnotationType annotationType = self.annotationModel.annotationType;
  1793. if (CAnnotationTypeSignFalse == annotationType ||
  1794. CAnnotationTypeSignTure == annotationType ||
  1795. CAnnotationTypeSignDot == annotationType ||
  1796. CAnnotationTypeSignCircle == annotationType ||
  1797. CAnnotationTypeSignLine == annotationType) {
  1798. self.annotationModel.opacity = opcity;
  1799. [self updateFillColorPickerVC];
  1800. } else if(CAnnotationTypeCircle == annotationType ||
  1801. CAnnotationTypeSquare == annotationType){
  1802. if(opcity !=0) {
  1803. self.annotationModel.opacity = opcity;
  1804. self.annotationModel.interiorOpacity= opcity;
  1805. } else {
  1806. self.annotationModel.color = nil;
  1807. self.annotationModel.interiorColor= nil;
  1808. }
  1809. [self updateFillColorPickerVC];
  1810. [self updateBorderColorPickerVC];
  1811. } else if (CAnnotationTypeFreeText == annotationType ||
  1812. CAnnotationTypeSignDate == annotationType ||
  1813. CAnnotationTypeSignText == annotationType ) {
  1814. self.annotationModel.interiorOpacity = opcity;
  1815. [self updateBackgroundColorPickerVC];
  1816. } else {
  1817. self.annotationModel.opacity = opcity;
  1818. [self updateFillColorPickerVC];
  1819. }
  1820. [self updateOpacityView];
  1821. [self updateAnnotation];
  1822. }
  1823. - (IBAction)borderWidthSliderAction:(id)sender
  1824. {
  1825. self.annotationModel.lineWidth = self.borderWidthSlider.floatValue;
  1826. [self updateBorderWidthView];
  1827. [self updateAnnotation];
  1828. }
  1829. - (IBAction)leftAlignButtonAction:(NSBox *)sender {
  1830. [self updateAnnotation];
  1831. NSTextAlignment alignment = NSTextAlignmentLeft;
  1832. self.annotationModel.alignment = alignment;
  1833. [self alignmentTypeSelected:alignment];
  1834. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1835. [self updateAnnotation];
  1836. }
  1837. - (IBAction)centerAlignButtonAction:(NSBox *)sender {
  1838. [self updateAnnotation];
  1839. NSTextAlignment alignment = NSTextAlignmentCenter;
  1840. self.annotationModel.alignment = alignment;
  1841. [self alignmentTypeSelected:alignment];
  1842. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1843. [self updateAnnotation];
  1844. }
  1845. - (IBAction)rightAlignButtonAction:(NSBox *)sender {
  1846. [self updateAnnotation];
  1847. NSTextAlignment alignment = NSTextAlignmentRight;
  1848. self.annotationModel.alignment = alignment;
  1849. [self alignmentTypeSelected:alignment];
  1850. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1851. [self updateAnnotation];
  1852. }
  1853. - (IBAction)justifiedAlignButtonAction:(NSBox *)sender {
  1854. [self updateAnnotation];
  1855. NSTextAlignment alignment = NSTextAlignmentJustified;
  1856. self.annotationModel.alignment = alignment;
  1857. [self alignmentTypeSelected:alignment];
  1858. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationAlignmentTypeNotification" object:[NSString stringWithFormat:@"%ld",alignment]];
  1859. [self updateAnnotation];
  1860. }
  1861. - (IBAction)currentFontColorButtonAction:(NSButton *)sender {
  1862. KMAnnotationFontWindowController *fontWindowController = [KMAnnotationFontWindowController sharedAnnotationFont];
  1863. fontWindowController.PDFListView = self.pdfView;
  1864. NSWindow *window = [fontWindowController window];
  1865. fontWindowController.annotationModel = self.annotationModel;
  1866. __block typeof(self) blockSelf = self;
  1867. fontWindowController.annotationAlignCallback = ^(NSInteger selectedCount) {
  1868. NSTextAlignment textAlignment = NSTextAlignmentLeft;
  1869. if (selectedCount == 0) {
  1870. textAlignment = NSTextAlignmentLeft;
  1871. } else if (selectedCount == 2) {
  1872. textAlignment = NSTextAlignmentCenter;
  1873. } else if (selectedCount == 1) {
  1874. textAlignment = NSTextAlignmentRight;
  1875. } else if (selectedCount == 3) {
  1876. textAlignment = NSTextAlignmentJustified;
  1877. }
  1878. [blockSelf alignmentTypeSelected:selectedCount];
  1879. if(blockSelf.annotationModel) {
  1880. blockSelf.annotationModel.alignment = textAlignment;
  1881. [blockSelf updateAnnotation];
  1882. }
  1883. };
  1884. fontWindowController.annotationCallback = ^(CPDFAnnotation *annotation) {
  1885. [blockSelf updateFontView];
  1886. [blockSelf updateAnnotation];
  1887. };
  1888. [window orderFront:sender];
  1889. }
  1890. - (IBAction)fontCustomColorButtonAction:(NSButton *)sender {
  1891. [[NSColorPanel sharedColorPanel] setTarget:self];
  1892. [NSColorPanel sharedColorPanel].showsAlpha = YES;
  1893. [[NSColorPanel sharedColorPanel] setAction:@selector(colorPanelAction:)];
  1894. [[NSColorPanel sharedColorPanel] orderFront:nil];
  1895. }
  1896. - (IBAction)fontColorButtonAction:(NSButton *)sender {
  1897. self.annotationModel.fontColor = _fontColorButton.color;
  1898. [self updateAnnotation];
  1899. }
  1900. - (NSColor *)colorWithCGColor:(CGColorRef)CGColor
  1901. {
  1902. if (CGColor == NULL) return nil;
  1903. return [NSColor colorWithCIColor:[CIColor colorWithCGColor:CGColor]];
  1904. }
  1905. - (void)colorPanelAction:(id)sender {
  1906. if([NSColorPanel sharedColorPanel].visible) {
  1907. NSColor *currentColor = [NSColorPanel sharedColorPanel].color;
  1908. _fontColorButton.color = currentColor;
  1909. [self.fontColorButton setNeedsDisplay:YES];
  1910. CGFloat r, g, b, a = 0.0;
  1911. [[currentColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1912. if (fabs(a - 0) < 0.001) {
  1913. //设置透明色必须要设一个颜色值
  1914. self.annotationModel.opacity = 0;
  1915. self.annotationModel.fontColor = [NSColor blackColor];
  1916. } else {
  1917. self.annotationModel.opacity = a;
  1918. self.annotationModel.fontColor = currentColor;
  1919. }
  1920. [self updateOpacityView];
  1921. if (CAnnotationTypeFreeText == _annotationType ||
  1922. CAnnotationTypeSignDate == _annotationType ||
  1923. CAnnotationTypeSignText == _annotationType) {
  1924. [[self.annotationModel.fontColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
  1925. self.fontColorButton.color = [NSColor colorWithRed:r green:g blue:b alpha:self.annotationModel.opacity];
  1926. [_fontButton setNeedsDisplay:YES];
  1927. }
  1928. CPDFAnnotation *annotation = self.annotationModel.annotation;
  1929. if (annotation) {
  1930. if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  1931. CPDFFreeTextAnnotation *textNote = (CPDFFreeTextAnnotation *)annotation;
  1932. if ([self.pdfView isEditWithCurrentFreeText:textNote]) {
  1933. [self.pdfView setEditAnnotationFreeTextColor:currentColor freeText:textNote];
  1934. } else {
  1935. [self updateAnnotation];
  1936. }
  1937. } else {
  1938. [self updateAnnotation];
  1939. }
  1940. self.generalImageView.image = [self.annotationModel annotationImage];
  1941. } else {
  1942. [self updateAnnotation];
  1943. }
  1944. }
  1945. }
  1946. - (IBAction)buttonClicked_TypeAwitch:(NSButton *)sender {
  1947. NSInteger tag = sender.tag;
  1948. CAnnotationType annotationType = CAnnotationTypeSignLine;
  1949. if (tag == 201) {
  1950. annotationType = CAnnotationTypeSignTure;
  1951. } else if (tag == 202) {
  1952. annotationType = CAnnotationTypeSignFalse;
  1953. } else {
  1954. annotationType = tag;
  1955. }
  1956. self.selfSignType = annotationType;
  1957. [self typeSelected:annotationType];
  1958. if (self.callBack) {
  1959. self.callBack (annotationType);
  1960. }
  1961. self.annotationModel.stampAnnotationType = annotationType;
  1962. if (self.selfSignType == CAnnotationTypeSignDot) {
  1963. self.borderWidthView.hidden = YES;
  1964. self.borderWidthViewTopConstraint.constant = -(self.borderWidthView.bounds.size.height);
  1965. } else {
  1966. self.borderWidthView.hidden = NO;
  1967. self.borderWidthViewTopConstraint.constant = 16.0f;
  1968. }
  1969. [self updateAnnotation];
  1970. }
  1971. - (IBAction)buttonClicked_SwitchIncludeTime:(NSButton *)sender
  1972. {
  1973. self.annotationModel.includeTime = sender.state == NSControlStateValueOn?YES:NO;
  1974. [self updateDateView];
  1975. [self updateAnnotation];
  1976. }
  1977. - (IBAction)dateCheckButtonAction:(NSPopUpButton *)sender
  1978. {
  1979. self.annotationModel.dateFormatIndex = sender.indexOfSelectedItem;
  1980. [self updateAnnotation];
  1981. }
  1982. #pragma mark SqureAnnotation Style
  1983. - (IBAction)updateFigurateModelAction:(NSButton *)sender {
  1984. if ((sender == self.squareVC.button && _annotationType == CAnnotationTypeSquare) ||
  1985. (sender == self.circleVC.button && _annotationType == CAnnotationTypeCircle) ||
  1986. (sender == self.arrowVC.button && _annotationType == CAnnotationTypeArrow) ||
  1987. (sender == self.lineVC.button && _annotationType == CAnnotationTypeLine)) {
  1988. return;
  1989. }
  1990. self.squareVC.state = KMDesignTokenStateNorm;
  1991. self.circleVC.state = KMDesignTokenStateNorm;
  1992. self.arrowVC.state = KMDesignTokenStateNorm;
  1993. self.lineVC.state = KMDesignTokenStateNorm;
  1994. if (sender == self.squareVC.button) {
  1995. self.pdfView.annotationType = CAnnotationTypeSquare;
  1996. self.squareVC.state = KMDesignTokenStateSel;
  1997. } else if (sender == self.circleVC.button) {
  1998. self.pdfView.annotationType = CAnnotationTypeCircle;
  1999. self.circleVC.state = KMDesignTokenStateSel;
  2000. } else if (sender == self.arrowVC.button) {
  2001. self.pdfView.annotationType = CAnnotationTypeArrow;
  2002. self.arrowVC.state = KMDesignTokenStateSel;
  2003. } else if (sender == self.lineVC.button) {
  2004. self.pdfView.annotationType = CAnnotationTypeLine;
  2005. self.lineVC.state = KMDesignTokenStateSel;
  2006. }
  2007. self.annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.pdfView.annotationType];
  2008. [self loadingUIAndLocalization];
  2009. }
  2010. #pragma mark CPDFTextAnnotation Action
  2011. - (IBAction)textAnnotationStyleAction:(NSButton *)sender {
  2012. [self.annotationModel setAnchoredIconType:sender.tag];
  2013. [self loadingUIAndLocalization];
  2014. [self updateAnnotation];
  2015. }
  2016. #pragma mark Font、FontSize Action
  2017. - (IBAction)defaultFontPopUpButtonAction:(id)sender {
  2018. NSDictionary *model = [[CPDFAnnotationModel defaultFreeTextPropert] objectAtIndex:self.defaultPopUpButton.indexOfSelectedItem];
  2019. self.annotationModel.fontName = model[@"fontName"];
  2020. self.annotationModel.fontSize = [model[@"fontSize"] floatValue];
  2021. [self updateFillColorPickerVC];
  2022. [self updateFontView];
  2023. [self updateAnnotation];
  2024. [self createFreeTextProperties];
  2025. }
  2026. - (IBAction)resetDefaultAction:(id)sender {
  2027. NSMenu *menu = [[NSMenu alloc] init];
  2028. if (self.defaultPopUpButton.indexOfSelectedItem != 0) {
  2029. [menu addItemWithTitle:NSLocalizedString(@"Redefine", nil) action:@selector(updateCurrentDefaultFont:) target:self tag:0];
  2030. [menu addItemWithTitle:NSLocalizedString(@"Reset", nil) action:@selector(updateCurrentDefaultFont:) target:self tag:1];
  2031. } else {
  2032. [menu addItemWithTitle:NSLocalizedString(@"Redefine", nil) action:nil target:self tag:0];
  2033. [menu addItemWithTitle:NSLocalizedString(@"Reset", nil) action:nil target:self tag:1];
  2034. }
  2035. [menu popUpMenuPositioningItem:nil atLocation:NSMakePoint(self.view.frame.size.width-100, CGRectGetMinY(self.defaultFontView.frame)-7) inView:self.mianView];
  2036. }
  2037. #pragma mark - NSNotification
  2038. - (void)textDidChange:(NSNotification *)notification {
  2039. NSObject *obj = notification.object;
  2040. if ([obj isEqualTo:self.noteTextView]) {
  2041. [self.annotationModel setContents:self.noteTextView.string?:@""];
  2042. if (CAnnotationTypeHighlight == self.annotationModel.annotationType || CAnnotationTypeStrikeOut == self.annotationModel.annotationType || CAnnotationTypeUnderline == self.annotationModel.annotationType) {
  2043. } else {
  2044. [self updateAnnotation];
  2045. }
  2046. }
  2047. }
  2048. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  2049. if (![object isEqual:self.annotationModel.annotation]) {
  2050. return;
  2051. }
  2052. id newValue = [change objectForKey:NSKeyValueChangeNewKey] ? : [NSNull null];
  2053. id oldValue = [change objectForKey:NSKeyValueChangeOldKey] ? : [NSNull null];
  2054. if ([newValue isEqual:oldValue]) {
  2055. return;
  2056. }
  2057. if ([keyPath isEqualToString:@"contents"] || [keyPath isEqualToString:@"markupText"]) {
  2058. if ([newValue isKindOfClass:[NSNull class]]) {
  2059. return;
  2060. }
  2061. self.noteTextView.string = newValue ? : @"";
  2062. }
  2063. }
  2064. - (void)alignmentTypeNotification:(NSNotification *)notification {
  2065. NSString *count = notification.object;
  2066. NSTextAlignment alignment = NSTextAlignmentLeft;
  2067. if ([count isEqualToString:@"0"]) {
  2068. alignment = NSTextAlignmentLeft;
  2069. } else if ([count isEqualToString:@"1"]) {
  2070. alignment = NSTextAlignmentRight;
  2071. } else if ([count isEqualToString:@"2"]) {
  2072. alignment = NSTextAlignmentCenter;
  2073. }
  2074. [self alignmentTypeSelected:alignment];
  2075. }
  2076. - (void)annotationChangeNotification:(NSNotification *)notification {
  2077. if (notification.object != nil) {
  2078. CPDFAnnotation *annotation = notification.object[@"object"];
  2079. if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
  2080. if (![notification.object[@"keyPath"] isEqualToString: CPDFAnnotationBoundsKey]) {
  2081. [self configureUIView];
  2082. }
  2083. }
  2084. }
  2085. }
  2086. #pragma mark - NSPopoverDelegate
  2087. - (void)popoverWillShow:(NSNotification *)notification {
  2088. NSPopover *popover = notification.object;
  2089. if ([popover isEqual:_fillColorPopover]) {
  2090. self.fillButton.wantsLayer = YES;
  2091. self.fillButton.layer.cornerRadius = 4.0;
  2092. self.fillButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
  2093. } else if ([popover isEqual:_borderColorPopover]) {
  2094. self.showborderOpacityButton.wantsLayer = YES;
  2095. self.showborderOpacityButton.layer.cornerRadius = 4.0;
  2096. self.showborderOpacityButton.layer.backgroundColor = [NSColor colorWithRed:206/255.0 green:208/255.0 blue:212/255.0 alpha:1.0].CGColor;
  2097. }
  2098. }
  2099. - (void)popoverWillClose:(NSNotification *)notification {
  2100. NSPopover *popover = notification.object;
  2101. if ([popover isEqual:_fillColorPopover]) {
  2102. self.fillButton.wantsLayer = YES;
  2103. self.fillButton.layer.cornerRadius = 0.0;
  2104. self.fillButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  2105. } else if ([popover isEqual:_borderColorPopover]) {
  2106. self.showborderOpacityButton.wantsLayer = YES;
  2107. self.showborderOpacityButton.layer.cornerRadius = 0.0;
  2108. self.showborderOpacityButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  2109. }
  2110. }
  2111. #pragma mark - KMSelectPopButtonDelegate
  2112. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  2113. if ([self.fontNameVC isEqual:obj]) {
  2114. NSArray *fonts = [CPDFAnnotationModel supportFonts];
  2115. NSString *familyString = self.fontNameVC.stringValue;
  2116. for (NSDictionary *dict in fonts) {
  2117. NSString * fontName = dict.allKeys.firstObject;
  2118. if ([fontName isEqualToString:familyString]) {
  2119. [self.fontStyleVC removeAllItems];
  2120. [self.fontStyleVC addItemsWithObjectValues:dict.allValues.firstObject];
  2121. [self.fontStyleVC selectItemAt:0];
  2122. }
  2123. }
  2124. NSString *styleString = self.fontStyleVC.stringValue;
  2125. if ([styleString isEqualToString:@"Regular"] || [styleString isEqualToString:@"Roman"]) {
  2126. [_annotationModel setFontName:[NSString stringWithFormat:@"%@", familyString]];
  2127. } else {
  2128. [_annotationModel setFontName:[NSString stringWithFormat:@"%@-%@", familyString, [styleString stringByReplacingOccurrencesOfString:@" " withString:@""]]];
  2129. }
  2130. [self updateFontView];
  2131. [self adjustFreetText];
  2132. [self updateAnnotation];
  2133. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  2134. } else if ([self.fontStyleVC isEqual:obj]) {
  2135. NSInteger index = self.fontStyleVC.indexOfSelectedItem;
  2136. if (index < 0) {
  2137. return;
  2138. }
  2139. NSString *familyString = self.fontNameVC.stringValue;
  2140. NSString *styleString = self.fontStyleVC.stringValue;
  2141. if ([styleString isEqualToString:@"Regular"] || [styleString isEqualToString:@"Roman"]) {
  2142. [_annotationModel setFontName:[NSString stringWithFormat:@"%@", familyString]];
  2143. } else {
  2144. [_annotationModel setFontName:[NSString stringWithFormat:@"%@-%@", familyString, [styleString stringByReplacingOccurrencesOfString:@" " withString:@""]]];
  2145. }
  2146. [self updateFontView];
  2147. [self adjustFreetText];
  2148. [self updateAnnotation];
  2149. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  2150. } else if (self.fontSizeVC == obj) {
  2151. NSInteger index = self.fontSizeVC.indexOfSelectedItem;
  2152. if (index < 0) {
  2153. return;
  2154. }
  2155. NSString *size = [self.fontSizeVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""];
  2156. [self.annotationModel setFontSize:[size floatValue]];
  2157. [self adjustFreetText];
  2158. [self updateAnnotation];
  2159. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationFontTypeNotification" object:self.pdfView];
  2160. } else if (self.borderWidthVC == obj) {
  2161. CGFloat lineWidth = [[self.borderWidthVC.stringValue stringByReplacingOccurrencesOfString:@"pt" withString:@""] floatValue];
  2162. if (self.fillColorPickerVC.annotationType == KMPropertiesColor_SelfSignColors) {
  2163. if (lineWidth > 8) {
  2164. lineWidth = 8;
  2165. }
  2166. } else {
  2167. if (_annotationType != CAnnotationTypeEraser) {
  2168. if (lineWidth > 20) {
  2169. lineWidth = 20;
  2170. }
  2171. }
  2172. }
  2173. self.annotationModel.lineWidth = lineWidth;
  2174. [self updateBorderWidthView];
  2175. [self updateAnnotation];
  2176. }
  2177. }
  2178. -(void)adjustFreetText {
  2179. if(self.annotationModel.annotation &&
  2180. (CAnnotationTypeFreeText == self.annotationModel.annotationType ||
  2181. CAnnotationTypeSignText == self.annotationModel.annotationType ||
  2182. CAnnotationTypeSignDate == self.annotationModel.annotationType )) {
  2183. for(CPDFAnnotation *an in self.annotationModel.annotations) {
  2184. if([an isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  2185. CPDFFreeTextAnnotation *freeTextAn = (CPDFFreeTextAnnotation *)an;
  2186. NSFont* font = freeTextAn.font;
  2187. NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
  2188. [dictionary setObject:font forKey:NSFontAttributeName];
  2189. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  2190. [style setAlignment:freeTextAn.alignment];
  2191. [dictionary setObject:style forKey:NSParagraphStyleAttributeName];
  2192. CGSize textViewSize = [freeTextAn.contents?:@"" boundingRectWithSize:CGSizeMake(freeTextAn.bounds.size.width, MAXFLOAT)
  2193. options:NSStringDrawingUsesLineFragmentOrigin
  2194. attributes:dictionary].size;
  2195. CGRect rect = freeTextAn.bounds;
  2196. if(textViewSize.height != freeTextAn.bounds.size.height) {
  2197. rect.origin.y -= (textViewSize.height - rect.size.height);
  2198. rect.size.height = textViewSize.height;
  2199. }
  2200. if(textViewSize.width < freeTextAn.bounds.size.width) {
  2201. rect.size.width = textViewSize.width;
  2202. }
  2203. freeTextAn.bounds = rect;
  2204. }
  2205. }
  2206. }
  2207. }
  2208. - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj {
  2209. }
  2210. @end