|
@@ -16,15 +16,15 @@
|
|
|
#import "CPDFSlider.h"
|
|
|
#import "CPDFPageIndicatorView.h"
|
|
|
|
|
|
-typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
- PDFAnnotationDraggingNone = 0,
|
|
|
- PDFAnnotationDraggingCenter,
|
|
|
- PDFAnnotationDraggingTopLeft,
|
|
|
- PDFAnnotationDraggingTopRight,
|
|
|
- PDFAnnotationDraggingBottomLeft,
|
|
|
- PDFAnnotationDraggingBottomRight,
|
|
|
- PDFAnnotationDraggingStart,
|
|
|
- PDFAnnotationDraggingEnd
|
|
|
+typedef NS_ENUM(NSInteger, CPDFAnnotationDraggingType) {
|
|
|
+ CPDFAnnotationDraggingNone = 0,
|
|
|
+ CPDFAnnotationDraggingCenter,
|
|
|
+ CPDFAnnotationDraggingTopLeft,
|
|
|
+ CPDFAnnotationDraggingTopRight,
|
|
|
+ CPDFAnnotationDraggingBottomLeft,
|
|
|
+ CPDFAnnotationDraggingBottomRight,
|
|
|
+ CPDFAnnotationDraggingStart,
|
|
|
+ CPDFAnnotationDraggingEnd
|
|
|
};
|
|
|
|
|
|
@interface CPDFListView()
|
|
@@ -33,7 +33,7 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
@property (nonatomic, strong) CPDFPageIndicatorView * pageIndicatorView;
|
|
|
|
|
|
-@property (nonatomic, assign) PDFAnnotationDraggingType draggingType;
|
|
|
+@property (nonatomic, assign) CPDFAnnotationDraggingType draggingType;
|
|
|
|
|
|
@property (nonatomic, assign) CGPoint draggingPoint;
|
|
|
|
|
@@ -81,6 +81,74 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
return self;
|
|
|
}
|
|
|
|
|
|
+- (void)setAnnotationMode:(CPDFViewAnnotationMode)annotationMode {
|
|
|
+ _annotationMode = annotationMode;
|
|
|
+
|
|
|
+ if (CPDFViewAnnotationModeHighlight == annotationMode ||
|
|
|
+ CPDFViewAnnotationModeUnderline == annotationMode ||
|
|
|
+ CPDFViewAnnotationModeStrikeout == annotationMode ||
|
|
|
+ CPDFViewAnnotationModeSquiggly == annotationMode) {
|
|
|
+ self.textSelectionMode = YES;
|
|
|
+ } else {
|
|
|
+ self.textSelectionMode = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CPDFViewAnnotationModeLink == annotationMode) {
|
|
|
+ self.scrollEnabled = NO;
|
|
|
+ [self endDrawing];
|
|
|
+ } else if (CPDFViewAnnotationModeInk == annotationMode) {
|
|
|
+ self.scrollEnabled = NO;
|
|
|
+ [self beginDrawing];
|
|
|
+ } else {
|
|
|
+ if (self.activeAnnotation) {
|
|
|
+ self.scrollEnabled = NO;
|
|
|
+ } else {
|
|
|
+ self.scrollEnabled = YES;
|
|
|
+ }
|
|
|
+ [self endDrawing];
|
|
|
+ [self becomeFirstResponder];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CPDFViewAnnotationModeNone != annotationMode) {
|
|
|
+ CPDFPage *page = self.activeAnnotation.page;
|
|
|
+ self.activeAnnotation = nil;
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateScrollEnabled {
|
|
|
+ if (self.activeAnnotation) {
|
|
|
+ self.scrollEnabled = NO;
|
|
|
+ } else {
|
|
|
+ if (CPDFViewAnnotationModeLink == self.annotationMode) {
|
|
|
+ self.scrollEnabled = NO;
|
|
|
+ } else {
|
|
|
+ self.scrollEnabled = YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (NSString *)annotationUserName {
|
|
|
+ NSString *annotationUserName = CPDFKitShareConfig.annotationAuthor;
|
|
|
+ if (!annotationUserName || [annotationUserName length] <= 0) {
|
|
|
+ annotationUserName = [[UIDevice currentDevice] name];
|
|
|
+ }
|
|
|
+ return annotationUserName ? : @"";
|
|
|
+}
|
|
|
+
|
|
|
+- (UIImage *)compressImage:(UIImage *)image size:(CGSize)size {
|
|
|
+ CGFloat imageScale = 1.0;
|
|
|
+ if (image.size.width > size.width || image.size.height > size.height) {
|
|
|
+ imageScale = MIN(size.width / image.size.width, size.height / image.size.height);
|
|
|
+ }
|
|
|
+ CGSize newSize = CGSizeMake(image.size.width * imageScale, image.size.height * imageScale);
|
|
|
+ UIGraphicsBeginImageContext(newSize);
|
|
|
+ [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
|
|
|
+ UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
+ UIGraphicsEndImageContext();
|
|
|
+ return newImage;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Touch
|
|
|
|
|
|
- (void)touchBeganAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
@@ -92,6 +160,45 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
} else {
|
|
|
}
|
|
|
+
|
|
|
+ if (self.textSelectionMode) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ self.addLinkPoint = point;
|
|
|
+ self.addLinkRect = CGRectZero;
|
|
|
+
|
|
|
+ self.draggingType = CPDFAnnotationDraggingNone;
|
|
|
+ if (!self.activeAnnotation || self.activeAnnotation.page != page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CGRect topLeftRect = CGRectInset(self.topLeftRect, -5, -5);
|
|
|
+ CGRect bottomLeftRect = CGRectInset(self.bottomLeftRect, -5, -5);
|
|
|
+ CGRect topRightRect = CGRectInset(self.topRightRect, -5, -5);
|
|
|
+ CGRect bottomRightRect = CGRectInset(self.bottomRightRect, -5, -5);
|
|
|
+ CGRect startPointRect = CGRectInset(self.startPointRect, -5, -5);
|
|
|
+ CGRect endPointRect = CGRectInset(self.endPointRect, -5, -5);
|
|
|
+ if (CGRectContainsPoint(topLeftRect, point)) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingBottomLeft;
|
|
|
+ } else if (CGRectContainsPoint(topRightRect, point)) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingTopRight;
|
|
|
+ } else if (CGRectContainsPoint(bottomRightRect, point)) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingBottomRight;
|
|
|
+ } else if (CGRectContainsPoint(startPointRect, point)) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingStart;
|
|
|
+ } else if (CGRectContainsPoint(endPointRect, point)) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingEnd;
|
|
|
+ } else if ([page annotation:self.activeAnnotation atPoint:point]) {
|
|
|
+ self.draggingType = CPDFAnnotationDraggingCenter;
|
|
|
+ }
|
|
|
+ self.draggingPoint = point;
|
|
|
+
|
|
|
+ if (CPDFAnnotationDraggingCenter == self.draggingType) {
|
|
|
+ if ([self.activeAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]] ||
|
|
|
+ [self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
|
|
|
+// [self addMagnifierAtPoint:point forPage:page];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)touchMovedAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
@@ -103,6 +210,39 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
} else {
|
|
|
}
|
|
|
+
|
|
|
+ if (self.textSelectionMode) {
|
|
|
+
|
|
|
+ } else if (CPDFAnnotationDraggingNone != self.draggingType) {
|
|
|
+ [self moveAnnotation:self.activeAnnotation fromPoint:self.draggingPoint toPoint:point forType:self.draggingType];
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ self.draggingPoint = point;
|
|
|
+
|
|
|
+ if (CPDFAnnotationDraggingCenter == self.draggingType) {
|
|
|
+ if ([self.activeAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]] ||
|
|
|
+ [self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
|
|
|
+// [self addMagnifierAtPoint:point forPage:page];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (CPDFViewAnnotationModeLink == self.annotationMode) {
|
|
|
+ CGRect rect = CGRectZero;
|
|
|
+ if (point.x > self.addLinkPoint.x) {
|
|
|
+ rect.origin.x = self.addLinkPoint.x;
|
|
|
+ rect.size.width = point.x-self.addLinkPoint.x;
|
|
|
+ } else {
|
|
|
+ rect.origin.x = point.x;
|
|
|
+ rect.size.width = self.addLinkPoint.x-point.x;
|
|
|
+ }
|
|
|
+ if (point.y > self.addLinkPoint.y) {
|
|
|
+ rect.origin.y = self.addLinkPoint.y;
|
|
|
+ rect.size.height = point.y-self.addLinkPoint.y;
|
|
|
+ } else {
|
|
|
+ rect.origin.y = point.y;
|
|
|
+ rect.size.height = self.addLinkPoint.y-point.y;
|
|
|
+ }
|
|
|
+ self.addLinkRect = rect;
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)touchEndedAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
@@ -114,6 +254,109 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
} else {
|
|
|
}
|
|
|
+ if (self.textSelectionMode) {
|
|
|
+ if (self.currentSelection) {
|
|
|
+ [self addAnnotation:self.annotationMode atPoint:point forPage:page];
|
|
|
+ } else {
|
|
|
+ CPDFAnnotation *annotation = [page annotationAtPoint:point];
|
|
|
+ if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (CPDFAnnotationDraggingNone == self.draggingType) {
|
|
|
+ if (self.activeAnnotation) {
|
|
|
+ CPDFPage *previousPage = self.activeAnnotation.page;
|
|
|
+ self.activeAnnotation = nil;
|
|
|
+ [self setNeedsDisplayForPage:previousPage];
|
|
|
+ [self updateScrollEnabled];
|
|
|
+ } else {
|
|
|
+ if (CPDFViewAnnotationModeNone == self.annotationMode) {
|
|
|
+ CPDFAnnotation *annotation = [page annotationAtPoint:point];
|
|
|
+ if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
|
|
|
+ if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformOpenNote:forAnnotation:)]) {
|
|
|
+ [self.performDelegate PDFViewPerformOpenNote:self forAnnotation:annotation];
|
|
|
+ }
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
|
|
|
+// if (CGRectContainsPoint(annotation.bounds, point)) {
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+// } else {
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformPopup:forAnnotation:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformPopup:self forAnnotation:(CPDFMarkupAnnotation *)annotation];
|
|
|
+// }
|
|
|
+// }
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
|
|
|
+ [super touchEndedAtPoint:point forPage:page];
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFMovieAnnotation class]]) {
|
|
|
+ [super touchEndedAtPoint:point forPage:page];
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
|
|
|
+ if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
|
|
|
+// if ([(CPDFSignatureWidgetAnnotation *)annotation isSigned]) {
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+// } else {
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformSignatureWidget:forAnnotation:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformSignatureWidget:self forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation];
|
|
|
+// }
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ [super touchEndedAtPoint:point forPage:page];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.activeAnnotation = annotation;
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ [self updateScrollEnabled];
|
|
|
+
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+//
|
|
|
+// if (!self.activeAnnotation) {
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformTouchEnded:self];
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ } else if (CPDFViewAnnotationModeLink == self.annotationMode) {
|
|
|
+// if (CGRectIsEmpty(self.addLinkRect)) {
|
|
|
+// CPDFAnnotation *annotation = [page annotationAtPoint:point];
|
|
|
+// if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
|
|
|
+// self.activeAnnotation = annotation;
|
|
|
+// [self setNeedsDisplayForPage:page];
|
|
|
+// [self updateScrollEnabled];
|
|
|
+//
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// [self addAnnotationLinkAtPoint:point forPage:page];
|
|
|
+// }
|
|
|
+ } else if (CPDFViewAnnotationModeFreeText == self.annotationMode) {
|
|
|
+// [self addAnnotationFreeTextAtPoint:point forPage:page];
|
|
|
+ } else if (CPDFViewAnnotationModeStamp == self.annotationMode) {
|
|
|
+// [self addAnnotationAtPoint:point forPage:page];
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformTouchEnded:self];
|
|
|
+// }
|
|
|
+ } else if (CPDFViewAnnotationModeImage == self.annotationMode) {
|
|
|
+// [self addAnnotationAtPoint:point forPage:page];
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformTouchEnded:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformTouchEnded:self];
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ [self addAnnotation:self.annotationMode atPoint:point forPage:page];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (CPDFAnnotationDraggingCenter != self.draggingType) {
|
|
|
+ if ([self.activeAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]] ||
|
|
|
+ [self.activeAnnotation isKindOfClass:[CPDFStampAnnotation class]] ||
|
|
|
+ [self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
|
|
|
+ [self.activeAnnotation updateAppearanceStream];
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.draggingType = CPDFAnnotationDraggingNone;
|
|
|
+
|
|
|
+// [self showMenuForAnnotation:self.activeAnnotation];
|
|
|
+ }
|
|
|
+// [self removeMagnifier];
|
|
|
}
|
|
|
|
|
|
- (void)touchCancelledAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
@@ -125,6 +368,8 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
} else {
|
|
|
}
|
|
|
+
|
|
|
+ self.draggingType = CPDFAnnotationDraggingNone;
|
|
|
}
|
|
|
|
|
|
- (NSArray<UIMenuItem *> *)menuItemsAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
@@ -175,7 +420,7 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
|
|
|
}];
|
|
|
|
|
|
- UIViewController *tRootViewControl = self.window.rootViewController;
|
|
|
+ UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController;
|
|
|
if ([tRootViewControl presentedViewController]) {
|
|
|
tRootViewControl = [tRootViewControl presentedViewController];
|
|
|
}
|
|
@@ -216,4 +461,523 @@ typedef NS_ENUM(NSInteger, PDFAnnotationDraggingType) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Rendering
|
|
|
+
|
|
|
+- (void)drawPage:(CPDFPage *)page toContext:(CGContextRef)context {
|
|
|
+ if (CPDFViewAnnotationModeLink == self.annotationMode) {
|
|
|
+ CGContextSetLineWidth(context, 1.0);
|
|
|
+ CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:255.0/255.f green:255.0/255.f blue:255.0/255.f alpha:0.8].CGColor);
|
|
|
+ CGContextSetFillColorWithColor(context, [UIColor colorWithRed:100.0/255.f green:149.0/255.f blue:237.0/255.f alpha:0.4].CGColor);
|
|
|
+ CGContextAddRect(context, self.addLinkRect);
|
|
|
+ CGContextDrawPath(context, kCGPathFillStroke);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.activeAnnotation.page != page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CGSize dragDotSize = CGSizeMake(30, 30);
|
|
|
+ CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:72.0/255.0 green:183.0/255.0 blue:247.0/255.0 alpha:1.0].CGColor);
|
|
|
+ if ([self.activeAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
|
|
|
+ CPDFLineAnnotation *line = (CPDFLineAnnotation *)self.activeAnnotation;
|
|
|
+ CGPoint startPoint = line.startPoint;
|
|
|
+ CGPoint endPoint = line.endPoint;
|
|
|
+
|
|
|
+ CGPoint tStartPoint = startPoint;
|
|
|
+ CGPoint tEndPoint = endPoint;
|
|
|
+
|
|
|
+ float final = 40;
|
|
|
+ if (fabs(tStartPoint.x - tEndPoint.x) < 0.00001) {
|
|
|
+ if (tStartPoint.y > tEndPoint.y) {
|
|
|
+ tStartPoint.y += final;
|
|
|
+ tEndPoint.y -= final;
|
|
|
+ } else {
|
|
|
+ tStartPoint.y -= final;
|
|
|
+ tEndPoint.y += final;
|
|
|
+ }
|
|
|
+ } else if (fabs(tStartPoint.y - tEndPoint.y) < 0.00001) {
|
|
|
+ if (tStartPoint.x > tEndPoint.x) {
|
|
|
+ tStartPoint.x += final;
|
|
|
+ tEndPoint.x -= final;
|
|
|
+ } else {
|
|
|
+ tStartPoint.x -= final;
|
|
|
+ tEndPoint.x += final;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ double k = (tEndPoint.y - tStartPoint.y)/(tEndPoint.x - tStartPoint.x);
|
|
|
+ double atank = atan(k);
|
|
|
+ if (endPoint.x > startPoint.x) {
|
|
|
+ tEndPoint.x += cos(atank) * final;
|
|
|
+ tEndPoint.y += sin(atank) * final;
|
|
|
+ tStartPoint.x -= cos(atank) * final;
|
|
|
+ tStartPoint.y -= sin(atank) * final;
|
|
|
+ } else {
|
|
|
+ tEndPoint.x -= cos(atank) * final;
|
|
|
+ tEndPoint.y -= sin(atank) * final;
|
|
|
+ tStartPoint.x += cos(atank) * final;
|
|
|
+ tStartPoint.y += sin(atank) * final;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CGContextSetLineWidth(context, 1.0);
|
|
|
+ CGFloat dashArray[] = {3,3};
|
|
|
+ CGContextSetLineDash(context, 0, dashArray, 2);
|
|
|
+ CGContextMoveToPoint(context, tStartPoint.x, tStartPoint.y);
|
|
|
+ CGContextAddLineToPoint(context, startPoint.x, startPoint.y);
|
|
|
+ CGContextStrokePath(context);
|
|
|
+ CGContextMoveToPoint(context, tEndPoint.x, tEndPoint.y);
|
|
|
+ CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
|
|
|
+ CGContextStrokePath(context);
|
|
|
+
|
|
|
+ CGRect startPointRect = CGRectMake(tStartPoint.x - dragDotSize.width/2.0,
|
|
|
+ tStartPoint.y - dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ CGRect endPointRect = CGRectMake(tEndPoint.x - dragDotSize.width/2.0,
|
|
|
+ tEndPoint.y - dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+
|
|
|
+ UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
|
|
|
+ CGImageRef dragDotImage = image.CGImage;
|
|
|
+
|
|
|
+ CGContextDrawImage(context, startPointRect, dragDotImage);
|
|
|
+ CGContextDrawImage(context, endPointRect, dragDotImage);
|
|
|
+
|
|
|
+ self.startPointRect = startPointRect;
|
|
|
+ self.endPointRect = endPointRect;
|
|
|
+ } else if ([self.activeAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
|
|
|
+ CGRect rect = CGRectInset(self.activeAnnotation.bounds, -dragDotSize.width/2.0, -dragDotSize.height/2.0);
|
|
|
+ CGContextSetLineWidth(context, 1.0);
|
|
|
+ CGFloat lengths[] = {6, 6};
|
|
|
+ CGContextSetLineDash(context, 0, lengths, 2);
|
|
|
+ CGContextStrokeRect(context, rect);
|
|
|
+ CGContextStrokePath(context);
|
|
|
+
|
|
|
+ CGAffineTransform transform = [page transform];
|
|
|
+ if (CPDFKitShareConfig.enableAnnotationNoRotate) {
|
|
|
+ rect = CGRectApplyAffineTransform(rect, transform);
|
|
|
+ }
|
|
|
+ CGRect leftCenterRect = CGRectMake(CGRectGetMinX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMidY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ CGRect rightCenterRect = CGRectMake(CGRectGetMaxX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMidY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ if (CPDFKitShareConfig.enableAnnotationNoRotate) {
|
|
|
+ leftCenterRect = CGRectApplyAffineTransform(leftCenterRect, CGAffineTransformInvert(transform));
|
|
|
+ rightCenterRect = CGRectApplyAffineTransform(rightCenterRect, CGAffineTransformInvert(transform));
|
|
|
+ }
|
|
|
+
|
|
|
+ UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
|
|
|
+ CGImageRef dragDotImage = image.CGImage;
|
|
|
+
|
|
|
+ CGContextDrawImage(context, leftCenterRect, dragDotImage);
|
|
|
+ CGContextDrawImage(context, rightCenterRect, dragDotImage);
|
|
|
+
|
|
|
+ self.startPointRect = leftCenterRect;
|
|
|
+ self.endPointRect = rightCenterRect;
|
|
|
+ } else {
|
|
|
+ CGRect rect = CGRectInset(self.activeAnnotation.bounds, -dragDotSize.width/2.0, -dragDotSize.height/2.0);
|
|
|
+ CGContextSetLineWidth(context, 1.0);
|
|
|
+ CGFloat lengths[] = {6, 6};
|
|
|
+ CGContextSetLineDash(context, 0, lengths, 2);
|
|
|
+ CGContextStrokeRect(context, rect);
|
|
|
+ CGContextStrokePath(context);
|
|
|
+
|
|
|
+ if ([self.activeAnnotation isKindOfClass:[CPDFSoundAnnotation class]] ||
|
|
|
+ [self.activeAnnotation isKindOfClass:[CPDFMovieAnnotation class]]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ CGRect topLeftRect = CGRectMake(CGRectGetMinX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMaxY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ CGRect bottomLeftRect = CGRectMake(CGRectGetMinX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMinY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ CGRect topRightRect = CGRectMake(CGRectGetMaxX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMaxY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+ CGRect bottomRightRect = CGRectMake(CGRectGetMaxX(rect)-dragDotSize.width/2.0,
|
|
|
+ CGRectGetMinY(rect)-dragDotSize.height/2.0,
|
|
|
+ dragDotSize.width, dragDotSize.height);
|
|
|
+
|
|
|
+ UIImage *image = [UIImage imageNamed:@"annotation_drag_dot.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
|
|
|
+ CGImageRef dragDotImage = image.CGImage;
|
|
|
+
|
|
|
+ CGContextDrawImage(context, topLeftRect, dragDotImage);
|
|
|
+ CGContextDrawImage(context, bottomLeftRect, dragDotImage);
|
|
|
+ CGContextDrawImage(context, topRightRect, dragDotImage);
|
|
|
+ CGContextDrawImage(context, bottomRightRect, dragDotImage);
|
|
|
+
|
|
|
+ self.topLeftRect = topLeftRect;
|
|
|
+ self.bottomLeftRect = bottomLeftRect;
|
|
|
+ self.topRightRect = topRightRect;
|
|
|
+ self.bottomRightRect = bottomRightRect;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Annotation
|
|
|
+
|
|
|
+- (void)moveAnnotation:(CPDFAnnotation *)annotation fromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint forType:(CPDFAnnotationDraggingType)draggingType {
|
|
|
+ CGRect bounds = annotation.bounds;
|
|
|
+ CGPoint offsetPoint = CGPointMake(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y);
|
|
|
+ CGFloat scale = bounds.size.height/bounds.size.width;
|
|
|
+ if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
|
|
|
+ CPDFLineAnnotation *line = (CPDFLineAnnotation *)annotation;
|
|
|
+ CGPoint startPoint = line.startPoint;
|
|
|
+ CGPoint endPoint = line.endPoint;
|
|
|
+ switch (draggingType) {
|
|
|
+ case CPDFAnnotationDraggingCenter:
|
|
|
+ {
|
|
|
+ startPoint.x += offsetPoint.x;
|
|
|
+ startPoint.y += offsetPoint.y;
|
|
|
+ endPoint.x += offsetPoint.x;
|
|
|
+ endPoint.y += offsetPoint.y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingStart:
|
|
|
+ {
|
|
|
+ startPoint.x += offsetPoint.x;
|
|
|
+ startPoint.y += offsetPoint.y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingEnd:
|
|
|
+ {
|
|
|
+ endPoint.x += offsetPoint.x;
|
|
|
+ endPoint.y += offsetPoint.y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ line.startPoint = startPoint;
|
|
|
+ line.endPoint = endPoint;
|
|
|
+ bounds = line.bounds;
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
|
|
|
+ CGAffineTransform transform = [annotation.page transform];
|
|
|
+ if (CPDFKitShareConfig.enableAnnotationNoRotate) {
|
|
|
+ bounds = CGRectApplyAffineTransform(bounds, transform);
|
|
|
+ toPoint = CGPointApplyAffineTransform(toPoint, transform);
|
|
|
+ fromPoint = CGPointApplyAffineTransform(fromPoint, transform);
|
|
|
+ offsetPoint = CGPointMake(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y);
|
|
|
+ }
|
|
|
+ CPDFFreeTextAnnotation *freeText = (CPDFFreeTextAnnotation *)annotation;
|
|
|
+ NSDictionary *attributes = @{NSFontAttributeName : freeText.font};
|
|
|
+ switch (draggingType) {
|
|
|
+ case CPDFAnnotationDraggingCenter:
|
|
|
+ {
|
|
|
+ bounds.origin.x += offsetPoint.x;
|
|
|
+ bounds.origin.y += offsetPoint.y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingStart:
|
|
|
+ {
|
|
|
+ CGFloat x = CGRectGetMaxX(bounds);
|
|
|
+ bounds.size.width -= offsetPoint.x;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.origin.x = x - bounds.size.width;
|
|
|
+
|
|
|
+ CGRect rect = [freeText.contents boundingRectWithSize:CGSizeMake(bounds.size.width, CGFLOAT_MAX)
|
|
|
+ options:NSStringDrawingUsesLineFragmentOrigin
|
|
|
+ attributes:attributes
|
|
|
+ context:nil];
|
|
|
+ bounds.origin.y = CGRectGetMaxY(bounds) - rect.size.height;
|
|
|
+ bounds.size.height = rect.size.height;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingEnd:
|
|
|
+ {
|
|
|
+ bounds.size.width += offsetPoint.x;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+
|
|
|
+ CGRect rect = [freeText.contents boundingRectWithSize:CGSizeMake(bounds.size.width, CGFLOAT_MAX)
|
|
|
+ options:NSStringDrawingUsesLineFragmentOrigin
|
|
|
+ attributes:attributes
|
|
|
+ context:nil];
|
|
|
+ bounds.origin.y = CGRectGetMaxY(bounds) - rect.size.height;
|
|
|
+ bounds.size.height = rect.size.height;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (CPDFKitShareConfig.enableAnnotationNoRotate) {
|
|
|
+ bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformInvert(transform));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ switch (draggingType) {
|
|
|
+ case CPDFAnnotationDraggingCenter:
|
|
|
+ {
|
|
|
+ bounds.origin.x += offsetPoint.x;
|
|
|
+ bounds.origin.y += offsetPoint.y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingTopLeft:
|
|
|
+ {
|
|
|
+ CGFloat x = CGRectGetMaxX(bounds);
|
|
|
+ bounds.size.width -= offsetPoint.x;
|
|
|
+ bounds.size.height += offsetPoint.y;
|
|
|
+
|
|
|
+ if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
|
|
|
+ bounds.size.height = bounds.size.width*scale;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0*scale);
|
|
|
+ } else {
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ bounds.origin.x = x - bounds.size.width;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingBottomLeft:
|
|
|
+ {
|
|
|
+ CGFloat x = CGRectGetMaxX(bounds);
|
|
|
+ CGFloat y = CGRectGetMaxY(bounds);
|
|
|
+ bounds.size.width -= offsetPoint.x;
|
|
|
+ bounds.size.height -= offsetPoint.y;
|
|
|
+
|
|
|
+ if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
|
|
|
+ bounds.size.height = bounds.size.width*scale;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0*scale);
|
|
|
+ } else {
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ bounds.origin.x = x - bounds.size.width;
|
|
|
+ bounds.origin.y = y - bounds.size.height;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingTopRight:
|
|
|
+ {
|
|
|
+ bounds.size.width += offsetPoint.x;
|
|
|
+ bounds.size.height += offsetPoint.y;
|
|
|
+
|
|
|
+ if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
|
|
|
+ bounds.size.height = bounds.size.width*scale;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0*scale);
|
|
|
+ } else {
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationDraggingBottomRight:
|
|
|
+ {
|
|
|
+ CGFloat y = CGRectGetMaxY(bounds);
|
|
|
+ bounds.size.width += offsetPoint.x;
|
|
|
+ bounds.size.height -= offsetPoint.y;
|
|
|
+
|
|
|
+ if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
|
|
|
+ [annotation isKindOfClass:[CPDFInkAnnotation class]]) {
|
|
|
+ bounds.size.height = bounds.size.width*scale;
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0*scale);
|
|
|
+ } else {
|
|
|
+ bounds.size.width = MAX(bounds.size.width, 5.0);
|
|
|
+ bounds.size.height = MAX(bounds.size.height, 5.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ bounds.origin.y = y - bounds.size.height;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CGRectGetMinX(bounds) < 0) {
|
|
|
+ bounds.origin.x = 0;
|
|
|
+ }
|
|
|
+ if (CGRectGetMaxX(bounds) > CGRectGetWidth(annotation.page.bounds)) {
|
|
|
+ bounds.origin.x = CGRectGetWidth(annotation.page.bounds) - CGRectGetWidth(bounds);
|
|
|
+ }
|
|
|
+ if (CGRectGetMinY(bounds) < 0) {
|
|
|
+ bounds.origin.y = 0;
|
|
|
+ }
|
|
|
+ if (CGRectGetMaxY(bounds) > CGRectGetHeight(annotation.page.bounds)) {
|
|
|
+ bounds.origin.y = CGRectGetHeight(annotation.page.bounds) - CGRectGetHeight(bounds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ annotation.bounds = bounds;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)addAnnotation:(CPDFViewAnnotationMode)mode atPoint:(CGPoint)point forPage:(CPDFPage *)page {
|
|
|
+ CPDFAnnotation *annotation = nil;
|
|
|
+ switch (mode) {
|
|
|
+ case CPDFViewAnnotationModeNote:
|
|
|
+ {
|
|
|
+ CGFloat width = 57.0/1.5;
|
|
|
+ annotation = [[CPDFTextAnnotation alloc] initWithDocument:self.document];
|
|
|
+ annotation.bounds = CGRectMake(point.x-width/2.0, point.y-width/2.0, width, width);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeHighlight:
|
|
|
+ {
|
|
|
+ if (!self.currentSelection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSMutableArray *quadrilateralPoints = [NSMutableArray array];
|
|
|
+ annotation = [[CPDFMarkupAnnotation alloc] initWithDocument:self.document markupType:CPDFMarkupTypeHighlight];
|
|
|
+ for (CPDFSelection *selection in self.currentSelection.selectionsByLine) {
|
|
|
+ CGRect bounds = selection.bounds;
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ }
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setQuadrilateralPoints:quadrilateralPoints];
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setMarkupText:self.currentSelection.string];
|
|
|
+ [self clearSelection];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeUnderline:
|
|
|
+ {
|
|
|
+ if (!self.currentSelection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSMutableArray *quadrilateralPoints = [NSMutableArray array];
|
|
|
+ annotation = [[CPDFMarkupAnnotation alloc] initWithDocument:self.document markupType:CPDFMarkupTypeUnderline];
|
|
|
+ for (CPDFSelection *selection in self.currentSelection.selectionsByLine) {
|
|
|
+ CGRect bounds = selection.bounds;
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ }
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setQuadrilateralPoints:quadrilateralPoints];
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setMarkupText:self.currentSelection.string];
|
|
|
+ [self clearSelection];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeStrikeout:
|
|
|
+ {
|
|
|
+ if (!self.currentSelection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSMutableArray *quadrilateralPoints = [NSMutableArray array];
|
|
|
+ annotation = [[CPDFMarkupAnnotation alloc] initWithDocument:self.document markupType:CPDFMarkupTypeStrikeOut];
|
|
|
+ for (CPDFSelection *selection in self.currentSelection.selectionsByLine) {
|
|
|
+ CGRect bounds = selection.bounds;
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ }
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setQuadrilateralPoints:quadrilateralPoints];
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setMarkupText:self.currentSelection.string];
|
|
|
+ [self clearSelection];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeSquiggly:
|
|
|
+ {
|
|
|
+ if (!self.currentSelection) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSMutableArray *quadrilateralPoints = [NSMutableArray array];
|
|
|
+ annotation = [[CPDFMarkupAnnotation alloc] initWithDocument:self.document markupType:CPDFMarkupTypeSquiggly];
|
|
|
+ for (CPDFSelection *selection in self.currentSelection.selectionsByLine) {
|
|
|
+ CGRect bounds = selection.bounds;
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ [quadrilateralPoints addObject:[NSValue valueWithCGPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMinY(bounds))]];
|
|
|
+ }
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setQuadrilateralPoints:quadrilateralPoints];
|
|
|
+ [(CPDFMarkupAnnotation *)annotation setMarkupText:self.currentSelection.string];
|
|
|
+ [self clearSelection];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeCircle:
|
|
|
+ {
|
|
|
+ annotation = [[CPDFCircleAnnotation alloc] initWithDocument:self.document];
|
|
|
+ annotation.bounds = CGRectMake(point.x-50, point.y-50, 100, 100);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeSquare:
|
|
|
+ {
|
|
|
+ annotation = [[CPDFSquareAnnotation alloc] initWithDocument:self.document];
|
|
|
+ annotation.bounds = CGRectMake(point.x-50, point.y-50, 100, 100);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeArrow:
|
|
|
+ {
|
|
|
+ annotation = [[CPDFLineAnnotation alloc] initWithDocument:self.document];
|
|
|
+ [(CPDFLineAnnotation *)annotation setStartPoint:CGPointMake(point.x-50, point.y)];
|
|
|
+ [(CPDFLineAnnotation *)annotation setEndPoint:CGPointMake(point.x+50, point.y)];
|
|
|
+ [(CPDFLineAnnotation *)annotation setEndLineStyle:CPDFLineStyleClosedArrow];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CPDFViewAnnotationModeLine:
|
|
|
+ {
|
|
|
+ annotation = [[CPDFLineAnnotation alloc] initWithDocument:self.document];
|
|
|
+ [(CPDFLineAnnotation *)annotation setStartPoint:CGPointMake(point.x-50, point.y)];
|
|
|
+ [(CPDFLineAnnotation *)annotation setEndPoint:CGPointMake(point.x+50, point.y)];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!annotation) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [annotation setModificationDate:[NSDate date]];
|
|
|
+ [annotation setUserName:[self annotationUserName]];
|
|
|
+ [page addAnnotation:annotation];
|
|
|
+
|
|
|
+ if ([annotation isKindOfClass:[CPDFTextAnnotation class]]) {
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+// if ([self.performDelegate respondsToSelector:@selector(PDFViewPerformOpenNote:forAnnotation:)]) {
|
|
|
+// [self.performDelegate PDFViewPerformOpenNote:self forAnnotation:annotation];
|
|
|
+// }
|
|
|
+ } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ } else {
|
|
|
+ self.activeAnnotation = annotation;
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ [self updateScrollEnabled];
|
|
|
+
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)addAnnotation:(CPDFAnnotation *)annotation forPage:(CPDFPage *)page {
|
|
|
+ if (!annotation || !page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [annotation setModificationDate:[NSDate date]];
|
|
|
+ [annotation setUserName:[self annotationUserName]];
|
|
|
+ [page addAnnotation:annotation];
|
|
|
+
|
|
|
+ self.activeAnnotation = annotation;
|
|
|
+ [self setNeedsDisplayForPage:page];
|
|
|
+ [self updateScrollEnabled];
|
|
|
+
|
|
|
+// [self showMenuForAnnotation:annotation];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)addAnnotation:(CPDFAnnotation *)annotation {
|
|
|
+ CPDFPage *page = [self.document pageAtIndex:self.currentPageIndex];
|
|
|
+ CGPoint center = [self convertPoint:self.center toPage:page];
|
|
|
+ if (CGPointEqualToPoint(center, CGPointZero)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CGRect bounds = annotation.bounds;
|
|
|
+ bounds.origin.x = center.x-bounds.size.width/2.0;
|
|
|
+ bounds.origin.y = center.y-bounds.size.height/2.0;
|
|
|
+ bounds.origin.y = MIN(MAX(0, bounds.origin.y), page.bounds.size.height-bounds.size.height);
|
|
|
+ annotation.bounds = bounds;
|
|
|
+ [self addAnnotation:annotation forPage:page];
|
|
|
+}
|
|
|
+
|
|
|
@end
|