Browse Source

【Cisdem PDFMaster】线段测量注释修改

wanjun 7 months ago
parent
commit
4d142315e4

+ 0 - 5
PDF Office/PDF Master/Class/DigtalSignature/CPDFDigtalView/CPDFDigtalView.m

@@ -240,11 +240,6 @@
 
 - (void)dragAnnotationReferenceLine:(CPDFAnnotation *)annotation {
     
-//    if ([self isAlignedWithOtherForms:annotation] && annotation) {
-//        CGRect bounds = annotation.bounds;
-//        NSRect rect = [self convertRect:bounds fromPage:self.currentPage];
-//        [self drawLineOfDashByCAShapeLayer:rect];
-//    }
 }
 
 - (void)editAnnotation:(CPDFAnnotation *)annotation {

+ 1 - 9
PDF Office/PDF Master/Class/Measure/Window/CDistanceMeasureInfoWindowController.swift

@@ -25,20 +25,12 @@ class CDistanceMeasureInfoWindowController: NSWindowController {
 
     weak var delegate: CDistanceMeasureInfoWindowControllerDelegate?
     
-//    private(set) var measureInfo: CPDFDistanceMeasureInfo = CPDFDistanceMeasureInfo()
     var measureInfo: CPDFDistanceMeasureInfo = CPDFDistanceMeasureInfo()
     
     convenience init() {
         self.init(windowNibName: "CDistanceMeasureInfoWindowController")
     }
-//    init(measureInfo: CPDFDistanceMeasureInfo) {
-//        self.measureInfo = measureInfo
-//        super.init(window: nil)
-//    }
-//
-//    required init?(coder: NSCoder) {
-//        fatalError("init(coder:) has not been implemented")
-//    }
+    
     override func windowDidLoad() {
         super.windowDidLoad()
         

+ 3 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLineAnnotation+PDFListView.swift

@@ -128,9 +128,9 @@ import Foundation
         if (isMeasure) {
             let translationDistance = measureInfo!.leadLength;
             let normalVector = calculateNormalVector(startPoint: startPoint, endPoint: endPoint)
-            let startPoint = translate(point: startPoint, withNormalVector: normalVector, distance: translationDistance)
-            let endPoint = translate(point: endPoint, withNormalVector: normalVector, distance: translationDistance)
-            let midPoint = NSMakePoint((startPoint.x+endPoint.x)/2, (startPoint.y+endPoint.y)/2)
+            let translationStartPoint = translate(point: startPoint, withNormalVector: normalVector, distance: translationDistance)
+            let translationEndPoint = translate(point: endPoint, withNormalVector: normalVector, distance: translationDistance)
+            let midPoint = NSMakePoint((translationStartPoint.x+translationEndPoint.x)/2, (translationStartPoint.y+translationEndPoint.y)/2)
             
             if (NSPointInRect(point, CPDFListViewRectFromCenterAndSize(endPoint, size))) {
                 return .maxXEdgeMask

+ 1 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFPolygonAnnotation+PDFListView.swift

@@ -39,7 +39,7 @@ import Foundation
     }
     
     override func borderRecct(for pdfView: CPDFListView) -> CGRect {
-        let rect = pdfView.integralRect(self.bounds, on: self.page)
+        let rect = pdfView.integralRect(bounds, on: page)
         return rect
     }
 
@@ -139,5 +139,4 @@ import Foundation
         context.strokePath()
         context.restoreGState()
     }
-
 }

+ 8 - 4
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFPolylineAnnotation+PDFListView.swift

@@ -36,6 +36,11 @@ import Foundation
         }
     }
     
+    override func borderRecctForView(_ pdfView: CPDFListView) -> CGRect {
+        let rect = pdfView.integralRect(bounds, on: page)
+        return rect
+    }
+    
     override func resizeHandleForPoint(_ point: NSPoint, scaleFactor: CGFloat) -> CRectEdges {
         guard self.isResizable() else { return [] }
         let size = CPDFListViewMakeSquareSize(8 / scaleFactor)
@@ -50,7 +55,7 @@ import Foundation
         if self.hitTest(point) {
             return .editInEdgeMask
         } else {
-            return []
+            return CRectEdges(rawValue: 0)
         }
     }
     
@@ -72,7 +77,7 @@ import Foundation
     override func isMovable() -> Bool {
         return true
     }
-    
+        
     override func hitTest(_ point: NSPoint) -> Bool {
         let delta = max(4.0, 0.5 * self.lineWidth())
         let pointsArray = self.savePoints()
@@ -83,7 +88,7 @@ import Foundation
                 let pointA = pointValueA.pointValue
                 let pointB = pointValueB.pointValue
                 
-                let isNear = CPDFListViewPointNearLineFromPointToPoint(pointA, pointB, point, delta)
+                let isNear = CPDFListViewPointNearLineFromPointToPoint(point, pointA, pointB, delta)
                 if isNear {
                     return self.shouldDisplay() && isNear
                 }
@@ -91,5 +96,4 @@ import Foundation
         }
         return false
     }
-
 }

+ 120 - 32
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -3057,20 +3057,20 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     }
     
     if (NSEqualPoints(startPoint, endPoint) == NO) {
-        NSRect newBounds = CPDFListViewIntegralRectFromPoints(startPoint, endPoint);
-        
-        if (NSWidth(newBounds) < MIN_NOTE_SIZE) {
-            newBounds.size.width = MIN_NOTE_SIZE;
-            newBounds.origin.x = floor(0.5 * ((startPoint.x + endPoint.x) - MIN_NOTE_SIZE));
-        }
-        if (NSHeight(newBounds) < MIN_NOTE_SIZE) {
-            newBounds.size.height = MIN_NOTE_SIZE;
-            newBounds.origin.y = floor(0.5 * ((startPoint.y + endPoint.y) - MIN_NOTE_SIZE));
-        }
-        
+//        NSRect newBounds = CPDFListViewIntegralRectFromPoints(startPoint, endPoint);
+//        
+//        if (NSWidth(newBounds) < MIN_NOTE_SIZE) {
+//            newBounds.size.width = MIN_NOTE_SIZE;
+//            newBounds.origin.x = floor(0.5 * ((startPoint.x + endPoint.x) - MIN_NOTE_SIZE));
+//        }
+//        if (NSHeight(newBounds) < MIN_NOTE_SIZE) {
+//            newBounds.size.height = MIN_NOTE_SIZE;
+//            newBounds.origin.y = floor(0.5 * ((startPoint.y + endPoint.y) - MIN_NOTE_SIZE));
+//        }
+//        
         [(CPDFLineAnnotation *)activeAnnotation setObservedStartPoint:startPoint];
         [(CPDFLineAnnotation *)activeAnnotation setObservedEndPoint:endPoint];
-        [activeAnnotation setBounds:newBounds];
+//        [activeAnnotation setBounds:newBounds];
     }
 }
 
@@ -4458,6 +4458,95 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     lineAnnotation.bounds = bound;
 }
 
+- (void)doMoveAnnotation:(CPDFAnnotation *)activeAnnotation withEvent:(NSEvent *)theEvent boundOffset:(NSPoint)boundOffset offset:(NSPoint)offset{
+    // Move annotation.
+    [[[self scrollView] contentView] autoscroll:theEvent];
+    
+    NSPoint point = NSZeroPoint;
+    CPDFPage *newActivePage = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
+    
+    if (newActivePage) { // newActivePage should never be nil, but just to be sure
+        if (newActivePage != [activeAnnotation page]) {
+            return;
+        }
+        
+        NSRect newBounds = [activeAnnotation bounds];
+        newBounds.origin = CPDFListViewIntegralPoint(CPDFListViewSubstractPoints(point, boundOffset));
+        // constrain bounds inside page bounds
+        newBounds = CPDFListViewConstrainRect(newBounds, [newActivePage  boundsForBox:[self displayBox]],[CPDFListViewConfig defaultManager].annotationBorderOffset.floatValue);
+        
+        if([activeAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
+            CPDFLineAnnotation *line = (CPDFLineAnnotation *)activeAnnotation;
+            NSPoint startPoint = [line startPoint];
+            NSPoint endPoint = [line endPoint];
+            CPDFDistanceMeasureInfo *me = [line measureInfo];
+            
+            startPoint = CPDFListViewIntegralPoint(CPDFListViewAddPoints(startPoint, offset));
+            endPoint = CPDFListViewIntegralPoint(CPDFListViewAddPoints(endPoint, offset));
+
+            CGRect boderRect = [self borderRecctForSavePoints:[line pointsFromMeasureWithStartPoint:startPoint endPoint:endPoint]];
+            BOOL isContant = CGRectContainsRect([activeAnnotation.page boundsForBox:[self displayBox]], boderRect);
+            if (isContant) {
+                [line setStartPoint:startPoint];
+                [line setEndPoint:endPoint];
+                if(line.isMeasure) {
+                    [activeAnnotation setBounds:newBounds];
+                    [line setMeasureInfo:me];
+                }
+            }
+        } else if ([activeAnnotation isKindOfClass:[CPDFPolylineAnnotation class]]) {
+            CPDFPolylineAnnotation *line = (CPDFPolylineAnnotation *)activeAnnotation;
+            
+            NSMutableArray<NSValue *> *savePoints = [NSMutableArray arrayWithArray:[line savePoints]];
+            CPDFPerimeterMeasureInfo *me = [line measureInfo];
+            
+            NSMutableArray<NSValue *> *newSavePoints = [NSMutableArray array];
+            for (NSValue *saveValue in savePoints) {
+                NSPoint savePoint = [saveValue pointValue];
+                savePoint = CPDFListViewIntegralPoint(CPDFListViewAddPoints(savePoint, offset));
+                [newSavePoints addObject:[NSValue valueWithPoint:savePoint]];
+            }
+            
+            CGRect boderRect = [self borderRecctForSavePoints:newSavePoints];
+            BOOL isContant = CGRectContainsRect([newActivePage  boundsForBox:[self displayBox]], boderRect);
+            
+            if (isContant) {
+                [(CPDFPolylineAnnotation *)activeAnnotation setSavePoints:newSavePoints];
+                if(line.isMeasure) {
+                    [activeAnnotation setBounds:newBounds];
+                    [line setMeasureInfo:me];
+                }
+                
+            }
+        } else if ([activeAnnotation isKindOfClass:[CPDFPolygonAnnotation class]]) {
+            CPDFPolygonAnnotation *polygonAnnotation = (CPDFPolygonAnnotation *)activeAnnotation;
+            
+            NSMutableArray<NSValue *> *savePoints = [NSMutableArray arrayWithArray:[polygonAnnotation savePoints]];
+            CPDFAreaMeasureInfo *me = [polygonAnnotation measureInfo];
+            
+            NSMutableArray<NSValue *> *newSavePoints = [NSMutableArray array];
+            for (NSValue *saveValue in savePoints) {
+                NSPoint savePoint = [saveValue pointValue];
+                savePoint = CPDFListViewIntegralPoint(CPDFListViewAddPoints(savePoint, offset));
+                [newSavePoints addObject:[NSValue valueWithPoint:savePoint]];
+            }
+            
+            CGRect boderRect = [self borderRecctForSavePoints:newSavePoints];
+            BOOL isContant = CGRectContainsRect([newActivePage  boundsForBox:[self displayBox]], boderRect);
+            
+            if (isContant) {
+                [polygonAnnotation setSavePoints:newSavePoints];
+                if(polygonAnnotation.isMeasure) {
+                    [activeAnnotation setBounds:newBounds];
+                    [polygonAnnotation setMeasureInfo:me];
+                }
+            }
+        } else {
+            [activeAnnotation setBounds:newBounds];
+        }
+    }
+}
+
 - (void)doMoveAnnotation:(CPDFAnnotation *)activeAnnotation withEvent:(NSEvent *)theEvent offset:(NSPoint)offset {
     // Move annotation.
     [[[self scrollView] contentView] autoscroll:theEvent];
@@ -4968,6 +5057,11 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                     lastMouseEvent = theEvent;
                     draggedAnnotation = YES;
                     [self removeShapeLayer];
+                    
+                    NSPoint currentPoint = NSZeroPoint;
+                    [self pageAndPoint:&currentPoint forEvent:theEvent nearest:YES];
+                    CGPoint offsetPoint =  CGPointMake(currentPoint.x - pagePoint.x, currentPoint.y - pagePoint.y);
+
                     if(!isContains) {
                         
                         CGRect borderRect = [newActiveAnnotation borderRecctForView:self];
@@ -4978,53 +5072,47 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                         [self.selectAnnotations removeAllObjects];
                         [self.selectAnnotations addObject:newActiveAnnotation];
                         if(isLine) {
-                            NSPoint currentPoint = NSZeroPoint;
-                            [self pageAndPoint:&currentPoint forEvent:theEvent nearest:YES];
-                            
-                            CGPoint offsetPoint =  CGPointMake(currentPoint.x - pagePoint.x, currentPoint.y - pagePoint.y);
-                            [self doMoveLineAnnotation:(CPDFLineAnnotation *)newActiveAnnotation offset:offsetPoint];
-                            pagePoint = currentPoint;
+                            [self doMoveAnnotation:(CPDFLineAnnotation *)newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
+//                            [self doMoveAnnotation:(CPDFLineAnnotation *)newActiveAnnotation withEvent:theEvent offset:offsetPoint];
                             if (isMeasure) {
                                 if (self.pdfListViewDelegate && [self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewAnnotationMeasureInfoChange:withAnnotation:)]) {
                                     [self.pdfListViewDelegate PDFListViewAnnotationMeasureInfoChange:self withAnnotation:newActiveAnnotation];
                                 }
                             }
                         } else if (isPolyline || isPolygon || isSquarePolygon) {
-                            [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent offset:offset];
+                            [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
                             if (isMeasure) {
                                 
                                 if (self.pdfListViewDelegate && [self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewAnnotationMeasureInfoChange:withAnnotation:)]) {
                                     [self.pdfListViewDelegate PDFListViewAnnotationMeasureInfoChange:self withAnnotation:newActiveAnnotation];
                                 }
                             }
-                        } else
-                            [self doMoveAnnotation:newActiveAnnotation withEvent:lastMouseEvent offset:offset];
+                        } else {
+                            [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
+                        }
+                        pagePoint = currentPoint;
                     } else {
                         if (resizeHandle == CEditInEdgeMask) {
                             if(isLine) {
-                                NSPoint currentPoint = NSZeroPoint;
-                                [self pageAndPoint:&currentPoint forEvent:theEvent nearest:YES];
-                                
-                                CGPoint offsetPoint =  CGPointMake(currentPoint.x - pagePoint.x, currentPoint.y - pagePoint.y);
-                                [self doMoveLineAnnotation:(CPDFLineAnnotation *)newActiveAnnotation offset:offsetPoint];
-                                pagePoint = currentPoint;
+                                [self doMoveAnnotation:(CPDFLineAnnotation *)newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
+//                                [self doMoveAnnotation:(CPDFLineAnnotation *)newActiveAnnotation withEvent:theEvent offset:offset];
                                 if (isMeasure) {
                                     if (self.pdfListViewDelegate && [self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewAnnotationMeasureInfoChange:withAnnotation:)]) {
                                         [self.pdfListViewDelegate PDFListViewAnnotationMeasureInfoChange:self withAnnotation:newActiveAnnotation];
                                     }
                                 }
                             } else if (isPolyline || isPolygon || isSquarePolygon) {
-                                [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent offset:offset];
-                                
+                                [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
+
                                 if (isMeasure) {
                                     
                                     if (self.pdfListViewDelegate && [self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewAnnotationMeasureInfoChange:withAnnotation:)]) {
                                         [self.pdfListViewDelegate PDFListViewAnnotationMeasureInfoChange:self withAnnotation:newActiveAnnotation];
                                     }
                                 }
-                            } else
-                                [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent offset:offset];
-                            
+                            } else {
+                                [self doMoveAnnotation:newActiveAnnotation withEvent:theEvent boundOffset:offset offset:offsetPoint];
+                            }
                         } else if (isLine) {
                             if (isMeasure) {
                                 [self doResizeMeasureLineAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalStartPoint:originalStartPoint originalEndPoint:originalEndPoint translatedOriginalStartPoint:translatedOriginalStartPoint translatedOriginalEndPoint:translatedOriginalEndPoint resizeHandle:resizeHandle];

+ 56 - 65
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Tool.m

@@ -419,14 +419,13 @@
     return points;
 }
 
-- (void)dragAnnotationReferenceLine:(CPDFAnnotation *)annotation {
+- (void)dragAnnotationReferenceLine:(CPDFAnnotation *)annotation {    
     [self removeShapeLayer];
     
-    CAnnotationAlignState state = [self isAlignedWithOtherForms:annotation];
-    if (state != CAnnotationAlignStateNone && annotation) {
+    if ([self isAlignedWithOtherForms:annotation] && annotation) {
         CGRect bounds = annotation.bounds;
         NSRect rect = [self convertRect:bounds fromPage:self.currentPage];
-        [self drawLineOfDashByCAShapeLayer:rect withAlignState:state];
+        [self drawLineOfDashByCAShapeLayer:rect];
     }
 }
 
@@ -469,71 +468,63 @@
     }
 }
 
-- (void)drawLineOfDashByCAShapeLayer:(CGRect)frame withAlignState:(CAnnotationAlignState)state {
+- (void)drawLineOfDashByCAShapeLayer:(CGRect)frame {
     NSColor *lineColor = [CPDFListViewConfig defaultManager].dragHoverColor;
     CGFloat lineWidth = [self unitWidthOnPage:self.currentPage];
     
-    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.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 == 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];
-    }
+    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];
 }
 
 - (CAnnotationAlignState)isAlignedWithOtherForms:(CPDFAnnotation *)activeAnnotation {