KMGeneralAnnotationViewController.m 101 KB

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