|
@@ -384,80 +384,97 @@
|
|
|
- (void)dragAnnotationReferenceLine:(CPDFAnnotation *)annotation {
|
|
|
[self removeShapeLayer];
|
|
|
|
|
|
- if ([self isAlignedWithOtherForms:annotation] && annotation) {
|
|
|
+ CAnnotationAlignState state = [self isAlignedWithOtherForms:annotation];
|
|
|
+ if (state != CAnnotationAlignStateNone && annotation) {
|
|
|
CGRect bounds = annotation.bounds;
|
|
|
NSRect rect = [self convertRect:bounds fromPage:self.currentPage];
|
|
|
- [self drawLineOfDashByCAShapeLayer:rect];
|
|
|
+ [self drawLineOfDashByCAShapeLayer:rect withAlignState:state];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)drawLineOfDashByCAShapeLayer:(CGRect)frame {
|
|
|
+- (void)drawLineOfDashByCAShapeLayer:(CGRect)frame withAlignState:(CAnnotationAlignState)state {
|
|
|
NSColor *lineColor = [CPDFListViewConfig defaultManager].dragHoverColor;
|
|
|
CGFloat lineWidth = [self unitWidthOnPage:self.currentPage];
|
|
|
|
|
|
- self.shapeLayerTopH = [CAShapeLayer layer];
|
|
|
- [self.shapeLayerTopH setFrame:frame];
|
|
|
- [self.shapeLayerTopH setFillColor:[NSColor clearColor].CGColor];
|
|
|
- [self.shapeLayerTopH setStrokeColor:lineColor.CGColor];
|
|
|
- [self.shapeLayerTopH setLineWidth:lineWidth]; // 设置虚线宽度
|
|
|
- [self.shapeLayerTopH setLineJoin:kCALineJoinRound];
|
|
|
-// [self.shapeLayerTopH setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:20], [NSNumber numberWithInt:20], nil]]; // 设置线宽,线间距
|
|
|
- // 设置路径
|
|
|
- CGMutablePathRef path1 = CGPathCreateMutable();
|
|
|
- CGPathMoveToPoint(path1, NULL, -CGRectGetWidth(self.frame), 0);
|
|
|
- CGPathAddLineToPoint(path1, NULL, 2*CGRectGetWidth(self.frame), 0);
|
|
|
- [self.shapeLayerTopH setPath:path1];
|
|
|
- CGPathRelease(path1);
|
|
|
- [self.layer addSublayer:self.shapeLayerTopH];
|
|
|
+ if (state == CAnnotationAlignStateTop) {
|
|
|
+ self.shapeLayerTopH = [CAShapeLayer layer];
|
|
|
+ [self.shapeLayerTopH setFrame:frame];
|
|
|
+ [self.shapeLayerTopH setFillColor:[NSColor clearColor].CGColor];
|
|
|
+ [self.shapeLayerTopH setStrokeColor:lineColor.CGColor];
|
|
|
+ [self.shapeLayerTopH setLineWidth:lineWidth]; // 设置虚线宽度
|
|
|
+ [self.shapeLayerTopH setLineJoin:kCALineJoinRound];
|
|
|
+ // [self.shapeLayerTopH setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:20], [NSNumber numberWithInt:20], nil]]; // 设置线宽,线间距
|
|
|
+ // 设置路径
|
|
|
+ CGMutablePathRef path1 = CGPathCreateMutable();
|
|
|
+ CGPathMoveToPoint(path1, NULL, -CGRectGetWidth(self.frame), 0);
|
|
|
+ CGPathAddLineToPoint(path1, NULL, 2*CGRectGetWidth(self.frame), 0);
|
|
|
+ [self.shapeLayerTopH setPath:path1];
|
|
|
+ CGPathRelease(path1);
|
|
|
+ [self.layer addSublayer:self.shapeLayerTopH];
|
|
|
+ }
|
|
|
|
|
|
- self.shapeLayerBottomH = [CAShapeLayer layer];
|
|
|
- [self.shapeLayerBottomH setFrame:frame];
|
|
|
- [self.shapeLayerBottomH setFillColor:[NSColor clearColor].CGColor];
|
|
|
- [self.shapeLayerBottomH setStrokeColor:lineColor.CGColor];
|
|
|
- [self.shapeLayerBottomH setLineWidth:lineWidth];
|
|
|
- [self.shapeLayerBottomH setLineJoin:kCALineJoinRound];
|
|
|
- CGMutablePathRef path2 = CGPathCreateMutable();
|
|
|
- CGPathMoveToPoint(path2, NULL, -CGRectGetWidth(self.frame), CGRectGetHeight(frame));
|
|
|
- CGPathAddLineToPoint(path2, NULL, 2*CGRectGetWidth(self.frame), CGRectGetHeight(frame));
|
|
|
- [self.shapeLayerBottomH setPath:path2];
|
|
|
- CGPathRelease(path2);
|
|
|
- [self.layer addSublayer:self.shapeLayerBottomH];
|
|
|
-
|
|
|
- self.shapeLayerLeftV = [CAShapeLayer layer];
|
|
|
- [self.shapeLayerLeftV setFrame:frame];
|
|
|
- [self.shapeLayerLeftV setFillColor:[NSColor clearColor].CGColor];
|
|
|
- [self.shapeLayerLeftV setStrokeColor:lineColor.CGColor];
|
|
|
- [self.shapeLayerLeftV setLineWidth:lineWidth];
|
|
|
- [self.shapeLayerLeftV setLineJoin:kCALineJoinRound];
|
|
|
- CGMutablePathRef path3 = CGPathCreateMutable();
|
|
|
- CGPathMoveToPoint(path3, NULL, 0, -CGRectGetHeight(self.frame));
|
|
|
- CGPathAddLineToPoint(path3, NULL, 0, 2*CGRectGetHeight(self.frame));
|
|
|
- [self.shapeLayerLeftV setPath:path3];
|
|
|
- CGPathRelease(path3);
|
|
|
- [self.layer addSublayer:self.shapeLayerLeftV];
|
|
|
-
|
|
|
- self.shapeLayerRightV = [CAShapeLayer layer];
|
|
|
- [self.shapeLayerRightV setFrame:frame];
|
|
|
- [self.shapeLayerRightV setFillColor:[NSColor clearColor].CGColor];
|
|
|
- [self.shapeLayerRightV setStrokeColor:lineColor.CGColor];
|
|
|
- [self.shapeLayerRightV setLineWidth:lineWidth];
|
|
|
- [self.shapeLayerRightV setLineJoin:kCALineJoinRound];
|
|
|
- CGMutablePathRef path4 = CGPathCreateMutable();
|
|
|
- CGPathMoveToPoint(path4, NULL, CGRectGetWidth(frame), -CGRectGetHeight(self.frame));
|
|
|
- CGPathAddLineToPoint(path4, NULL, CGRectGetWidth(frame), 2*CGRectGetHeight(self.frame));
|
|
|
- [self.shapeLayerRightV setPath:path4];
|
|
|
- CGPathRelease(path4);
|
|
|
- [self.layer addSublayer:self.shapeLayerRightV];
|
|
|
-}
|
|
|
-
|
|
|
-- (BOOL)isAlignedWithOtherForms:(CPDFAnnotation *)activeAnnotation {
|
|
|
+ if (state == CAnnotationAlignStateBottom) {
|
|
|
+ self.shapeLayerBottomH = [CAShapeLayer layer];
|
|
|
+ [self.shapeLayerBottomH setFrame:frame];
|
|
|
+ [self.shapeLayerBottomH setFillColor:[NSColor clearColor].CGColor];
|
|
|
+ [self.shapeLayerBottomH setStrokeColor:lineColor.CGColor];
|
|
|
+ [self.shapeLayerBottomH setLineWidth:lineWidth];
|
|
|
+ [self.shapeLayerBottomH setLineJoin:kCALineJoinRound];
|
|
|
+ CGMutablePathRef path2 = CGPathCreateMutable();
|
|
|
+ CGPathMoveToPoint(path2, NULL, -CGRectGetWidth(self.frame), CGRectGetHeight(frame));
|
|
|
+ CGPathAddLineToPoint(path2, NULL, 2*CGRectGetWidth(self.frame), CGRectGetHeight(frame));
|
|
|
+ [self.shapeLayerBottomH setPath:path2];
|
|
|
+ CGPathRelease(path2);
|
|
|
+ [self.layer addSublayer:self.shapeLayerBottomH];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state == CAnnotationAlignStateLeft) {
|
|
|
+ self.shapeLayerLeftV = [CAShapeLayer layer];
|
|
|
+ [self.shapeLayerLeftV setFrame:frame];
|
|
|
+ [self.shapeLayerLeftV setFillColor:[NSColor clearColor].CGColor];
|
|
|
+ [self.shapeLayerLeftV setStrokeColor:lineColor.CGColor];
|
|
|
+ [self.shapeLayerLeftV setLineWidth:lineWidth];
|
|
|
+ [self.shapeLayerLeftV setLineJoin:kCALineJoinRound];
|
|
|
+ CGMutablePathRef path3 = CGPathCreateMutable();
|
|
|
+ CGPathMoveToPoint(path3, NULL, 0, -CGRectGetHeight(self.frame));
|
|
|
+ CGPathAddLineToPoint(path3, NULL, 0, 2*CGRectGetHeight(self.frame));
|
|
|
+ [self.shapeLayerLeftV setPath:path3];
|
|
|
+ CGPathRelease(path3);
|
|
|
+ [self.layer addSublayer:self.shapeLayerLeftV];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state == CAnnotationAlignStateRight) {
|
|
|
+ self.shapeLayerRightV = [CAShapeLayer layer];
|
|
|
+ [self.shapeLayerRightV setFrame:frame];
|
|
|
+ [self.shapeLayerRightV setFillColor:[NSColor clearColor].CGColor];
|
|
|
+ [self.shapeLayerRightV setStrokeColor:lineColor.CGColor];
|
|
|
+ [self.shapeLayerRightV setLineWidth:lineWidth];
|
|
|
+ [self.shapeLayerRightV setLineJoin:kCALineJoinRound];
|
|
|
+ CGMutablePathRef path4 = CGPathCreateMutable();
|
|
|
+ CGPathMoveToPoint(path4, NULL, CGRectGetWidth(frame), -CGRectGetHeight(self.frame));
|
|
|
+ CGPathAddLineToPoint(path4, NULL, CGRectGetWidth(frame), 2*CGRectGetHeight(self.frame));
|
|
|
+ [self.shapeLayerRightV setPath:path4];
|
|
|
+ CGPathRelease(path4);
|
|
|
+ [self.layer addSublayer:self.shapeLayerRightV];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (CAnnotationAlignState)isAlignedWithOtherForms:(CPDFAnnotation *)activeAnnotation {
|
|
|
if ([activeAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
|
|
|
for (CPDFAnnotation *annotation in self.currentPage.annotations) {
|
|
|
if (![annotation isEqual:activeAnnotation] && [annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
|
|
|
- CGFloat annotationX = ABS(activeAnnotation.bounds.origin.x - annotation.bounds.origin.x);
|
|
|
- CGFloat annotationY = ABS((activeAnnotation.bounds.origin.y+activeAnnotation.bounds.size.height) - (annotation.bounds.origin.y+annotation.bounds.size.height));
|
|
|
- if (annotationX < 0.5 || annotationY < 0.5) {
|
|
|
- return YES;
|
|
|
+ CGFloat annotationLeft = ABS(activeAnnotation.bounds.origin.x - annotation.bounds.origin.x);
|
|
|
+ CGFloat annotationRight = ABS((activeAnnotation.bounds.origin.x+activeAnnotation.bounds.size.width) - (annotation.bounds.origin.x + annotation.bounds.size.width));
|
|
|
+ CGFloat annotationTop = ABS(activeAnnotation.bounds.origin.y - annotation.bounds.origin.y);
|
|
|
+ CGFloat annotationBottom = ABS((activeAnnotation.bounds.origin.y+activeAnnotation.bounds.size.height) - (annotation.bounds.origin.y+annotation.bounds.size.height));
|
|
|
+ if (annotationLeft < 0.5) {
|
|
|
+ return CAnnotationAlignStateLeft;
|
|
|
+ } else if (annotationRight < 0.5) {
|
|
|
+ return CAnnotationAlignStateRight;
|
|
|
+ } else if (annotationTop < 0.5) {
|
|
|
+ return CAnnotationAlignStateTop;
|
|
|
+ } else if (annotationBottom < 0.5) {
|
|
|
+ return CAnnotationAlignStateBottom;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -466,15 +483,23 @@
|
|
|
if (![annotation isEqual:activeAnnotation] &&
|
|
|
![annotation isKindOfClass:[CPDFLinkAnnotation class]] &&
|
|
|
![annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
|
|
|
- CGFloat annotationX = ABS(activeAnnotation.bounds.origin.x - annotation.bounds.origin.x);
|
|
|
- CGFloat annotationY = ABS((activeAnnotation.bounds.origin.y+activeAnnotation.bounds.size.height) - (annotation.bounds.origin.y+annotation.bounds.size.height));
|
|
|
- if (annotationX < 0.5 || annotationY < 0.5) {
|
|
|
- return YES;
|
|
|
+ CGFloat annotationLeft = ABS(activeAnnotation.bounds.origin.x - annotation.bounds.origin.x);
|
|
|
+ CGFloat annotationRight = ABS((activeAnnotation.bounds.origin.x+activeAnnotation.bounds.size.width) - (annotation.bounds.origin.x + annotation.bounds.size.width));
|
|
|
+ CGFloat annotationTop = ABS(activeAnnotation.bounds.origin.y - annotation.bounds.origin.y);
|
|
|
+ CGFloat annotationBottom = ABS((activeAnnotation.bounds.origin.y+activeAnnotation.bounds.size.height) - (annotation.bounds.origin.y+annotation.bounds.size.height));
|
|
|
+ if (annotationLeft < 0.5) {
|
|
|
+ return CAnnotationAlignStateLeft;
|
|
|
+ } else if (annotationRight < 0.5) {
|
|
|
+ return CAnnotationAlignStateRight;
|
|
|
+ } else if (annotationTop < 0.5) {
|
|
|
+ return CAnnotationAlignStateTop;
|
|
|
+ } else if (annotationBottom < 0.5) {
|
|
|
+ return CAnnotationAlignStateBottom;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return NO;
|
|
|
+ return CAnnotationAlignStateNone;
|
|
|
}
|
|
|
|
|
|
- (void)moveAnnotationOnPage:(CPDFPage *)aPage
|