KMGeneralAnnotationViewController.m 99 KB

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