Ver código fonte

【fix】【手绘】手绘、线条、矩形圆形等注释,Pro上添加,升级到New,切换线段和边框样式,注释直接消失。bug修复

tangchao 10 meses atrás
pai
commit
ce87f9823b

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

@@ -58,6 +58,7 @@ import Foundation
         }
         context.restoreGState()
     }
+    
     @objc 
     func borderRecct(for pdfView: CPDFListView) -> CGRect {
         var rect = pdfView.integralRect(self.bounds, on: self.page)
@@ -99,7 +100,7 @@ import Foundation
             dashPattern.append(5.0)
             dashPattern.append(5.0)
         }
-        let border = CPDFBorder(style: style, lineWidth: oldBorder?.lineWidth ?? 0.0, dashPattern: dashPattern)
+        let border = CPDFBorder(style: style, lineWidth: oldBorder?.lineWidth ?? self.lineWidth(), dashPattern: dashPattern)
         self.border = border
     }
     

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

@@ -58,7 +58,7 @@ import Foundation
         
         bounds = CGRectInset(bounds, lineWidth, lineWidth)
         if (annotationModel.style() == .dashed &&
-            annotationModel.dashPattern != nil) {
+            annotationModel.dashPattern() != nil) {
             let count = annotationModel.dashPattern().count
             var lengths: [CGFloat] = []
             for i in 0 ..< count {

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

@@ -139,7 +139,8 @@ import Foundation
         image?.lockFocus()
         NSGraphicsContext.current?.imageInterpolation = .high
         
-        string.draw(in: NSMakeRect(0, 0, image!.size.width, image!.size.height), withAttributes: attributes)
+        let imageSize = image?.size ?? .zero
+        string.draw(in: NSMakeRect(0, 0, imageSize.width, imageSize.height), withAttributes: attributes)
         NSGraphicsContext.current?.imageInterpolation = .default
         
         image?.unlockFocus()

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

@@ -364,7 +364,7 @@ import Foundation
             }
             _path.transform(using: transform as AffineTransform)
         }
-        return paths as! [Any]
+        return paths as? [Any] ?? []
     }
     
     override func displayRectForBounds(_ bounds: NSRect, lineWidth: CGFloat) -> NSRect {

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

@@ -142,8 +142,8 @@ import Foundation
         }
         context?.setLineWidth(annotationModel.lineWidth())
         
-        startPoint = self._drawLineExEnding(style: annotationModel.startLineStyle(), point: startPoint, cpoint: endPoint, inContext: context!, model: annotationModel)
-        endPoint = self._drawLineExEnding(style: annotationModel.endLineStyle(), point: endPoint, cpoint: startPoint, inContext: context!, model: annotationModel)
+        startPoint = self._drawLineExEnding(style: annotationModel.startLineStyle(), point: startPoint, cpoint: endPoint, inContext: context, model: annotationModel)
+        endPoint = self._drawLineExEnding(style: annotationModel.endLineStyle(), point: endPoint, cpoint: startPoint, inContext: context, model: annotationModel)
         if (annotationModel.style() == .dashed) {
             if let dashPattern = annotationModel.dashPattern(), dashPattern.count > 0 {
                 let count = annotationModel.dashPattern().count
@@ -170,47 +170,47 @@ import Foundation
 // MARK: - Private Methods
 
 extension CPDFLineAnnotation {
-    private class func _drawLineExEnding(style: CPDFLineStyle, point: CGPoint, cpoint: CGPoint, inContext context: CGContext, model annotationModel: CPDFAnnotationModel) -> CGPoint {
+    private class func _drawLineExEnding(style: CPDFLineStyle, point: CGPoint, cpoint: CGPoint, inContext context: CGContext?, model annotationModel: CPDFAnnotationModel) -> CGPoint {
         var rpoint = point
         switch style {
         case .openArrow:
             var points: [CGPoint] = [CGPoint](repeating: CGPointZero, count: 3)
             self._openArrowExPoints(&points, point: point, cpoint: cpoint, borderWidth: annotationModel.lineWidth())
-            context.beginPath()
-            context.addLines(between: points)
-            context.drawPath(using: .stroke)
+            context?.beginPath()
+            context?.addLines(between: points)
+            context?.drawPath(using: .stroke)
             break
         case .closedArrow:
             var points: [CGPoint] = [CGPoint](repeating: CGPointZero, count: 3)
             rpoint = self._closedArrowExPoints(&points, point: point, cpoint: cpoint)
-            context.beginPath()
-            context.addLines(between: points)
-            context.closePath()
-            context.drawPath(using: .fillStroke)
+            context?.beginPath()
+            context?.addLines(between: points)
+            context?.closePath()
+            context?.drawPath(using: .fillStroke)
             break
         case .square:
             var points: [CGPoint] = [CGPoint](repeating: CGPointZero, count: 4)
             rpoint = self._squareExPoints(&points, point: point, cpoint: cpoint, borderWidth: annotationModel.lineWidth())
-            context.beginPath()
-            context.addLines(between: points)
-            context.closePath()
-            context.drawPath(using: .fillStroke)
+            context?.beginPath()
+            context?.addLines(between: points)
+            context?.closePath()
+            context?.drawPath(using: .fillStroke)
             break
         case .circle:
             var points: [CGPoint] = [CGPoint](repeating: CGPointZero, count: 1)
             rpoint = self._circleExPoints(&points, point: point, cpoint: cpoint, borderWidth: annotationModel.lineWidth())
             let radius = sqrt((rpoint.x - points[0].x) * (rpoint.x - points[0].x) + (rpoint.y - points[0].y) * (rpoint.y - points[0].y))
-            context.beginPath()
-            context.addArc(center: points[0], radius: radius, startAngle: 0, endAngle: 2 * Double.pi, clockwise: false)
-            context.closePath()
-            context.drawPath(using: .fillStroke)
+            context?.beginPath()
+            context?.addArc(center: points[0], radius: radius, startAngle: 0, endAngle: 2 * Double.pi, clockwise: false)
+            context?.closePath()
+            context?.drawPath(using: .fillStroke)
         case .diamond:
             var points: [CGPoint] = [CGPoint](repeating: CGPointZero, count: 4)
             rpoint = self._diamondExPoints(&points, point: point, cpoint: cpoint, borderWidth: annotationModel.lineWidth())
-            context.beginPath()
-            context.addLines(between: points)
-            context.closePath()
-            context.drawPath(using: .fillStroke)
+            context?.beginPath()
+            context?.addLines(between: points)
+            context?.closePath()
+            context?.drawPath(using: .fillStroke)
             break
         default:
             break

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

@@ -284,7 +284,8 @@ class CPDFAnnotationMarkupExtraIvars: NSObject {
         image = NSImage(size: size)
         image?.lockFocus()
         NSGraphicsContext.current?.imageInterpolation = .high
-        (string as? NSString)?.draw(in: NSMakeRect(0, 0, image!.size.width, image!.size.height), withAttributes: attributes as? [NSAttributedString.Key : Any])
+        let imageSize = image?.size ?? .zero
+        (string as? NSString)?.draw(in: NSMakeRect(0, 0, imageSize.width, imageSize.height), withAttributes: attributes as? [NSAttributedString.Key : Any])
         NSGraphicsContext.current?.imageInterpolation = .default
         image?.unlockFocus()
         

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

@@ -89,7 +89,7 @@ import Foundation
             outerRect2.size.width = size
             outerRect2.size.height = size
 
-            KMContextSetLineWidth(context!, width)
+            KMContextSetLineWidth(context, width)
             KMContextMoveToPoint(context, CGRectGetMinX(outerRect1), CGRectGetMinY(outerRect1))
             KMContextAddLineToPoint(context, CGRectGetMinX(outerRect1), CGRectGetMaxY(outerRect1))
             KMContextAddLineToPoint(context, CGRectGetMaxX(outerRect1), CGRectGetMaxY(outerRect1))