|
@@ -35,7 +35,9 @@
|
|
|
|
|
|
@property (nonatomic, assign) BOOL isBold;
|
|
|
|
|
|
-@property (nonatomic, assign) BOOL isUnderline;
|
|
|
+@property (nonatomic, assign) BOOL isItalic;
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSString *baseName;
|
|
|
|
|
|
@property (nonatomic, strong) CPDFFontStyleTableView *fontStyleTableView;
|
|
|
|
|
@@ -52,37 +54,37 @@
|
|
|
[self.fontStyleBtn setTitle:NSLocalizedString(@"Font Style", nil) forState:UIControlStateNormal];
|
|
|
[self.fontStyleBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
|
|
|
[self.fontStyleBtn addTarget:self action:@selector(buttonItemClicked_FontStyle:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.fontStyleBtn];
|
|
|
+ [self.scrcollView addSubview:self.fontStyleBtn];
|
|
|
|
|
|
self.boldBtn = [[UIButton alloc] init];
|
|
|
[self.boldBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageBold" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
[self.boldBtn addTarget:self action:@selector(buttonItemClicked_Bold:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.boldBtn];
|
|
|
+ [self.scrcollView addSubview:self.boldBtn];
|
|
|
|
|
|
self.underlineBtn = [[UIButton alloc] init];
|
|
|
[self.underlineBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageUnderline" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
- [self.underlineBtn addTarget:self action:@selector(buttonItemClicked_Underline:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.underlineBtn];
|
|
|
+ [self.underlineBtn addTarget:self action:@selector(buttonItemClicked_Italic:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self.scrcollView addSubview:self.underlineBtn];
|
|
|
|
|
|
self.alignmentLabel = [[UILabel alloc] init];
|
|
|
self.alignmentLabel.text = NSLocalizedString(@"Alignment Mode", nil);
|
|
|
self.alignmentLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
- [self.view addSubview:self.alignmentLabel];
|
|
|
+ [self.scrcollView addSubview:self.alignmentLabel];
|
|
|
|
|
|
self.leftBtn = [[UIButton alloc] init];
|
|
|
[self.leftBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageLeft" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
[self.leftBtn addTarget:self action:@selector(buttonItemClicked_Left:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.leftBtn];
|
|
|
+ [self.scrcollView addSubview:self.leftBtn];
|
|
|
|
|
|
self.centerBtn = [[UIButton alloc] init];
|
|
|
[self.centerBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageCenter" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
[self.centerBtn addTarget:self action:@selector(buttonItemClicked_Center:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.centerBtn];
|
|
|
+ [self.scrcollView addSubview:self.centerBtn];
|
|
|
|
|
|
self.rightBtn = [[UIButton alloc] init];
|
|
|
[self.rightBtn setImage:[UIImage imageNamed:@"CPDFFreeTextImageRight" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
|
|
|
[self.rightBtn addTarget:self action:@selector(buttonItemClicked_Right:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [self.view addSubview:self.rightBtn];
|
|
|
+ [self.scrcollView addSubview:self.rightBtn];
|
|
|
|
|
|
self.fontsizeSliderView = [[CPDFThicknessSliderView alloc] init];
|
|
|
self.fontsizeSliderView.thicknessSlider.value = 20;
|
|
@@ -90,25 +92,39 @@
|
|
|
self.fontsizeSliderView.thicknessSlider.maximumValue = 100;
|
|
|
self.fontsizeSliderView.titleLabel.text = NSLocalizedString(@"Font Size", nil);
|
|
|
self.fontsizeSliderView.startLabel.text = @"1";
|
|
|
- self.fontsizeSliderView.endLabel.text = @"100";
|
|
|
self.fontsizeSliderView.delegate = self;
|
|
|
self.fontsizeSliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
|
|
- [self.view addSubview:self.fontsizeSliderView];
|
|
|
+ [self.scrcollView addSubview:self.fontsizeSliderView];
|
|
|
|
|
|
self.isBold = NO;
|
|
|
- self.isUnderline = NO;
|
|
|
+ self.isItalic = NO;
|
|
|
+ self.baseName = @"Helvetica";
|
|
|
}
|
|
|
|
|
|
- (void)viewWillLayoutSubviews {
|
|
|
[super viewWillLayoutSubviews];
|
|
|
- self.fontStyleBtn.frame = CGRectMake(10, 370, 180, 45);
|
|
|
- self.boldBtn.frame = CGRectMake(self.view.frame.size.width - 80, 385, 30, 30);
|
|
|
- self.underlineBtn.frame = CGRectMake(self.view.frame.size.width - 40, 385, 30, 30);
|
|
|
- self.alignmentLabel.frame = CGRectMake(10, 415, 120, 45);
|
|
|
- self.leftBtn.frame = CGRectMake(self.view.frame.size.width - 120, 430, 30, 30);
|
|
|
- self.centerBtn.frame = CGRectMake(self.view.frame.size.width - 80, 430, 30, 30);
|
|
|
- self.rightBtn.frame = CGRectMake(self.view.frame.size.width - 40, 430, 30, 30);
|
|
|
- self.fontsizeSliderView.frame = CGRectMake(10, 450, self.view.frame.size.width - 20, 90);
|
|
|
+ self.scrcollView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50);
|
|
|
+ self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 600);
|
|
|
+
|
|
|
+ if (@available(iOS 11.0, *)) {
|
|
|
+ self.fontStyleBtn.frame = CGRectMake(self.view.safeAreaInsets.left, 300, 180, 45);
|
|
|
+ self.boldBtn.frame = CGRectMake(self.view.frame.size.width - 80 - self.view.safeAreaInsets.right, 315, 30, 30);
|
|
|
+ self.underlineBtn.frame = CGRectMake(self.view.frame.size.width - 40 - self.view.safeAreaInsets.right, 315, 30, 30);
|
|
|
+ self.alignmentLabel.frame = CGRectMake(self.view.safeAreaInsets.left, 345, 120, 45);
|
|
|
+ self.leftBtn.frame = CGRectMake(self.view.frame.size.width - 120 - self.view.safeAreaInsets.right, 360, 30, 30);
|
|
|
+ self.centerBtn.frame = CGRectMake(self.view.frame.size.width - 80 - self.view.safeAreaInsets.right, 360, 30, 30);
|
|
|
+ self.rightBtn.frame = CGRectMake(self.view.frame.size.width - 40, 360, 30, 30);
|
|
|
+ self.fontsizeSliderView.frame = CGRectMake(self.view.safeAreaInsets.left, 400, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, 90);
|
|
|
+ } else {
|
|
|
+ self.fontStyleBtn.frame = CGRectMake(10, 300, 180, 45);
|
|
|
+ self.boldBtn.frame = CGRectMake(self.view.frame.size.width - 80, 315, 30, 30);
|
|
|
+ self.underlineBtn.frame = CGRectMake(self.view.frame.size.width - 40, 315, 30, 30);
|
|
|
+ self.alignmentLabel.frame = CGRectMake(10, 345, 120, 45);
|
|
|
+ self.leftBtn.frame = CGRectMake(self.view.frame.size.width - 120, 360, 30, 30);
|
|
|
+ self.centerBtn.frame = CGRectMake(self.view.frame.size.width - 80, 360, 30, 30);
|
|
|
+ self.rightBtn.frame = CGRectMake(self.view.frame.size.width - 40, 360, 30, 30);
|
|
|
+ self.fontsizeSliderView.frame = CGRectMake(10, 480, self.view.frame.size.width - 20, 90);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma mark - Protect Mehtods
|
|
@@ -116,13 +132,70 @@
|
|
|
- (void)commomInitTitle {
|
|
|
self.titleLabel.text = NSLocalizedString(@"Free Text", nil);
|
|
|
self.sampleView.selecIndex = CPDFSamplesFreeText;
|
|
|
- self.sampleView.fontName = @"Helvetica";
|
|
|
self.sampleView.fillColor = [UIColor blueColor];
|
|
|
- self.sampleView.thickness = 20;
|
|
|
}
|
|
|
|
|
|
- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
|
|
|
- self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 270 : 600);
|
|
|
+ self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 600);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)commomInitFromAnnotStyle {
|
|
|
+ self.sampleView.fillColor = self.annotStyle.color;
|
|
|
+ self.sampleView.opcity = self.annotStyle.opacity;
|
|
|
+ self.sampleView.thickness = self.annotStyle.fontSize;
|
|
|
+ self.fontsizeSliderView.thicknessSlider.value = self.annotStyle.fontSize;
|
|
|
+ [self analyzeFont:self.annotStyle.fontName];
|
|
|
+ [self.sampleView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Private
|
|
|
+
|
|
|
+- (void)analyzeFont:(NSString *)fontName {
|
|
|
+ if ([fontName rangeOfString:@"Bold"].location != NSNotFound) {
|
|
|
+ self.isBold = YES;
|
|
|
+ self.sampleView.isBold = self.isBold;
|
|
|
+ }
|
|
|
+ if ([fontName rangeOfString:@"Italic"].location != NSNotFound) {
|
|
|
+ self.isItalic = YES;
|
|
|
+ self.sampleView.isItalic = self.isItalic;
|
|
|
+ }
|
|
|
+ if ([fontName rangeOfString:@"Helvetica"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ self.baseName = @"Helvetica";
|
|
|
+ self.sampleView.fontName = self.baseName;
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if ([fontName rangeOfString:@"Courier"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ self.baseName = @"Courier";
|
|
|
+ self.sampleView.fontName = self.baseName;
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if ([fontName rangeOfString:@"Times"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ self.baseName = @"Times-Roman";
|
|
|
+ self.sampleView.fontName = self.baseName;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (NSString *)constructionFontname:(NSString *)baseName isBold:(BOOL)isBold isItalic:(BOOL)isItalic {
|
|
|
+ NSString *result;
|
|
|
+ if ([baseName rangeOfString:@"Times"].location != NSNotFound) {
|
|
|
+ if (isBold || isItalic) {
|
|
|
+ if (isBold && isItalic) return @"Times-BoldItalic";
|
|
|
+ if (isBold) return @"Times-Bold";
|
|
|
+ if (isItalic) return @"Times-Italic";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return @"Times-Roman";
|
|
|
+ }
|
|
|
+ if (isBold || isItalic) {
|
|
|
+ result = [NSString stringWithFormat:@"%@-",baseName];
|
|
|
+ if (isBold) result = [NSString stringWithFormat:@"%@Bold",result];
|
|
|
+ if (isItalic) result = [NSString stringWithFormat:@"%@Oblique",result];
|
|
|
+ }
|
|
|
+ else return baseName;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
#pragma mark - Action
|
|
@@ -131,12 +204,21 @@
|
|
|
self.isBold = !(self.isBold);
|
|
|
self.sampleView.isBold = self.isBold;
|
|
|
[self.sampleView setNeedsDisplay];
|
|
|
+ self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-- (void)buttonItemClicked_Underline:(id)sender {
|
|
|
- self.isUnderline = !(self.isUnderline);
|
|
|
- self.sampleView.isUnderline = self.isUnderline;
|
|
|
+- (void)buttonItemClicked_Italic:(id)sender {
|
|
|
+ self.isItalic = !(self.isItalic);
|
|
|
+ self.sampleView.isItalic = self.isItalic;
|
|
|
[self.sampleView setNeedsDisplay];
|
|
|
+ self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
|
|
|
+
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_FontStyle:(id)sender {
|
|
@@ -144,24 +226,40 @@
|
|
|
self.fontStyleTableView.delegate = self;
|
|
|
self.fontStyleTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
[self.view addSubview:self.fontStyleTableView];
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_Left:(id)sender {
|
|
|
-
|
|
|
+ self.annotStyle.alignment = NSTextAlignmentLeft;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_Center:(id)sender {
|
|
|
-
|
|
|
+ self.annotStyle.alignment = NSTextAlignmentCenter;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_Right:(id)sender {
|
|
|
-
|
|
|
+ self.annotStyle.alignment = NSTextAlignmentRight;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma mark - CPDFThicknessSliderViewDelegate
|
|
|
|
|
|
- (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {
|
|
|
self.sampleView.thickness = thickness;
|
|
|
+ self.annotStyle.fontSize = self.fontsizeSliderView.thicknessSlider.value;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
[self.sampleView setNeedsDisplay];
|
|
|
}
|
|
|
|
|
@@ -169,6 +267,33 @@
|
|
|
|
|
|
- (void)fontStyleTableView:(CPDFFontStyleTableView *)fontStyleTableView fontName:(NSString *)fontName {
|
|
|
self.sampleView.fontName = fontName;
|
|
|
+ self.baseName = fontName;
|
|
|
+ self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
+ [self.sampleView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - CPDFColorSelectViewDelegate
|
|
|
+
|
|
|
+- (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
|
|
|
+ self.sampleView.fillColor = color;
|
|
|
+ self.annotStyle.color = color;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
+ [self.sampleView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - CPDFColorPickerViewDelegate
|
|
|
+
|
|
|
+- (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
|
|
|
+ self.sampleView.fillColor = color;
|
|
|
+ self.annotStyle.color = color;
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
|
|
|
+ [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
|
|
|
+ }
|
|
|
[self.sampleView setNeedsDisplay];
|
|
|
}
|
|
|
|