Browse Source

PDFView(ios) - 水印12/27

yangliuhua 2 years ago
parent
commit
2ada589050

+ 7 - 1
PDFViewer.xcodeproj/project.pbxproj

@@ -12,6 +12,7 @@
 		C96384932949E2020055CCCA /* ComPDFKit.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C96384922949E2020055CCCA /* ComPDFKit.xcframework */; };
 		C9638496294ACC240055CCCA /* CPDFAddViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9638495294ACC240055CCCA /* CPDFAddViewController.m */; };
 		C96D13932924793800CC92C7 /* btn_more.png in Resources */ = {isa = PBXBuildFile; fileRef = C96D13922924793800CC92C7 /* btn_more.png */; };
+		C97E91682959B96C007F6943 /* CPDFEditView.m in Sources */ = {isa = PBXBuildFile; fileRef = C97E91672959B96C007F6943 /* CPDFEditView.m */; };
 		EC62978E29220F8300D339EE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EC62978D29220F8300D339EE /* AppDelegate.m */; };
 		EC62979129220F8300D339EE /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EC62979029220F8300D339EE /* SceneDelegate.m */; };
 		EC62979429220F8300D339EE /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EC62979329220F8300D339EE /* ViewController.m */; };
@@ -64,6 +65,8 @@
 		C9638494294ACC240055CCCA /* CPDFAddViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFAddViewController.h; sourceTree = "<group>"; };
 		C9638495294ACC240055CCCA /* CPDFAddViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFAddViewController.m; sourceTree = "<group>"; };
 		C96D13922924793800CC92C7 /* btn_more.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = btn_more.png; sourceTree = "<group>"; };
+		C97E91662959B96C007F6943 /* CPDFEditView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFEditView.h; sourceTree = "<group>"; };
+		C97E91672959B96C007F6943 /* CPDFEditView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFEditView.m; sourceTree = "<group>"; };
 		EC62978929220F8300D339EE /* PDFViewer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PDFViewer.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		EC62978C29220F8300D339EE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
 		EC62978D29220F8300D339EE /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -217,10 +220,10 @@
 			children = (
 				ECD0AC1E2928EF030091B6EB /* sources */,
 				ECD0ABEB2928ED9A0091B6EB /* CPDFImagePreview.h */,
-				ECD0ABEC2928ED9A0091B6EB /* CPDFImagePreview.m */,
 				ECD0ABED2928ED9A0091B6EB /* CPDFImageView.h */,
 				ECD0ABE82928ED990091B6EB /* CPDFImageView.m */,
 				ECD0ABEF2928ED9A0091B6EB /* CPDFTextPreview.h */,
+				ECD0ABEC2928ED9A0091B6EB /* CPDFImagePreview.m */,
 				ECD0ABE52928ED990091B6EB /* CPDFTextPreview.m */,
 				ECD0ABE92928ED990091B6EB /* CPDFTextView.h */,
 				ECD0ABEA2928ED990091B6EB /* CPDFTextView.m */,
@@ -228,6 +231,8 @@
 				C96150D1295400B00020F445 /* CPDFDrawView.m */,
 				C96150D329554F660020F445 /* CPDFClipView.h */,
 				C96150D429554F660020F445 /* CPDFClipView.m */,
+				C97E91662959B96C007F6943 /* CPDFEditView.h */,
+				C97E91672959B96C007F6943 /* CPDFEditView.m */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -347,6 +352,7 @@
 				ECC8831D2923352B00F6392E /* CPDFViewController.m in Sources */,
 				EC62979429220F8300D339EE /* ViewController.m in Sources */,
 				ECD0AC172928EECB0091B6EB /* MASConstraint.m in Sources */,
+				C97E91682959B96C007F6943 /* CPDFEditView.m in Sources */,
 				C96150D2295400B00020F445 /* CPDFDrawView.m in Sources */,
 				EC6297B8292239A700D339EE /* CPDFModel.m in Sources */,
 				ECD0AC232928F2A70091B6EB /* CPDFTextViewController.m in Sources */,

+ 3 - 1
PDFViewer/Controller/CPDFAddViewController.h

@@ -6,6 +6,7 @@
 //  Alter cause : code standards
 
 #import <UIKit/UIKit.h>
+#import <ComPDFKit/ComPDFKit.h>
 #import "CPDFDataModel.h"
 #import "CPDFTextViewController.h"
 #import "CPDFImageViewController.h"
@@ -25,8 +26,9 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) id<WaterMarkModelDataDelegate> delegate;
 @property (nonatomic,strong) CPDFTextViewController *textViewController;
 @property (nonatomic,strong) CPDFImageViewController *imageViewController;
+@property (nonatomic,strong) CPDFDocument *document;
 
-- (instancetype)initWithImage:(UIImage *)image;
+- (instancetype)initWithImage:(UIImage *)image withDocument:(CPDFDocument *)document;
 
 @end
 

+ 97 - 12
PDFViewer/Controller/CPDFAddViewController.m

@@ -7,44 +7,55 @@
 
 #import "CPDFAddViewController.h"
 #import <ComPDFKit/ComPDFKit.h>
+#import <ComPDFKit/CPDFWatermark.h>
 #import "CPDFViewController.h"
 #import "CPDFTextView.h"
 #import "CPDFTextPreview.h"
 #import "CPDFImageView.h"
 #import "CPDFImagePreview.h"
 #import "CPDFDataModel.h"
+#import "CPDFEditView.h"
 #import "Masonry.h"
 
-@interface CPDFAddViewController ()
+@interface CPDFAddViewController () <UITableViewDelegate,UITableViewDataSource>
 
 @property (nonatomic,assign) CGSize imageSize;
-@property (nonatomic,strong) CPDFView *pdfView;
 @property (nonatomic,strong) UIImage *image;
 @property (nonatomic,strong) CPDFDataModel *dataModel;
+@property (nonatomic,strong) CPDFEditView *editView;
+@property (nonatomic,strong) NSMutableArray *dataArray;
 
 @end
 
 @implementation CPDFAddViewController
 
-- (instancetype)initWithImage:(UIImage *)image {
-    self = [super init];
-    if (self) {
-        _image = image;
-        _imageSize = image.size;
-    }
-    return self;
-}
-
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    
     UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedDoneBtn)];
-    self.navigationItem.rightBarButtonItem = doneBtn;
+    
+    UIBarButtonItem *editBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editClick)];
+    UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick)];
+    
+    self.navigationItem.rightBarButtonItems = @[doneBtn,editBtn,cancelBtn];
     
     [self createView];
     [self addConstraint];
 }
 
+#pragma mark - Initializers
+
+- (instancetype)initWithImage:(UIImage *)image withDocument:(CPDFDocument *)document{
+    self = [super init];
+    if (self) {
+        _image = image;
+        _imageSize = image.size;
+        _document = document;
+    }
+    return self;
+}
+
 - (void)createView {
     NSArray *segmentArray = @[@"Text",@"Image"];
     _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentArray];
@@ -65,6 +76,12 @@
     [self.view addSubview:_textViewController.view];
     [self.view addSubview:_imageViewController.view];
     
+    _editView = [[CPDFEditView alloc] init];
+    _editView.editTableView.dataSource = self;
+    _editView.editTableView.delegate = self;
+    
+    [self.view addSubview:_editView];
+    
     _textViewController.textPreview.documentView.image = self.image;
     _imageViewController.imagePreview.documentView.image = self.image;
     _imageViewController.view.hidden = YES;
@@ -161,6 +178,51 @@
     }
 }
 
+#pragma mark - Accessors
+
+- (NSArray *)dataArray {
+    if (!_dataArray) {
+        _dataArray = [NSMutableArray array];
+        
+        CPDFWatermark *dataWater = [[CPDFWatermark alloc] init];
+        
+        NSArray *waterArray = [_document watermarks];
+        
+        for (NSInteger i = 0; i < waterArray.count; i++) {
+            CPDFDataModel *dataModel = [[CPDFDataModel alloc] init];
+            dataWater = waterArray[i];
+            dataModel.text = dataWater.text;
+            dataModel.textColor = dataWater.textColor;
+            dataModel.watermarkScale = dataWater.scale;
+            dataModel.watermarkOpacity = dataWater.opacity;
+            dataModel.watermarkRotation = dataWater.rotation;
+            
+            [_dataArray addObject:dataModel];
+        }
+    }
+    
+    return _dataArray;
+}
+
+#pragma mark - UITableViewDataSource
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+    return self.dataArray.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+    static NSString *path = @"AddWater";
+    
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:path];
+    
+    if (!cell) {
+        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:path];
+    }
+    
+    cell.textLabel.text = [self.dataArray[indexPath.row] text];
+    return cell;
+}
+
 #pragma mark - Actons
 
 - (void)onClickedDoneBtn {
@@ -195,6 +257,29 @@
     }
 }
 
+- (void)editClick {
+    if (self.editView.center.x < 50) {
+        [_editView mas_makeConstraints:^(MASConstraintMaker *make) {
+            make.left.equalTo(self.view.mas_left);
+            make.top.equalTo(self.textViewController.textPreview.mas_top);
+            make.bottom.equalTo(self.textViewController.textPreview.mas_bottom);
+            make.width.mas_equalTo(150);
+        }];
+        
+        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
+            self.editView.center = CGPointMake(self.editView.center.x + 150, self.editView.center.y);
+        } completion:nil];
+    }
+}
+
+- (void)cancelClick {
+    if (self.editView.center.x > 0) {
+        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
+            self.editView.center = CGPointMake(self.editView.center.x - 150, self.editView.center.y);
+        } completion:nil];
+    }
+}
+
 #pragma mark - Orientation
 
 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {

+ 10 - 66
PDFViewer/Controller/CPDFImageViewController.m

@@ -13,14 +13,12 @@
 #import "CPDFClipView.h"
 #import "Masonry.h"
 
-@interface CPDFImageViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate,CPDFTextPreviewDelegate,CPDFClipTextPreviewDelegate,UITextFieldDelegate>
+@interface CPDFImageViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate,CPDFClipTextPreviewDelegate,UITextFieldDelegate>
 
 @property (nonatomic,assign) CGRect watermarkFrame;
 
 @property (nonatomic,strong) CPDFDrawView *drawView;
 @property (nonatomic,strong) CPDFClipView *cliView;
-@property (nonatomic,assign) CGFloat vertical;
-@property (nonatomic,assign) CGFloat horizontal;
 
 @end
 
@@ -40,14 +38,10 @@
     [self.view addSubview:_imageView];
     [self.view setBackgroundColor:UIColor.systemGray5Color];
     
-    _horizontal = 100;
-    _vertical = 100;
-    
     [self initDataModel];
     [self addConstraint];
     [self addTargets];
     [self createGestureRecognizer];
-
 }
 
 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
@@ -246,7 +240,11 @@
         _imageView.imageScaleSlider.enabled = NO;
         
         _drawView = [[CPDFDrawView alloc] initWithFrame:self.imagePreview.bounds];
-        _drawView.delegate = self;
+        
+        [_drawView setDataModel:self.dataModel];
+        [_drawView setWaterLabelRect:self.imagePreview.watermarkView.frame];
+        [_drawView setDocumentViewRect:self.imagePreview.documentView.frame];
+        
         [self.view addSubview:_drawView];
         [self.imagePreview bringSubviewToFront:_drawView];
         
@@ -267,37 +265,13 @@
 }
 
 - (void)horizontalChange:(UITextField *)text {
-    _horizontal = [text.text floatValue];
-    
-    [_drawView removeFromSuperview];
-    [_cliView removeFromSuperview];
-    
-    _drawView = [[CPDFDrawView alloc] initWithFrame:self.imagePreview.bounds];
-    _drawView.delegate = self;
-    [self.view addSubview:_drawView];
-    [self.imagePreview bringSubviewToFront:_drawView];
-    
-    _cliView = [[CPDFClipView alloc] initWithFrame:self.imagePreview.bounds];
-    _cliView.delegate = self;
-    [self.view addSubview:_cliView];
-    [self.drawView bringSubviewToFront:_cliView];
+    [_drawView setHorizontal:[text.text floatValue]];
+    [_drawView setNeedsDisplay];
 }
 
 - (void)verticalChage:(UITextField *)text {
-    _vertical = [text.text floatValue];
-    
-    [_drawView removeFromSuperview];
-    [_cliView removeFromSuperview];
-    
-    _drawView = [[CPDFDrawView alloc] initWithFrame:self.imagePreview.bounds];
-    _drawView.delegate = self;
-    [self.view addSubview:_drawView];
-    [self.imagePreview bringSubviewToFront:_drawView];
-    
-    _cliView = [[CPDFClipView alloc] initWithFrame:self.imagePreview.bounds];
-    _cliView.delegate = self;
-    [self.view addSubview:_cliView];
-    [self.drawView bringSubviewToFront:_cliView];
+    [_drawView setVertical:[text.text floatValue]];
+    [_drawView setNeedsDisplay];
 }
 
 
@@ -327,36 +301,6 @@
     return newImage;
 }
 
-#pragma mark - CPDFTextPreviewDelegate
-
-- (void)drawText:(CGContextRef)context {
-    
-    CGContextSaveGState(context);
-    
-    UIImage *image = self.imagePreview.watermarkView.image;
-    
-    self.drawView.transform = CGAffineTransformMakeRotation((self.dataModel.watermarkRotation * M_PI) / 180);
-    
-    NSInteger wx,wy,height,width;
-    wx = self.imagePreview.watermarkView.frame.origin.x + self.imagePreview.documentView.frame.origin.x;
-    wy = self.imagePreview.watermarkView.frame.origin.y + self.imagePreview.documentView.frame.origin.y;
-    height = self.imagePreview.watermarkView.frame.size.height + _vertical / 10;
-    width = self.imagePreview.watermarkView.frame.size.width + _horizontal / 10;
-
-    NSInteger x,y,a,b;
-    x = wx / width + (self.imagePreview.frame.size.width - (wx + width)) / width + 1;
-    y = wy / height + (self.imagePreview.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++) {
-            [image drawInRect:CGRectMake(a + i * width, b + j * height, width - _horizontal / 10, height - _vertical / 10)];
-        }
-    }
-}
-
 #pragma mark - CPDFClipTextPreviewDelegate
 
 - (void)clipText:(CGContextRef)context {

+ 11 - 67
PDFViewer/Controller/CPDFTextViewController.m

@@ -12,12 +12,10 @@
 #import "CPDFClipView.h"
 #import "Masonry.h"
 
-@interface CPDFTextViewController () <CPDFTextPreviewDelegate,CPDFClipTextPreviewDelegate,UITextFieldDelegate>
+@interface CPDFTextViewController () <CPDFClipTextPreviewDelegate,UITextFieldDelegate>
 
 @property (nonatomic,strong) CPDFDrawView *drawView;
 @property (nonatomic,strong) CPDFClipView *cliView;
-@property (nonatomic,assign) CGFloat vertical;
-@property (nonatomic,assign) CGFloat horizontal;
 
 @end
 
@@ -40,9 +38,6 @@
     [self.view addSubview:_textView];
     [self.view setBackgroundColor:UIColor.systemGray5Color];
     
-    _horizontal = 100;
-    _vertical = 100;
-    
     [self addConstraint];
     [self initDataModel];
     [self addTargets];
@@ -80,7 +75,6 @@
 }
 
 - (void)addTargets {
-    
     for (NSInteger i = 0; i < _textView.colorArray.count; ++i) {
         [_textView.colorArray[i] addTarget:self action:@selector(onColorBtnClicked:) forControlEvents:UIControlEventTouchDown];
     }
@@ -139,7 +133,11 @@
         _textView.textScaleSlider.enabled = NO;
         
         _drawView = [[CPDFDrawView alloc] initWithFrame:self.textPreview.bounds];
-        _drawView.delegate = self;
+        
+        [_drawView setDataModel:self.dataModel];
+        [_drawView setWaterLabelRect:self.textPreview.watermarkLabel.frame];
+        [_drawView setDocumentViewRect:self.textPreview.documentView.frame];
+        
         [self.view addSubview:_drawView];
         [self.textPreview bringSubviewToFront:_drawView];
         
@@ -153,6 +151,7 @@
         _textView.horizontalField.enabled = NO;
         _textView.verticalField.enabled = NO;
         _textView.textScaleSlider.enabled = YES;
+        
         [_drawView removeFromSuperview];
         [_cliView removeFromSuperview];
     }
@@ -192,37 +191,13 @@
 }
 
 - (void)horizontalChange:(UITextField *)text {
-    _horizontal = [text.text floatValue];
-    
-    [_drawView removeFromSuperview];
-    [_cliView removeFromSuperview];
-    
-    _drawView = [[CPDFDrawView alloc] initWithFrame:self.textPreview.bounds];
-    _drawView.delegate = self;
-    [self.view addSubview:_drawView];
-    [self.textPreview bringSubviewToFront:_drawView];
-    
-    _cliView = [[CPDFClipView alloc] initWithFrame:self.textPreview.bounds];
-    _cliView.delegate = self;
-    [self.view addSubview:_cliView];
-    [self.drawView bringSubviewToFront:_cliView];
+    [_drawView setHorizontal:[text.text floatValue]];
+    [_drawView setNeedsDisplay];
 }
 
 - (void)verticalChage:(UITextField *)text {
-    _vertical = [text.text floatValue];
-    
-    [_drawView removeFromSuperview];
-    [_cliView removeFromSuperview];
-    
-    _drawView = [[CPDFDrawView alloc] initWithFrame:self.textPreview.bounds];
-    _drawView.delegate = self;
-    [self.view addSubview:_drawView];
-    [self.textPreview bringSubviewToFront:_drawView];
-    
-    _cliView = [[CPDFClipView alloc] initWithFrame:self.textPreview.bounds];
-    _cliView.delegate = self;
-    [self.view addSubview:_cliView];
-    [self.drawView bringSubviewToFront:_cliView];
+    [_drawView setVertical:[text.text floatValue]];
+    [_drawView setNeedsDisplay];
 }
 
 #pragma mark - Gesture
@@ -310,37 +285,6 @@
     }
 }
 
-#pragma mark - CPDFTextPreviewDelegate
-
-- (void)drawText:(CGContextRef)context {
-    CGContextSetFillColorWithColor(context, self.textPreview.watermarkLabel.textColor.CGColor);
-    CGContextSaveGState(context);
-    
-    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 + _vertical / 10;
-    width = self.textPreview.watermarkLabel.frame.size.width + _horizontal / 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 - _horizontal / 10, height - _vertical / 10) withAttributes:dic];
-        }
-    }
-}
-
 #pragma mark - CPDFClipTextPreviewDelegate
 
 - (void)clipText:(CGContextRef)context {

+ 1 - 1
PDFViewer/Controller/CPDFViewController.m

@@ -67,7 +67,7 @@
 - (void)onClickedOkbtn {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-        self.addWaterMarkViewController = [[CPDFAddViewController alloc] initWithImage:self.image];
+        self.addWaterMarkViewController = [[CPDFAddViewController alloc] initWithImage:self.image withDocument:self.pdfDocument];
         self.addWaterMarkViewController.delegate = self;
         
         [self.navigationController pushViewController:self.addWaterMarkViewController animated:YES];

+ 6 - 9
PDFViewer/View/CPDFDrawView.h

@@ -6,20 +6,17 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "CPDFDataModel.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
-@protocol CPDFTextPreviewDelegate <NSObject>
-
-@required
-
-- (void)drawText:(CGContextRef)context;
-
-@end
-
 @interface CPDFDrawView : UIView
 
-@property (nonatomic,strong) id<CPDFTextPreviewDelegate> delegate;
+@property (nonatomic,strong) CPDFDataModel *dataModel;
+@property (nonatomic,assign) CGRect waterLabelRect;
+@property (nonatomic,assign) CGRect documentViewRect;
+@property (nonatomic,assign) CGFloat vertical;
+@property (nonatomic,assign) CGFloat horizontal;
 
 @end
 

+ 73 - 1
PDFViewer/View/CPDFDrawView.m

@@ -14,6 +14,11 @@
     
     if (self) {
         self.backgroundColor = [UIColor clearColor];
+        
+        _dataModel = [[CPDFDataModel alloc] init];
+        
+        _horizontal = 100;
+        _vertical = 100;
     }
     
     return self;
@@ -23,8 +28,75 @@
     [super drawRect:rect];
     
     CGContextRef context = UIGraphicsGetCurrentContext();
+
+    if (self.dataModel.text) {
+        [self drawText:context];
+    } else if (self.dataModel.image) {
+        [self drawImage:context];
+    }
+    
+}
+
+- (void)drawText:(CGContextRef)context {
+    CGContextSetFillColorWithColor(context, self.dataModel.textColor.CGColor);
+    CGContextSaveGState(context);
+    
+    CGContextSetAlpha(context, self.dataModel.watermarkOpacity);
     
-    [self.delegate drawText:context];
+    UIFont *font = [UIFont systemFontOfSize:24 * self.dataModel.watermarkScale];
+    NSDictionary *dic = @{NSFontAttributeName:font,NSForegroundColorAttributeName:self.dataModel.textColor};
+    
+    NSInteger wx,wy,height,width;
+    wx = self.waterLabelRect.origin.x + self.documentViewRect.origin.x;
+    wy = self.waterLabelRect.origin.y + self.documentViewRect.origin.y;
+    height = self.waterLabelRect.size.height + _vertical / 10;
+    width = self.waterLabelRect.size.width + _horizontal / 10;
+
+    NSInteger x,y,a,b;
+    x = self.frame.size.width / width;
+    y = self.frame.size.height / height;
+
+    a = wx % width;
+    b = wy % height;
+    
+    CGFloat ctm = (self.dataModel.watermarkRotation * M_PI) / 180;
+    CGContextRotateCTM(context, ctm);
+    CGContextTranslateCTM(context, ctm * 250, 0);
+
+    for (NSInteger i = 0; i < x; i++) {
+        for (NSInteger j = 0; j < y; j++) {
+            [self.dataModel.text drawInRect:CGRectMake(a + i * width, b + j * height, width - _horizontal / 10, height - _vertical / 10) withAttributes:dic];
+        }
+    }
+}
+
+- (void)drawImage:(CGContextRef)context {
+    CGContextSaveGState(context);
+    
+    CGContextSetAlpha(context, self.dataModel.watermarkOpacity);
+    
+    NSInteger wx,wy,height,width;
+    wx = self.waterLabelRect.origin.x + self.documentViewRect.origin.x;
+    wy = self.waterLabelRect.origin.y + self.documentViewRect.origin.y;
+    height = self.waterLabelRect.size.height + _vertical / 10;
+    width = self.waterLabelRect.size.width + _horizontal / 10;
+
+    NSInteger x,y,a,b;
+    x = self.frame.size.width / width;
+    y = self.frame.size.height / height;
+
+    a = wx % width;
+    b = wy % height;
+    
+    CGFloat ctm = (self.dataModel.watermarkRotation * M_PI) / 180;
+    CGContextRotateCTM(context, ctm);
+    CGContextTranslateCTM(context, ctm * 250, 0);
+
+    for (NSInteger i = 0; i < x; i++) {
+        for (NSInteger j = 0; j < y; j++) {
+            [self.dataModel.image drawInRect:CGRectMake(a + i * width, b + j * height, width - _horizontal / 10, height - _vertical / 10)];
+        }
+    }
 }
 
 @end

+ 18 - 0
PDFViewer/View/CPDFEditView.h

@@ -0,0 +1,18 @@
+//
+//  CPDFEditView.h
+//  PDFViewer
+//
+//  Created by kdanmobile_2 on 2022/12/26.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CPDFEditView : UIView
+ 
+@property (nonatomic,strong) UITableView *editTableView;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 28 - 0
PDFViewer/View/CPDFEditView.m

@@ -0,0 +1,28 @@
+//
+//  CPDFEditView.m
+//  PDFViewer
+//
+//  Created by kdanmobile_2 on 2022/12/26.
+//
+
+#import "CPDFEditView.h"
+
+@implementation CPDFEditView
+
+- (instancetype)initWithFrame:(CGRect)frame {
+    self = [super initWithFrame:frame];
+    
+    if (self) {
+        _editTableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
+        _editTableView.rowHeight = 50;
+        _editTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+        _editTableView.tableFooterView = [[UIView alloc] init];
+        
+        [self addSubview:_editTableView];
+        
+        self.backgroundColor = [UIColor systemGray6Color];
+    }
+    return self;
+}
+
+@end