|
@@ -7,13 +7,12 @@
|
|
|
|
|
|
#import "CPDFTextViewController.h"
|
|
|
#import "CPDFTextView.h"
|
|
|
-#import "CPDFTextPreview.h"
|
|
|
#import "CPDFDataModel.h"
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
-@interface CPDFTextViewController () <CPDFTextPreviewDelegate>
|
|
|
+@interface CPDFTextViewController ()
|
|
|
|
|
|
-@property (nonatomic,assign) CGContextRef context;
|
|
|
+@property (nonatomic,strong) CPDFDrawView *drawView;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -107,8 +106,8 @@
|
|
|
|
|
|
- (void)onTextScaleChanged:(UISlider *)sender {
|
|
|
if (!_dataModel.isTile) {
|
|
|
- sender.minimumValue = 24;
|
|
|
- sender.maximumValue = 48;
|
|
|
+ sender.minimumValue = 12;
|
|
|
+ sender.maximumValue = 36;
|
|
|
_textPreview.watermarkLabel.font = [_textPreview.watermarkLabel.font fontWithSize:sender.value];
|
|
|
[_textPreview.watermarkLabel sizeToFit];
|
|
|
[_dataModel setWatermarkScale:sender.value / 24];
|
|
@@ -117,16 +116,22 @@
|
|
|
|
|
|
- (void)onTileSwitchChanged:(UISwitch *) sender {
|
|
|
if ([sender isOn]) {
|
|
|
- [self drawMytext:self.context];
|
|
|
_dataModel.isTile = YES;
|
|
|
_textView.horizontalField.enabled = YES;
|
|
|
_textView.verticalField.enabled = YES;
|
|
|
_textView.textScaleSlider.enabled = NO;
|
|
|
+
|
|
|
+ _drawView = [[CPDFDrawView alloc] initWithFrame:self.textPreview.bounds];
|
|
|
+ _drawView.delegate = self;
|
|
|
+ [self.view addSubview:_drawView];
|
|
|
+ [self.textPreview bringSubviewToFront:_drawView];
|
|
|
+
|
|
|
} else {
|
|
|
_dataModel.isTile = NO;
|
|
|
_textView.horizontalField.enabled = NO;
|
|
|
_textView.verticalField.enabled = NO;
|
|
|
_textView.textScaleSlider.enabled = YES;
|
|
|
+ [_drawView removeFromSuperview];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -163,32 +168,6 @@
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
-- (void)drawMytext:(CGContextRef)context {
|
|
|
- CGContextSetFillColorWithColor(context, self.textPreview.watermarkLabel.textColor.CGColor);
|
|
|
-
|
|
|
- UIFont *font = [UIFont systemFontOfSize:self.textView.textScaleSlider.value];
|
|
|
- NSDictionary *dic = @{NSFontAttributeName:font,NSForegroundColorAttributeName:self.textPreview.watermarkLabel.textColor};
|
|
|
-
|
|
|
- NSInteger wx,wy,height,width;
|
|
|
- wx = self.textPreview.watermarkLabel.frame.origin.x;
|
|
|
- wy = self.textPreview.watermarkLabel.frame.origin.y;
|
|
|
- height = self.textPreview.watermarkLabel.frame.size.height;
|
|
|
- width = self.textPreview.watermarkLabel.frame.size.width;
|
|
|
-
|
|
|
- NSInteger x,y,a,b;
|
|
|
- x = wx / width + (self.textPreview.frame.size.width - (wx + width)) / width + 1;
|
|
|
- y = wy / height + (self.textPreview.frame.size.height - (wy + height)) / height + 1;
|
|
|
-
|
|
|
- a = wx % width;
|
|
|
- b = wy % height;
|
|
|
-
|
|
|
- for (NSInteger i = 0; i < x; i++) {
|
|
|
- for (NSInteger j = 0; j < y; j++) {
|
|
|
-
|
|
|
- [@"watermark" drawInRect:CGRectMake(a + i * (width + 50), b + j * (height + 50), width, height) withAttributes:dic];
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
#pragma mark - Gesture
|
|
|
|
|
@@ -278,7 +257,39 @@
|
|
|
#pragma mark - CPDFTextPreviewDelegate
|
|
|
|
|
|
- (void)drawText:(CGContextRef)context {
|
|
|
- _context = context;
|
|
|
+ CGContextSetFillColorWithColor(context, self.textPreview.watermarkLabel.textColor.CGColor);
|
|
|
+ CGContextSaveGState(context);
|
|
|
+
|
|
|
+ CGContextClipToRect(context, self.textPreview.documentView.frame);
|
|
|
+
|
|
|
+ UIFont *font = [UIFont systemFontOfSize:self.textView.textScaleSlider.value];
|
|
|
+ NSDictionary *dic = @{NSFontAttributeName:font,NSForegroundColorAttributeName:self.textPreview.watermarkLabel.textColor};
|
|
|
+
|
|
|
+ self.drawView.transform = CGAffineTransformMakeRotation((self.dataModel.watermarkRotation * M_PI) / 180);
|
|
|
+
|
|
|
+ NSInteger wx,wy,height,width;
|
|
|
+ wx = self.textPreview.watermarkLabel.frame.origin.x + self.textPreview.documentView.frame.origin.x;
|
|
|
+ wy = self.textPreview.watermarkLabel.frame.origin.y + self.textPreview.documentView.frame.origin.y;
|
|
|
+ height = self.textPreview.watermarkLabel.frame.size.height + 10;
|
|
|
+ width = self.textPreview.watermarkLabel.frame.size.width + 10;
|
|
|
+
|
|
|
+ NSInteger x,y,a,b;
|
|
|
+ x = wx / width + (self.textPreview.frame.size.width - (wx + width)) / width + 1;
|
|
|
+ y = wy / height + (self.textPreview.frame.size.height - (wy + height)) / height + 1;
|
|
|
+
|
|
|
+ a = wx % width;
|
|
|
+ b = wy % height;
|
|
|
+
|
|
|
+ for (NSInteger i = 0; i < x; i++) {
|
|
|
+ for (NSInteger j = 0; j < y; j++) {
|
|
|
+ [@"watermark" drawInRect:CGRectMake(a + i * width, b + j * height, width - 10, height - 10) withAttributes:dic];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CGContextRestoreGState(context);
|
|
|
+
|
|
|
+ //self.drawView.transform = CGAffineTransformMakeRotation((self.dataModel.watermarkRotation * M_PI) / 180);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@end
|