KMGeneralAnnotationViewController.m 99 KB

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