KMGeneralAnnotationViewController.m 100 KB

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