KMGeneralAnnotationViewController.m 101 KB

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