KMGeneralAnnotationViewController.m 99 KB

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