CPDFFreeTextViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. //
  2. // CPDFFreeTextViewController.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFFreeTextViewController.h"
  13. #import "CPDFAnnotationBaseViewController_Header.h"
  14. #import "CPDFThicknessSliderView.h"
  15. #import "CPDFFontStyleTableView.h"
  16. #if __has_include(<ComPDFKit_Tools/ComPDFKit_Tools.h>)
  17. #import <ComPDFKit_Tools/ComPDFKit_Tools.h>
  18. #else
  19. #import "ComPDFKit_Tools.h"
  20. #endif
  21. @interface CPDFFreeTextViewController () <UIColorPickerViewControllerDelegate, CPDFThicknessSliderViewDelegate, CPDFFontStyleTableViewDelegate, CPDFColorPickerViewDelegate>
  22. @property (nonatomic, strong) UIButton *boldBtn;
  23. @property (nonatomic, strong) UIButton *italicBtn;
  24. @property (nonatomic, strong) UILabel *alignmentLabel;
  25. @property (nonatomic, strong) UIButton *leftBtn;
  26. @property (nonatomic, strong) UIButton *centerBtn;
  27. @property (nonatomic, strong) UIButton *rightBtn;
  28. @property (nonatomic, strong) CPDFThicknessSliderView *fontsizeSliderView;
  29. @property (nonatomic, assign) BOOL isBold;
  30. @property (nonatomic, assign) BOOL isItalic;
  31. @property (nonatomic, assign) NSString *baseName;
  32. @property (nonatomic, strong) CPDFFontStyleTableView *fontStyleTableView;
  33. @property (nonatomic, strong) UIView * dropMenuView;
  34. @property (nonatomic, strong) UIView * splitView;
  35. @property (nonatomic, strong) UIButton * fontSelectBtn;
  36. @property (nonatomic, strong) UIImageView *dropDownIcon;
  37. @property (nonatomic, strong) UILabel * fontNameLabel;
  38. @property (nonatomic, strong) UILabel * fontNameSelectLabel;
  39. @end
  40. @implementation CPDFFreeTextViewController
  41. #pragma mark - ViewController Methods
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. // Do any additional setup after loading the view.
  45. self.fontNameLabel = [[UILabel alloc] init];
  46. self.fontNameLabel.text = NSLocalizedString(@"Font", nil);
  47. self.fontNameLabel.font = [UIFont systemFontOfSize:14];
  48. self.fontNameLabel.textColor = [UIColor colorWithRed:153./255 green:153./255 blue:153./255 alpha:1.];
  49. [self.scrcollView addSubview:self.fontNameLabel];
  50. self.dropMenuView = [[UIView alloc] init];
  51. [self.scrcollView addSubview:self.dropMenuView];
  52. self.splitView = [[UIView alloc] init];
  53. self.splitView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
  54. [self.dropMenuView addSubview:self.splitView];
  55. self.dropDownIcon = [[UIImageView alloc] init];
  56. self.dropDownIcon.image = [UIImage imageNamed:@"CPDFEditArrow" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
  57. [self.dropMenuView addSubview:self.dropDownIcon];
  58. self.fontNameSelectLabel = [[UILabel alloc] init];
  59. self.fontNameSelectLabel.font = [UIFont systemFontOfSize:14];
  60. self.fontNameSelectLabel.textColor = [UIColor blackColor];
  61. [self.dropMenuView addSubview:self.fontNameSelectLabel];
  62. self.fontSelectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  63. self.fontSelectBtn.backgroundColor = [UIColor clearColor];
  64. [self.fontSelectBtn addTarget:self action:@selector(buttonItemClicked_FontStyle:) forControlEvents:UIControlEventTouchUpInside];
  65. [self.dropMenuView addSubview:self.fontSelectBtn];
  66. self.boldBtn = [[UIButton alloc] init];
  67. [self.boldBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageBold" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  68. [self.boldBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageBoldHighLinght" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateSelected];
  69. [self.boldBtn addTarget:self action:@selector(buttonItemClicked_Bold:) forControlEvents:UIControlEventTouchUpInside];
  70. [self.scrcollView addSubview:self.boldBtn];
  71. self.italicBtn = [[UIButton alloc] init];
  72. [self.italicBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageUnderline" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  73. [self.italicBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageItailcHighLight" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateSelected];
  74. [self.italicBtn addTarget:self action:@selector(buttonItemClicked_Italic:) forControlEvents:UIControlEventTouchUpInside];
  75. [self.scrcollView addSubview:self.italicBtn];
  76. self.alignmentLabel = [[UILabel alloc] init];
  77. self.alignmentLabel.text = NSLocalizedString(@"Alignment", nil);
  78. self.alignmentLabel.textColor = [UIColor grayColor];
  79. self.alignmentLabel.font = [UIFont systemFontOfSize:12.0];
  80. [self.scrcollView addSubview:self.alignmentLabel];
  81. self.leftBtn = [[UIButton alloc] init];
  82. [self.leftBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageLeft" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  83. [self.leftBtn addTarget:self action:@selector(buttonItemClicked_Left:) forControlEvents:UIControlEventTouchUpInside];
  84. [self.scrcollView addSubview:self.leftBtn];
  85. self.centerBtn = [[UIButton alloc] init];
  86. [self.centerBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageCenter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  87. [self.centerBtn addTarget:self action:@selector(buttonItemClicked_Center:) forControlEvents:UIControlEventTouchUpInside];
  88. [self.scrcollView addSubview:self.centerBtn];
  89. self.rightBtn = [[UIButton alloc] init];
  90. [self.rightBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageRight" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  91. [self.rightBtn addTarget:self action:@selector(buttonItemClicked_Right:) forControlEvents:UIControlEventTouchUpInside];
  92. [self.scrcollView addSubview:self.rightBtn];
  93. self.fontsizeSliderView = [[CPDFThicknessSliderView alloc] init];
  94. self.fontsizeSliderView.thicknessSlider.value = 20;
  95. self.fontsizeSliderView.thicknessSlider.minimumValue = 1;
  96. self.fontsizeSliderView.thicknessSlider.maximumValue = 100;
  97. self.fontsizeSliderView.titleLabel.text = NSLocalizedString(@"Font Size", nil);
  98. self.fontsizeSliderView.startLabel.text = @"1";
  99. self.fontsizeSliderView.delegate = self;
  100. self.fontsizeSliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  101. [self.scrcollView addSubview:self.fontsizeSliderView];
  102. self.baseName = @"Helvetica";
  103. self.view.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
  104. }
  105. - (void)viewWillLayoutSubviews {
  106. [super viewWillLayoutSubviews];
  107. self.scrcollView.frame = CGRectMake(0, 170, self.view.frame.size.width, self.view.frame.size.height-170);
  108. self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 470);
  109. if (@available(iOS 11.0, *)) {
  110. self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 50);
  111. self.fontNameLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, 195, 30, 30);
  112. self.dropMenuView.frame = CGRectMake(self.view.safeAreaInsets.left+60, 195, self.view.frame.size.width - 150 - self.view.safeAreaInsets.right-self.view.safeAreaInsets.left, 30);
  113. self.dropDownIcon.frame = CGRectMake(self.dropMenuView.bounds.size.width - 24 - 5, 3, 24, 24);
  114. self.fontNameSelectLabel.frame = CGRectMake(10, 0, self.dropMenuView.bounds.size.width - 40, 29);
  115. self.fontSelectBtn.frame = self.dropMenuView.bounds;
  116. self.splitView.frame = CGRectMake(0, 29, self.dropMenuView.bounds.size.width, 1);
  117. self.boldBtn.frame = CGRectMake(self.view.frame.size.width - 80 - self.view.safeAreaInsets.right, 195, 30, 30);
  118. self.italicBtn.frame = CGRectMake(self.view.frame.size.width - 50 - self.view.safeAreaInsets.right, 195, 30, 30);
  119. self.alignmentLabel.frame = CGRectMake(self.view.safeAreaInsets.left+20, 225, 120, 45);
  120. self.leftBtn.frame = CGRectMake(self.view.frame.size.width - 130 - self.view.safeAreaInsets.right, 240, 30, 30);
  121. self.centerBtn.frame = CGRectMake(self.view.frame.size.width - 90 - self.view.safeAreaInsets.right, 240, 30, 30);
  122. self.rightBtn.frame = CGRectMake(self.view.frame.size.width - 50, 240, 30, 30);
  123. self.fontsizeSliderView.frame = CGRectMake(self.view.safeAreaInsets.left, 280, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
  124. } else {
  125. self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 50);
  126. self.boldBtn.frame = CGRectMake(self.view.frame.size.width - 80, 195, 30, 30);
  127. self.italicBtn.frame = CGRectMake(self.view.frame.size.width - 50, 195, 30, 30);
  128. self.alignmentLabel.frame = CGRectMake(20, 225, 120, 45);
  129. self.leftBtn.frame = CGRectMake(self.view.frame.size.width - 110, 240, 30, 30);
  130. self.centerBtn.frame = CGRectMake(self.view.frame.size.width - 80, 240, 30, 30);
  131. self.rightBtn.frame = CGRectMake(self.view.frame.size.width - 50, 240, 30, 30);
  132. self.fontsizeSliderView.frame = CGRectMake(0, 280, self.view.frame.size.width, 90);
  133. self.fontNameLabel.frame = CGRectMake(20, 195, 30, 30);
  134. self.dropMenuView.frame = CGRectMake(60, 195, self.view.frame.size.width - 140, 30);
  135. self.dropDownIcon.frame = CGRectMake(self.dropMenuView.bounds.size.width - 24 - 5, 3, 24, 24);
  136. self.fontNameSelectLabel.frame = CGRectMake(10, 0, self.dropMenuView.bounds.size.width-40, 29);
  137. self.fontSelectBtn.frame = self.dropMenuView.bounds;
  138. self.splitView.frame = CGRectMake(0, 29, self.dropMenuView.bounds.size.width, 1);
  139. }
  140. }
  141. #pragma mark - Protect Mehtods
  142. - (void)commomInitTitle {
  143. self.titleLabel.text = NSLocalizedString(@"FreeText", nil);
  144. self.colorView.colorLabel.text = NSLocalizedString(@"Font Color", nil);
  145. self.colorView.selectedColor = self.annotStyle.fontColor;
  146. self.sampleView.selecIndex = CPDFSamplesFreeText;
  147. self.sampleView.color = [UIColor blueColor];
  148. }
  149. - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
  150. self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 600);
  151. }
  152. - (void)commomInitFromAnnotStyle {
  153. self.opacitySliderView.opacitySlider.value = self.annotStyle.opacity;
  154. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  155. self.fontsizeSliderView.thicknessSlider.value = self.annotStyle.fontSize;
  156. self.fontsizeSliderView.startLabel.text = [NSString stringWithFormat:@"%d",(int)self.annotStyle.fontSize];
  157. self.fontNameSelectLabel.text = self.annotStyle.fontName;
  158. [self analyzeFont:self.annotStyle.fontName];
  159. [self analyzeAlignment:self.annotStyle.alignment];
  160. self.sampleView.color = self.annotStyle.fontColor;
  161. self.sampleView.opcity = self.annotStyle.opacity;
  162. self.sampleView.thickness = self.annotStyle.fontSize;
  163. self.sampleView.fontName = self.annotStyle.fontName;
  164. self.sampleView.textAlignment = self.annotStyle.alignment;
  165. [self.sampleView setNeedsDisplay];
  166. }
  167. #pragma mark - Private
  168. - (void)analyzeFont:(NSString *)fontName {
  169. if ([fontName rangeOfString:@"Bold"].location != NSNotFound) {
  170. self.isBold = YES;
  171. self.sampleView.isBold = self.isBold;
  172. self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  173. [self.sampleView setNeedsDisplay];
  174. } else {
  175. self.isBold = NO;
  176. self.sampleView.isBold = self.isBold;
  177. self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  178. [self.sampleView setNeedsDisplay];
  179. }
  180. if (([fontName rangeOfString:@"Italic"].location != NSNotFound) || ([fontName rangeOfString:@"Oblique"].location != NSNotFound)) {
  181. self.isItalic = YES;
  182. self.sampleView.isItalic = self.isItalic;
  183. self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  184. [self.sampleView setNeedsDisplay];
  185. } else {
  186. self.isItalic = NO;
  187. self.sampleView.isItalic = self.isBold;
  188. self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  189. [self.sampleView setNeedsDisplay];
  190. }
  191. if ([fontName rangeOfString:@"Helvetica"].location != NSNotFound)
  192. {
  193. self.baseName = @"Helvetica";
  194. self.sampleView.fontName = self.baseName;
  195. return ;
  196. }
  197. if ([fontName rangeOfString:@"Courier"].location != NSNotFound)
  198. {
  199. self.baseName = @"Courier";
  200. self.sampleView.fontName = self.baseName;
  201. return ;
  202. }
  203. if ([fontName rangeOfString:@"Times"].location != NSNotFound)
  204. {
  205. self.baseName = @"Times-Roman";
  206. self.sampleView.fontName = self.baseName;
  207. }
  208. }
  209. - (void)analyzeAlignment:(NSTextAlignment)aligment {
  210. switch (aligment) {
  211. case NSTextAlignmentLeft:
  212. {
  213. self.leftBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  214. }
  215. break;
  216. case NSTextAlignmentCenter:
  217. {
  218. self.centerBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  219. }
  220. break;
  221. case NSTextAlignmentRight:
  222. {
  223. self.rightBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  224. }
  225. break;
  226. default:
  227. break;
  228. }
  229. }
  230. - (NSString *)constructionFontname:(NSString *)baseName isBold:(BOOL)isBold isItalic:(BOOL)isItalic {
  231. NSString *result;
  232. if ([baseName rangeOfString:@"Times"].location != NSNotFound) {
  233. if (isBold || isItalic) {
  234. if (isBold && isItalic) return @"Times-BoldItalic";
  235. if (isBold) return @"Times-Bold";
  236. if (isItalic) return @"Times-Italic";
  237. }
  238. else
  239. return @"Times-Roman";
  240. }
  241. if (isBold || isItalic) {
  242. result = [NSString stringWithFormat:@"%@-",baseName];
  243. if (isBold) result = [NSString stringWithFormat:@"%@Bold",result];
  244. if (isItalic) result = [NSString stringWithFormat:@"%@Oblique",result];
  245. }
  246. else return baseName;
  247. return result;
  248. }
  249. #pragma mark - Action
  250. - (void)buttonItemClicked_Bold:(id)sender {
  251. self.isBold = !(self.isBold);
  252. if (self.isBold) {
  253. self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  254. } else {
  255. self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  256. }
  257. self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
  258. [self.sampleView setNeedsDisplay];
  259. self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
  260. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  261. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  262. }
  263. }
  264. - (void)buttonItemClicked_Italic:(id)sender {
  265. self.isItalic = !(self.isItalic);
  266. if (self.isItalic) {
  267. self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  268. } else {
  269. self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  270. }
  271. self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
  272. self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
  273. [self.sampleView setNeedsDisplay];
  274. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  275. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  276. }
  277. }
  278. - (void)buttonItemClicked_FontStyle:(id)sender {
  279. self.fontStyleTableView = [[CPDFFontStyleTableView alloc] initWithFrame:self.view.bounds];
  280. self.fontStyleTableView.delegate = self;
  281. self.fontStyleTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  282. self.fontStyleTableView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  283. [self.view addSubview:self.fontStyleTableView];
  284. }
  285. - (void)buttonItemClicked_Left:(id)sender {
  286. self.leftBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  287. self.centerBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  288. self.rightBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  289. self.leftBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  290. self.annotStyle.alignment = NSTextAlignmentLeft;
  291. self.sampleView.textAlignment = NSTextAlignmentLeft;
  292. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  293. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  294. }
  295. [self.sampleView setNeedsDisplay];
  296. }
  297. - (void)buttonItemClicked_Center:(id)sender {
  298. self.leftBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  299. self.centerBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  300. self.rightBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  301. self.centerBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  302. self.annotStyle.alignment = NSTextAlignmentCenter;
  303. self.sampleView.textAlignment = NSTextAlignmentCenter;
  304. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  305. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  306. }
  307. [self.sampleView setNeedsDisplay];
  308. }
  309. - (void)buttonItemClicked_Right:(id)sender {
  310. self.leftBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  311. self.centerBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  312. self.rightBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  313. self.rightBtn.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
  314. self.annotStyle.alignment = NSTextAlignmentRight;
  315. self.sampleView.textAlignment = NSTextAlignmentRight;
  316. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  317. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  318. }
  319. [self.sampleView setNeedsDisplay];
  320. }
  321. #pragma mark - CPDFOpacitySliderViewDelegate
  322. - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
  323. self.sampleView.opcity = opacity;
  324. self.annotStyle.opacity = opacity;
  325. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  326. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  327. }
  328. [self.sampleView setNeedsDisplay];
  329. }
  330. #pragma mark - CPDFThicknessSliderViewDelegate
  331. - (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {
  332. self.sampleView.thickness = thickness;
  333. self.annotStyle.fontSize = self.fontsizeSliderView.thicknessSlider.value;
  334. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  335. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  336. }
  337. [self.sampleView setNeedsDisplay];
  338. }
  339. #pragma mark - CPDFFontStyleTableViewDelegate
  340. - (void)fontStyleTableView:(CPDFFontStyleTableView *)fontStyleTableView fontName:(NSString *)fontName {
  341. self.sampleView.fontName = fontName;
  342. self.baseName = fontName;
  343. self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
  344. self.fontNameSelectLabel.text = fontName;
  345. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  346. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  347. }
  348. [self.sampleView setNeedsDisplay];
  349. }
  350. #pragma mark - CPDFColorSelectViewDelegate
  351. - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
  352. self.sampleView.color = color;
  353. self.annotStyle.fontColor = color;
  354. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  355. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  356. }
  357. [self.sampleView setNeedsDisplay];
  358. }
  359. - (void)selectColorView:(CPDFColorSelectView *)select {
  360. if (@available(iOS 14.0, *)) {
  361. UIColorPickerViewController *picker = [[UIColorPickerViewController alloc] init];
  362. picker.delegate = self;
  363. [self presentViewController:picker animated:YES completion:nil];
  364. } else {
  365. self.colorPicker = [[CPDFColorPickerView alloc] initWithFrame:self.view.frame];
  366. self.colorPicker.delegate = self;
  367. self.colorPicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  368. self.colorPicker.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
  369. [self.view addSubview:self.colorPicker];
  370. }
  371. }
  372. #pragma mark - CPDFColorPickerViewDelegate
  373. - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
  374. self.sampleView.color = color;
  375. self.annotStyle.fontColor = color;
  376. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  377. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  378. }
  379. [self.sampleView setNeedsDisplay];
  380. CGFloat red, green, blue, alpha;
  381. [color getRed:&red green:&green blue:&blue alpha:&alpha];
  382. self.opacitySliderView.opacitySlider.value = alpha;
  383. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  384. }
  385. #pragma mark - UIColorPickerViewControllerDelegate
  386. - (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)) {
  387. self.sampleView.color = viewController.selectedColor;
  388. self.annotStyle.fontColor = self.sampleView.color;
  389. if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
  390. [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
  391. }
  392. [self.sampleView setNeedsDisplay];
  393. CGFloat red, green, blue, alpha;
  394. [viewController.selectedColor getRed:&red green:&green blue:&blue alpha:&alpha];
  395. self.opacitySliderView.opacitySlider.value = alpha;
  396. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  397. }
  398. @end