|
@@ -8,54 +8,18 @@
|
|
|
// Please see License for details. This notice may not be removed from this file.
|
|
|
//
|
|
|
|
|
|
-#import "PDFListView+Event.h"
|
|
|
-#import <objc/runtime.h>
|
|
|
+#import "CPDFListView+Edit.h"
|
|
|
+#import "CPDFListView+Private.h"
|
|
|
|
|
|
-
|
|
|
-static NSString *pointKey = @"pointKey";
|
|
|
-static NSString *pageKey = @"pageKey";
|
|
|
-
|
|
|
-
|
|
|
-@implementation PDFListView (Event)
|
|
|
-
|
|
|
-- (void)setMPage:(CPDFPage *)mPage{
|
|
|
- NSValue *value = [NSValue value:&mPage withObjCType:@encode(CGPoint)];
|
|
|
- objc_setAssociatedObject(self,&pageKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
-}
|
|
|
-
|
|
|
-- (CPDFPage *)mPage{
|
|
|
- NSValue *value = objc_getAssociatedObject(self, &pageKey);
|
|
|
- if(value) {
|
|
|
- CPDFPage *page;
|
|
|
- [value getValue:&page];
|
|
|
- return page;
|
|
|
- }else {
|
|
|
- return nil;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)setMPoint:(CGPoint)mPoint{
|
|
|
- NSValue *value = [NSValue value:&mPoint withObjCType:@encode(CGPoint)];
|
|
|
- objc_setAssociatedObject(self,&pointKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
-}
|
|
|
-
|
|
|
-- (CGPoint)mPoint{
|
|
|
- NSValue *value = objc_getAssociatedObject(self, &pointKey);
|
|
|
- if(value) {
|
|
|
- CGPoint point;
|
|
|
- [value getValue:&point];
|
|
|
- return point;
|
|
|
- }else {
|
|
|
- return CGPointZero;
|
|
|
- }
|
|
|
-}
|
|
|
+@implementation CPDFListView (Edit)
|
|
|
|
|
|
|
|
|
- (NSArray<UIMenuItem *> *)menuItemsEditingAtPoint:(CGPoint)point forPage:(CPDFPage *)page{
|
|
|
+
|
|
|
NSArray *menuItem = [super menuItemsEditingAtPoint:point forPage:page];
|
|
|
|
|
|
- self.mPoint= point;
|
|
|
- self.mPage = page;
|
|
|
+ self.menuPoint = point;
|
|
|
+ self.menuPage = page;
|
|
|
|
|
|
NSMutableArray *menuItems =[NSMutableArray array];
|
|
|
if (menuItem) {
|
|
@@ -68,56 +32,82 @@ static NSString *pageKey = @"pageKey";
|
|
|
}
|
|
|
|
|
|
if(self.editStatus == CEditingSelectStateEmpty){
|
|
|
- UIMenuItem *addTextItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Text", nil)
|
|
|
- action:@selector(addTextEditingItemAction:)] autorelease];
|
|
|
- UIMenuItem *addImageItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Image", nil)
|
|
|
- action:@selector(addImageEditingItemAction:)] autorelease];
|
|
|
+ UIMenuItem *addTextItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Text", nil)
|
|
|
+ action:@selector(addTextEditingItemAction:)];
|
|
|
+ UIMenuItem *addImageItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Image", nil)
|
|
|
+ action:@selector(addImageEditingItemAction:)];
|
|
|
[menuItems addObject:addImageItem];
|
|
|
[menuItems addObject:addTextItem];
|
|
|
}
|
|
|
|
|
|
if(isCropMode){
|
|
|
- UIMenuItem * doneItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) action:@selector(doneActionClick:)] autorelease];
|
|
|
- UIMenuItem * cancelItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Cancel", nil) action:@selector(cancelActionClick:)] autorelease];
|
|
|
+ UIMenuItem * doneItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) action:@selector(doneActionClick:)];
|
|
|
+ UIMenuItem * cancelItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Cancel", nil) action:@selector(cancelActionClick:)];
|
|
|
|
|
|
[menuItems addObject:doneItem];
|
|
|
[menuItems addObject:cancelItem];
|
|
|
}else{
|
|
|
if(self.editingArea){
|
|
|
if (self.editingArea.IsImageArea) {
|
|
|
- UIMenuItem * cropItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Crop", nil) action:@selector(enterCropActionClick:)] autorelease];
|
|
|
- UIMenuItem * rotateItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Rotate", nil) action:@selector(rotateActionClick:)] autorelease];
|
|
|
- UIMenuItem * hMirrorItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"HMirror", nil) action:@selector(horizontalMirrorClick:)] autorelease];
|
|
|
- UIMenuItem * vMirrorItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"VMirror", nil) action:@selector(verticalMirrorClick:)] autorelease];
|
|
|
- UIMenuItem * rPlaceItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Replace", nil) action:@selector(replaceActionClick:)] autorelease];
|
|
|
|
|
|
- UIMenuItem * extractItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Extract", nil) action:@selector(extractActionClick:)] autorelease];
|
|
|
+ UIMenuItem * leftRotateItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Left Rotate", nil) action:@selector(leftRotateCropActionClick:)];
|
|
|
|
|
|
- UIMenuItem * opacityItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Opacity", nil) action:@selector(opacityEditingItemAction:)] autorelease];
|
|
|
+ UIMenuItem * rightRotateItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Right Rotate", nil) action:@selector(leftRotateCropActionClick:)];
|
|
|
|
|
|
- [menuItems addObject:cropItem];
|
|
|
+ UIMenuItem * rPlaceItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Replace", nil) action:@selector(replaceActionClick:)];
|
|
|
+
|
|
|
+ UIMenuItem * cropItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Crop", nil) action:@selector(enterCropActionClick:)];
|
|
|
+
|
|
|
+ UIMenuItem * opacityItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Opacity", nil) action:@selector(opacityEditingItemAction:)];
|
|
|
+
|
|
|
+ UIMenuItem * rotateItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Rotate", nil) action:@selector(rotateActionClick:)];
|
|
|
+ UIMenuItem * hMirrorItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"HMirror", nil) action:@selector(horizontalMirrorClick:)];
|
|
|
+ UIMenuItem * vMirrorItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"VMirror", nil) action:@selector(verticalMirrorClick:)];
|
|
|
+
|
|
|
+ UIMenuItem * extractItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Extract", nil) action:@selector(extractActionClick:)];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [menuItems addObject:leftRotateItem];
|
|
|
+ [menuItems addObject:rightRotateItem];
|
|
|
+ [menuItems addObject:rPlaceItem];
|
|
|
[menuItems addObject:rotateItem];
|
|
|
+ [menuItems addObject:cropItem];
|
|
|
+ [menuItems addObject:opacityItem];
|
|
|
+
|
|
|
[menuItems addObject:hMirrorItem];
|
|
|
[menuItems addObject:vMirrorItem];
|
|
|
- [menuItems addObject:rPlaceItem];
|
|
|
[menuItems addObject:extractItem];
|
|
|
- [menuItems addObject:opacityItem];
|
|
|
}else{
|
|
|
- UIMenuItem * opacityItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Opacity", nil) action:@selector(opacityEditingItemAction:)] autorelease];
|
|
|
+
|
|
|
+ UIMenuItem * propertyItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Property", nil) action:@selector(propertyEditingItemAction:)];
|
|
|
+
|
|
|
+ UIMenuItem * opacityItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Opacity", nil) action:@selector(opacityEditingItemAction:)];
|
|
|
+
|
|
|
+ [menuItems addObject:propertyItem];
|
|
|
[menuItems addObject:opacityItem];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ if([self.performDelegate respondsToSelector:@selector(PDFListView:customizeMenuForPage:forPagePoint:)])
|
|
|
+ return [self.performDelegate PDFListView:self customizeMenuForPage:page forPagePoint:point];
|
|
|
return menuItems;
|
|
|
}
|
|
|
|
|
|
+- (void)leftRotateCropActionClick:(UIMenuItem*)menuItem {
|
|
|
+ [self rotateEditArea:self.editingArea rotateAngle:-90];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)rightRotateCropActionClick:(UIMenuItem*)menuItem {
|
|
|
+ [self rotateEditArea:self.editingArea rotateAngle:90];
|
|
|
+}
|
|
|
+
|
|
|
- (void)addTextEditingItemAction:(UIMenuItem*)menuItem{
|
|
|
- CPDFPage *page = self.mPage;
|
|
|
- NSMutableParagraphStyle *style = [[[NSMutableParagraphStyle alloc] init] autorelease];
|
|
|
+ CPDFPage *page = self.menuPage;
|
|
|
+ NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
|
|
|
[style setAlignment:NSTextAlignmentCenter];
|
|
|
- CGRect rect = CGRectMake(self.mPoint.x, self.mPoint.y, 60.0, 20);
|
|
|
+ CGRect rect = CGRectMake(self.menuPoint.x, self.menuPoint.y, 60.0, 20);
|
|
|
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
[dic setValue:style forKey:NSParagraphStyleAttributeName];
|
|
@@ -128,7 +118,6 @@ static NSString *pageKey = @"pageKey";
|
|
|
}
|
|
|
- (void)addImageEditingItemAction:(UIMenuItem*)menuItem{
|
|
|
|
|
|
-// [self setShouAddEditAreaType:CAddEditingAreaTypeImage];
|
|
|
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
|
|
|
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
imagePicker.delegate = self;
|
|
@@ -137,12 +126,12 @@ static NSString *pageKey = @"pageKey";
|
|
|
|
|
|
- (void)doneActionClick:(UIMenuItem*)menuItem{
|
|
|
CPDFEditImageArea * editArea = (CPDFEditImageArea *)self.editingArea;
|
|
|
- [self cropEditImageArea:editArea withBounds:editArea.cropRect];
|
|
|
- [self exitCropWithEditImageArea:editArea];
|
|
|
+ [self cropEditArea:self.editingArea WithRect:editArea.cropRect];
|
|
|
+ [self endCropEditArea:self.editingArea];
|
|
|
}
|
|
|
|
|
|
- (void)cancelActionClick:(UIMenuItem*)menuItem{
|
|
|
- [self exitCropWithEditImageArea:(CPDFEditImageArea *)self.editingArea];
|
|
|
+ [self endCropEditArea:self.editingArea];
|
|
|
}
|
|
|
|
|
|
- (void)deleteActionClick:(UIMenuItem*)menuItem{
|
|
@@ -156,16 +145,22 @@ static NSString *pageKey = @"pageKey";
|
|
|
[self.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
+- (void)propertyEditingItemAction:(UIMenuItem*)menuItem {
|
|
|
+ if(self.performDelegate && [self.performDelegate respondsToSelector:@selector(PDFViewCustomMenuClick:identifier:)]){
|
|
|
+ [self.performDelegate PDFViewCustomMenuClick:self identifier:@"PropertyItem"];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
- (void)opacityEditingItemAction:(UIMenuItem*)menuItem{
|
|
|
NSMutableArray *menuItems = [NSMutableArray array];
|
|
|
- UIMenuItem *opacity25Item = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"25%", nil)
|
|
|
- action:@selector(opacity25ItemAction:)] autorelease];
|
|
|
- UIMenuItem *opacity50Item = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"50%", nil)
|
|
|
- action:@selector(opacity50ItemAction:)] autorelease];
|
|
|
- UIMenuItem *opacity75Item = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"75%", nil)
|
|
|
- action:@selector(opacity75ItemAction:)] autorelease];
|
|
|
- UIMenuItem *opacity100Item = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"100%", nil)
|
|
|
- action:@selector(opacity100ItemAction:)] autorelease];
|
|
|
+ UIMenuItem *opacity25Item = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"25%", nil)
|
|
|
+ action:@selector(opacity25ItemAction:)];
|
|
|
+ UIMenuItem *opacity50Item = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"50%", nil)
|
|
|
+ action:@selector(opacity50ItemAction:)];
|
|
|
+ UIMenuItem *opacity75Item = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"75%", nil)
|
|
|
+ action:@selector(opacity75ItemAction:)];
|
|
|
+ UIMenuItem *opacity100Item = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"100%", nil)
|
|
|
+ action:@selector(opacity100ItemAction:)];
|
|
|
[menuItems addObject:opacity25Item];
|
|
|
[menuItems addObject:opacity50Item];
|
|
|
[menuItems addObject:opacity75Item];
|
|
@@ -182,19 +177,19 @@ static NSString *pageKey = @"pageKey";
|
|
|
}
|
|
|
|
|
|
- (void)opacity25ItemAction:(id)sender {
|
|
|
- [self setOpacityEditArea:self.editingArea opacity:0.25];
|
|
|
+ [self setCharsFontTransparency:0.25];
|
|
|
}
|
|
|
|
|
|
- (void)opacity50ItemAction:(id)sender {
|
|
|
- [self setOpacityEditArea:self.editingArea opacity:0.5];
|
|
|
+ [self setCharsFontTransparency:0.5];
|
|
|
}
|
|
|
|
|
|
- (void)opacity75ItemAction:(id)sender {
|
|
|
- [self setOpacityEditArea:self.editingArea opacity:0.75];
|
|
|
+ [self setCharsFontTransparency:0.75];
|
|
|
}
|
|
|
|
|
|
- (void)opacity100ItemAction:(id)sender {
|
|
|
- [self setOpacityEditArea:self.editingArea opacity:1.0];
|
|
|
+ [self setCharsFontTransparency:1.0];
|
|
|
}
|
|
|
|
|
|
#pragma mark - imagePickerDelegate
|
|
@@ -229,8 +224,8 @@ static NSString *pageKey = @"pageKey";
|
|
|
scaled_height = img_height*scaled;
|
|
|
scaled_width = img_width*scaled;
|
|
|
|
|
|
- CGRect rect = CGRectMake(self.mPoint.x, self.mPoint.y, scaled_width, scaled_height);
|
|
|
- [self createEmptyImage:rect page:self.mPage path:url.path];
|
|
|
+ CGRect rect = CGRectMake(self.menuPoint.x, self.menuPoint.y, scaled_width, scaled_height);
|
|
|
+ [self createEmptyImage:rect page:self.menuPage path:url.path];
|
|
|
}else{
|
|
|
[self replaceEditImageArea:(CPDFEditImageArea *)self.editingArea imagePath:url.path];
|
|
|
}
|
|
@@ -259,8 +254,8 @@ static NSString *pageKey = @"pageKey";
|
|
|
}
|
|
|
scaled_height = scaled_width*img_height/img_width;
|
|
|
|
|
|
- CGRect rect = CGRectMake(self.mPoint.x, self.mPoint.y, scaled_width, scaled_height);
|
|
|
- [self createEmptyImage:rect page:self.mPage path:url.path];
|
|
|
+ CGRect rect = CGRectMake(self.menuPoint.x, self.menuPoint.y, scaled_width, scaled_height);
|
|
|
+ [self createEmptyImage:rect page:self.menuPage path:url.path];
|
|
|
}else{
|
|
|
[self replaceEditImageArea:(CPDFEditImageArea *)self.editingArea imagePath:url.path];
|
|
|
}
|
|
@@ -277,19 +272,16 @@ static NSString *pageKey = @"pageKey";
|
|
|
}
|
|
|
|
|
|
- (void)horizontalMirrorClick:(UIMenuItem*)menuItem{
|
|
|
- [self horizontalMirrorWithEditImageArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
+ [self horizontalMirrorEditArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
}
|
|
|
|
|
|
- (void)verticalMirrorClick:(UIMenuItem*)menuItem{
|
|
|
- [self verticalMirrorWithEditImageArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
+ [self verticalMirrorEditArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
}
|
|
|
|
|
|
-- (void)rotateActionClick:(UIMenuItem*)menuItem{
|
|
|
- [self rotateWithEditImageArea:(CPDFEditImageArea*)self.editingArea rotate:90];
|
|
|
-}
|
|
|
|
|
|
- (void)enterCropActionClick:(UIMenuItem*)menuItem{
|
|
|
- [self enterCropWithEditImageArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
+ [self beginCropEditArea:(CPDFEditImageArea*)self.editingArea];
|
|
|
}
|
|
|
|
|
|
@end
|