Ver código fonte

【OCToSwift】CPDFInkAnnotation+PDFListView

tangchao 1 ano atrás
pai
commit
ecac1a67fb

+ 8 - 10
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -2950,6 +2950,9 @@
 		BBBB6CDA2AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CD92AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift */; };
 		BBBB6CDB2AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CD92AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift */; };
 		BBBB6CDC2AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CD92AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift */; };
+		BBBB6CDE2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CDD2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift */; };
+		BBBB6CDF2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CDD2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift */; };
+		BBBB6CE02AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBB6CDD2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift */; };
 		BBBF68802A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
 		BBBF68812A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
 		BBBF68822A3BF17F0058E14E /* KMFilePromiseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */; };
@@ -3318,9 +3321,6 @@
 		F373230B292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D6292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m */; };
 		F373230C292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D6292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m */; };
 		F373230D292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D6292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m */; };
-		F373230E292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D7292DF9410013862C /* CPDFInkAnnotation+PDFListView.m */; };
-		F373230F292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D7292DF9410013862C /* CPDFInkAnnotation+PDFListView.m */; };
-		F3732310292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D7292DF9410013862C /* CPDFInkAnnotation+PDFListView.m */; };
 		F3732311292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D9292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m */; };
 		F3732312292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D9292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m */; };
 		F3732313292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F37322D9292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m */; };
@@ -4700,6 +4700,7 @@
 		BBBB6CD12AD14A5F0035AA66 /* CPDFChoiceWidgetAnnotation+PDFListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFChoiceWidgetAnnotation+PDFListView.swift"; sourceTree = "<group>"; };
 		BBBB6CD52AD150D20035AA66 /* CPDFCircleAnnotation+PDFListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFCircleAnnotation+PDFListView.swift"; sourceTree = "<group>"; };
 		BBBB6CD92AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFFreeTextAnnotation+PDFListView.swift"; sourceTree = "<group>"; };
+		BBBB6CDD2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFInkAnnotation+PDFListView.swift"; sourceTree = "<group>"; };
 		BBBF687F2A3BF17F0058E14E /* KMFilePromiseProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMFilePromiseProvider.swift; sourceTree = "<group>"; };
 		BBBF68832A3C3AF10058E14E /* NSDocumentController+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSDocumentController+KMExtension.swift"; sourceTree = "<group>"; };
 		BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCropPreviewController.swift; sourceTree = "<group>"; };
@@ -4859,7 +4860,6 @@
 		F37322BE292DF9410013862C /* CPDFTextAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFTextAnnotation+PDFListView.h"; sourceTree = "<group>"; };
 		F37322BF292DF9410013862C /* CPDFAnnotationHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFAnnotationHeader.h; sourceTree = "<group>"; };
 		F37322C0292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFSignatureWidgetAnnotation+PDFListView.h"; sourceTree = "<group>"; };
-		F37322C1292DF9410013862C /* CPDFInkAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFInkAnnotation+PDFListView.h"; sourceTree = "<group>"; };
 		F37322C3292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFTextWidgetAnnotation+PDFListView.h"; sourceTree = "<group>"; };
 		F37322C4292DF9410013862C /* CPDFLineAnnotation+PDFListView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPDFLineAnnotation+PDFListView.h"; sourceTree = "<group>"; };
 		F37322C7292DF9410013862C /* CSelfSignAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSelfSignAnnotation.h; sourceTree = "<group>"; };
@@ -4875,7 +4875,6 @@
 		F37322D4292DF9410013862C /* CPDFSquareAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFSquareAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F37322D5292DF9410013862C /* CPDFLineAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFLineAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F37322D6292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFTextWidgetAnnotation+PDFListView.m"; sourceTree = "<group>"; };
-		F37322D7292DF9410013862C /* CPDFInkAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFInkAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F37322D9292DF9410013862C /* CPDFSignatureWidgetAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFSignatureWidgetAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F37322DA292DF9410013862C /* CPDFTextAnnotation+PDFListView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CPDFTextAnnotation+PDFListView.m"; sourceTree = "<group>"; };
 		F3732321292DFFFE0013862C /* CPDFListView+Extension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPDFListView+Extension.h"; sourceTree = "<group>"; };
@@ -9191,8 +9190,7 @@
 				BBBB6CD12AD14A5F0035AA66 /* CPDFChoiceWidgetAnnotation+PDFListView.swift */,
 				BBBB6CD52AD150D20035AA66 /* CPDFCircleAnnotation+PDFListView.swift */,
 				BBBB6CD92AD15B900035AA66 /* CPDFFreeTextAnnotation+PDFListView.swift */,
-				F37322C1292DF9410013862C /* CPDFInkAnnotation+PDFListView.h */,
-				F37322D7292DF9410013862C /* CPDFInkAnnotation+PDFListView.m */,
+				BBBB6CDD2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift */,
 				F37322C4292DF9410013862C /* CPDFLineAnnotation+PDFListView.h */,
 				F37322D5292DF9410013862C /* CPDFLineAnnotation+PDFListView.m */,
 				F37322BB292DF9410013862C /* CPDFLinkAnnotation+PDFListView.h */,
@@ -10581,7 +10579,6 @@
 				BB89722E294B08DE0045787C /* KMWatermarkViewController.swift in Sources */,
 				89E9B406295D268E00AEFA61 /* KMEditImagePropertyViewController.swift in Sources */,
 				899700F628F4051B009AF911 /* KMAnnotationViewController.swift in Sources */,
-				F373230E292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */,
 				F359916929261F0D000D25DE /* CPDFListView+Tool.m in Sources */,
 				9F3D819329A33A290087B5AD /* KMDesignDropdown.swift in Sources */,
 				9F0CB47F2967F64D00007028 /* KMPropertiesPanelReadOnlySubVC.swift in Sources */,
@@ -10864,6 +10861,7 @@
 				BBD1F798296FF78C00343885 /* KMPageEditSettingBaseModel.swift in Sources */,
 				9FAAA33E290FECA70046FFCE /* NSImage+QuickLook.swift in Sources */,
 				ADE3C1E429A5ABC200793B13 /* KMLoginWindowController.swift in Sources */,
+				BBBB6CDE2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */,
 				9F0CB4D52986551600007028 /* KMDesignToken+Spacing.swift in Sources */,
 				BBBB6CCA2AD109F30035AA66 /* CPDFAnnotation+PDFListView.swift in Sources */,
 				BB0A55102A302DB700B6E84B /* KMTextField.swift in Sources */,
@@ -11418,7 +11416,6 @@
 				9FAAA333290BD0A20046FFCE /* KMHistoryFileCollectionViewItem.swift in Sources */,
 				BB7648ED29ECEEF400931039 /* KMAppearance.swift in Sources */,
 				8997010728F4082C009AF911 /* KMFromViewController.swift in Sources */,
-				F373230F292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */,
 				9F1F82F329373D6E0092C4B4 /* String+KMExtensions.swift in Sources */,
 				F3B7DF9B2948565000333201 /* CPDFListHoverAnnotationViewController.m in Sources */,
 				9FD0FA4C29D43D6800F2AB0D /* KMDeviceBrowserWindowController.swift in Sources */,
@@ -11960,6 +11957,7 @@
 				BBB14A542978DD5400936EDB /* KMRedactTools.swift in Sources */,
 				BB5F8A1229BB04F000365ADB /* GBDeviceInfo_Common.m in Sources */,
 				BBAFC83D2985194800D0648E /* KMPDFEditAppendWindow.m in Sources */,
+				BBBB6CDF2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */,
 				89E4E6F62963D1E9002DBA6F /* KMAnnotationPropertiesColorManager.m in Sources */,
 				BBBB6CCF2AD13E210035AA66 /* CPDFButtonWidgetAnnotation+PDFListView.swift in Sources */,
 				F359916A29261F0E000D25DE /* CPDFListView+Tool.m in Sources */,
@@ -12267,7 +12265,6 @@
 				BB003037298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */,
 				ADB1FE9029752F7000ED072D /* KMBatchBackgroundView.swift in Sources */,
 				BBD7FE062A1323F000F96075 /* KMCustomTableRowView.swift in Sources */,
-				F3732310292DF9410013862C /* CPDFInkAnnotation+PDFListView.m in Sources */,
 				9F0CB4C6298625F400007028 /* NSColor+KMExtensions.swift in Sources */,
 				BBC745F4295F0DD00072C2ED /* KMCropSettingPageSizeView.swift in Sources */,
 				F34BF92329530320002C25A2 /* NSString+PDFListView.m in Sources */,
@@ -12386,6 +12383,7 @@
 				BBEC00DB295C39FD00A26C98 /* KMBatesPropertyInfoController.swift in Sources */,
 				BB0A551A2A3074F400B6E84B /* KMHoverView.swift in Sources */,
 				9F1FE4AA29406E4700E952CA /* CTBrowserWindowController.m in Sources */,
+				BBBB6CE02AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */,
 				ADE3C1AD29A4779E00793B13 /* KMPrintAccessoryController.swift in Sources */,
 				ADC075B829866962006C752F /* KMBatchConverPDFWordView.swift in Sources */,
 				ADEC7A80299397F8009A8256 /* NSFont+SFProText.swift in Sources */,

+ 16 - 0
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -68,5 +68,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "CE1D713A-5ED0-429C-8A71-4266D6188CCA"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFInkAnnotation+PDFListView.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "142"
+            endingLineNumber = "142"
+            landmarkName = "pathsImage(_:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 2 - 1
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -164,7 +164,8 @@ extension NSSharingServicePicker {
     func kmCGPath() -> CGPath {
         let mutablePath = CGMutablePath()
         let numElements = self.elementCount
-        let points: NSPointArray = NSPointArray(bitPattern: 3)!
+//        let points: NSPointArray = NSPointArray(bitPattern: 3)!
+        var points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
         
         for i in 0 ..< numElements {
             switch self.element(at: i, associatedPoints: points) {

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

@@ -121,7 +121,10 @@ import Foundation
     }
     
     func toolTipsString() -> String {
-        return self.contents.isEmpty ? "" : self.contents
+        if let data = self.contents {
+            return data
+        }
+        return ""
     }
 }
 

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotationModel.m

@@ -12,7 +12,6 @@
 
 #import "CPDFAnnotationModel.h"
 
-#import "CPDFInkAnnotation+PDFListView.h"
 #import "CPDFLineAnnotation+PDFListView.h"
 #import "CPDFSquareAnnotation+PDFListView.h"
 #import "CPDFMarkupAnnotation+PDFListView.h"

+ 0 - 27
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFInkAnnotation+PDFListView.h

@@ -1,27 +0,0 @@
-//
-//  CPDFInkAnnotation+PDFListView.h
-//  ComPDFKit
-//
-//  Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
-//
-//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
-//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
-//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
-//  This notice may not be removed from this file.
-//
-
-#import <ComPDFKit/ComPDFKit.h>
-
-@class CPDFAnnotationModel;
-
-@interface CPDFInkAnnotation (PDFListView)
-
-- (id)initPDFListViewNoteWithPaths:(NSArray <NSBezierPath *>*)paths document:(CPDFDocument *)pdfDocument;
-
-+ (void)addPoint:(NSPoint)point toCNotesPath:(NSBezierPath *)path;
-
-+ (NSImage *)annotationImageWithAnnotationModel:(CPDFAnnotationModel *)annotationModel;
-
-//pathsImage
-+ (NSImage *)pathsImage:(CPDFInkAnnotation *)annotation;
-@end

+ 0 - 303
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFInkAnnotation+PDFListView.m

@@ -1,303 +0,0 @@
-//
-//  CPDFInkAnnotation+PDFListView.m
-//  ComPDFKit
-//
-//  Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
-//
-//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
-//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
-//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
-//  This notice may not be removed from this file.
-//
-
-#import "CPDFInkAnnotation+PDFListView.h"
-#import "NSBezierPath+PDFListView.h"
-#import "NSGraphics+PDFListView.h"
-#import "NSGeometry+PDFListView.h"
-#import "CPDFAnnotationModel.h"
-#import <PDF_Master-Swift.h>
-
-@implementation CPDFInkAnnotation (PDFListView)
-
-- (instancetype)initPDFListViewNoteWithDocument:(CPDFDocument *)document{
-    self = [self initWithDocument:document];
-    if (self) {
-        CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:CAnnotationTypeInk];
-        self.color = annotationModel.color;
-        self.border = [[CPDFBorder alloc] initWithStyle:annotationModel.style lineWidth:annotationModel.lineWidth dashPattern:annotationModel.dashPattern];
-        self.opacity = annotationModel.opacity;
-    }
-    return self;
-}
-
-- (id)initPDFListViewNoteWithPaths:(NSArray <NSBezierPath *>*)paths document:(CPDFDocument *)pdfDocument{
-    self = [self initWithDocument:pdfDocument];
-    if (self) {
-        [self setBezierPaths:paths];
-        CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:CAnnotationTypeInk];
-        self.color = annotationModel.color;
-        self.borderWidth = annotationModel.lineWidth;
-        CPDFBorder *cBorder = [[CPDFBorder alloc] initWithStyle:annotationModel.style lineWidth:annotationModel.lineWidth dashPattern:annotationModel.dashPattern];
-        self.border = cBorder;
-        self.opacity = annotationModel.opacity;
-        [self updateAppearanceInkWithIsAdd:NO];
-    }
-    return self;
-}
-
-- (NSSet *)keysForValuesToObserveForUndo {
-    static NSSet *circleKeys = nil;
-    if (circleKeys == nil) {
-        NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] mutableCopy];
-        [mutableKeys addObjectsFromArray:@[CPDFAnnotationPathsKey]];
-        circleKeys = [mutableKeys copy];
-    }
-    return circleKeys;
-}
-
-- (CGFloat)lineWidth {
-    return [self borderWidth];
-}
-
-- (BOOL)isResizable {
-    return YES;
-}
-
-- (BOOL)isMovable {
-    return YES;
-}
-
-+ (void)addPoint:(NSPoint)point toCNotesPath:(NSBezierPath *)path {
-    NSUInteger count = [path elementCount];
-    if (count == 0) {
-        [path moveToPoint:point];
-    } else if (count == 1) {
-        [path lineToPoint:point];
-    } else {
-        NSBezierPathElement elt;
-        NSPoint points[3];
-        NSPoint diff, controlPoint, point0, point1;
-        CGFloat t, dInv, d0, d1;
-        
-        elt = [path elementAtIndex:count - 2 associatedPoints:points];
-        point0 = elt == NSCurveToBezierPathElement ? points[2] : points[0];
-        
-        elt = [path elementAtIndex:count - 1 associatedPoints:points];
-        point1 = elt == NSCurveToBezierPathElement ? points[2] : points[0];
-        
-        diff.x = point.x - point0.x;
-        diff.y = point.y - point0.y;
-        
-        d0 = fabs((point1.x - point0.x) * diff.x + (point1.y - point0.y) * diff.y);
-        d1 = fabs((point.x - point1.x) * diff.x + (point.y - point1.y) * diff.y);
-        dInv = d0 + d1 > 0.0 ? 1.0 / (3.0 * (d0 + d1)) : 0.0;
-        
-        t = d0 * dInv;
-        controlPoint.x = point1.x - t * diff.x;
-        controlPoint.y = point1.y - t * diff.y;
-        
-        if (elt == NSCurveToBezierPathElement) {
-            points[1] = controlPoint;
-            [path setAssociatedPoints:points atIndex:count - 1];
-        } else if (count == 2) {
-            [path removeAllPoints];
-            [path moveToPoint:point0];
-            [path curveToPoint:point1 controlPoint1:point0 controlPoint2:controlPoint];
-        }
-        
-        t = d1 * dInv;
-        controlPoint.x = point1.x + t * diff.x;
-        controlPoint.y = point1.y + t * diff.y;
-        
-        [path curveToPoint:point controlPoint1:controlPoint controlPoint2:point];
-    }
-}
-
-//- (BOOL)hitTest:(NSPoint)point {
-//    if ([super hitTest:point] == NO)
-//        return NO;
-//    
-//    CGFloat delta = fmax(4.0, 0.5 * [self lineWidth]);
-//    for (NSBezierPath *path in [self bezierPaths]) {
-//        if (NSPointInRect(point, NSInsetRect([path nonPDFListViewEmptyBounds], -delta, -delta))) {
-//            NSBezierPathElement elt;
-//            NSPoint prevPoint, nextPoint = NSZeroPoint, points[3];
-//            NSUInteger i, iMax = [path elementCount];
-//            
-//            for (i = 0; i < iMax; i++) {
-//                
-//                prevPoint = nextPoint;
-//                elt = [path elementAtIndex:i associatedPoints:points];
-//                
-//                if (elt == NSCurveToBezierPathElement) {
-//                    NSPoint min = prevPoint, max = prevPoint;
-//                    NSBezierPath *flattenedPath;
-//                    NSUInteger j, jMax;
-//                    
-//                    for (j = 0; j < 3; j++) {
-//                        min.x = fmin(min.x, points[j].x);
-//                        min.y = fmin(min.y, points[j].y);
-//                        max.x = fmax(max.x, points[j].x);
-//                        max.y = fmax(max.y, points[j].y);
-//                    }
-//                    if (point.x < min.x - delta || point.y < min.y - delta || point.x > max.x + delta || point.y > max.y + delta) {
-//                        nextPoint = points[2];
-//                    } else {
-//                        flattenedPath = [NSBezierPath bezierPath];
-//                        [flattenedPath moveToPoint:prevPoint];
-//                        [flattenedPath curveToPoint:points[0] controlPoint1:points[1] controlPoint2:points[2]];
-//                        flattenedPath = [flattenedPath bezierPathByFlatteningPath];
-//                        jMax = [flattenedPath elementCount];
-//                        for (j = 1; j < jMax; j++) {
-//                            prevPoint = nextPoint;
-//                            nextPoint = [flattenedPath associatedPDListViewPointForElementAtIndex:j];
-//                            if (CPDFListViewPointNearLineFromPointToPoint(point, prevPoint, nextPoint, delta))
-//                                return YES;
-//                        }
-//                    }
-//                } else {
-//                    nextPoint = points[0];
-//                    if (elt != NSMoveToBezierPathElement && CPDFListViewPointNearLineFromPointToPoint(point, prevPoint, nextPoint, delta))
-//                        return YES;
-//                }
-//            }
-//        }
-//    }
-//    return NO;
-//}
-
-+ (NSImage *)annotationImageWithAnnotationModel:(CPDFAnnotationModel *)annotationModel{
-    CGRect bounds = annotationModel.annotationImageBounds;
-   NSImage * image = [[NSImage alloc] initWithSize:annotationModel.annotationImageBounds.size];
-    [image lockFocus];
-    [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
-    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-    CGFloat lineWidth = annotationModel.lineWidth;
-    if(annotationModel.annotationType == CAnnotationTypeEraser) {
-        CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0);
-        CGContextSetLineWidth(context, 1.0);
-        CGContextAddArc(context, CGRectGetMidX(bounds), CGRectGetMidY(bounds), lineWidth, 0, M_PI * 2, YES);
-        CGContextSetStrokeColorWithColor(context, [NSColor grayColor].CGColor);
-        CGContextSetFillColorWithColor(context, [NSColor grayColor].CGColor);
-        CGContextFillPath(context);
-        [image unlockFocus];
-    } else {
-        CGFloat width = image.size.width/3.0;
-        CGFloat height = image.size.height/2.0;
-        CGContextMoveToPoint(context, 0, height);
-        CGContextAddCurveToPoint(context,
-                                 width,height+25,
-                                 width*2.0,height-25,
-                                 width*3.0,height);
-        CGContextSetLineWidth(context, annotationModel.lineWidth);
-        NSColor *color = annotationModel.color;
-        CGFloat red,green,blue,alpha;
-        if (color) {
-            [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
-        } else {
-            [[[NSColor whiteColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
-        }
-        NSColor *noteColor = [NSColor colorWithRed:red green:green blue:blue alpha:annotationModel.opacity];
-        CGContextSetStrokeColorWithColor(context, noteColor.CGColor);
-        if (CPDFBorderStyleDashed == annotationModel.style) {
-            NSArray *dashPattern = annotationModel.dashPattern;
-            if (dashPattern.count > 0) {
-                CGFloat lengths[dashPattern.count];
-                for (NSUInteger i=0; i<dashPattern.count; i++) {
-                    lengths[i] = [dashPattern[i] floatValue];
-                }
-                CGContextSetLineDash(context, 0, lengths, dashPattern.count);
-            }
-        }
-        CGContextStrokePath(context);
-        [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationDefault];
-        [image unlockFocus];
-    }
-    return image;
-}
-
-+ (NSImage *)pathsImage:(CPDFInkAnnotation *)annotation {
-    if (annotation == nil) {
-        return nil;
-    }
-    CPDFAnnotationModel *model = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:@[annotation]];
-    CGFloat minX = CGFLOAT_MAX;
-    CGFloat minY = CGFLOAT_MAX;
-    CGFloat maxX = CGFLOAT_MIN;
-    CGFloat maxY = CGFLOAT_MIN;
-    
-    int count = 0;
-    for (int i = 0; i < annotation.paths.count; i++) {
-        NSArray *tempArray = annotation.paths[i];
-        for (int j = 0; j < tempArray.count; j++) {
-            CGPoint point = [tempArray[j] pointValue];
-            //获取最大值和最小值
-            if (point.x < minX) {
-                minX = point.x;
-            }
-            if (point.y < minY) {
-                minY = point.y;
-            }
-            if (point.x > maxX) {
-                maxX = point.x;
-            }
-            if (point.y > maxY) {
-                maxY = point.y;
-            }
-            count ++;
-        }
-    }
-    
-    if (count == 0) {
-        return nil;
-    }
-
-    if (count <= 2) {
-        minX = minX - 10;
-        maxX = maxX + 10;
-        minY = minY - 10;
-        maxY = maxY + 10;
-    }
-
-    minX = minX - model.lineWidth * 2;
-    maxX = maxX + model.lineWidth * 2;
-    minY = minY - model.lineWidth * 2;
-    maxY = maxY + model.lineWidth * 2;
-    
-    NSColor *color = model.color;
-    CGFloat lineWidth = model.lineWidth;
-    BOOL isDashed = model.style == CPDFBorderStyleDashed ? YES : NO;
-    //绘制
-    NSImage *image = [[NSImage alloc] initWithSize:CGSizeMake(maxX - minX, maxY - minY)];
-    [image lockFocus];
-
-    NSBezierPath *path = [NSBezierPath bezierPath];
-    [path removeAllPoints];
-    
-    for (int i = 0; i < annotation.paths.count; i++) {
-        NSArray *tempArray = annotation.paths[i];
-        for (int j = 0; j < tempArray.count; j++) {
-            CGPoint point = [tempArray[j] pointValue];
-            if (i == 0 && j == 0) {
-                [path moveToPoint:point];
-            } else {
-                [path lineToPoint:CGPointMake(point.x - minX, point.y - minY)];
-            }
-        }
-    }
-
-    if (isDashed) {
-        [path setLineDash:(CGFloat[]){5.0, 5.0} count:2 phase:0.0];
-    }
-    [color setStroke];
-    [path setLineWidth: lineWidth];
-    [path stroke];
-    
-    [image unlockFocus];
-    
-    CGImageRef cgImageRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
-    NSImage *finalImage = [[NSImage alloc] initWithCGImage:cgImageRef size:NSZeroSize];
-    return  finalImage;
-}
-
-@end

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

@@ -0,0 +1,249 @@
+//
+//  CPDFInkAnnotation+PDFListView.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/10/7.
+//
+
+import Foundation
+
+@objc extension CPDFInkAnnotation {
+    convenience init(PDFListViewNoteWith document: CPDFDocument) {
+        self.init(document: document)
+        if let model = CPDFAnnotationModel(annotationType: .ink) {
+            self.color = model.color()
+            self.border = CPDFBorder(style: model.style(), lineWidth: model.lineWidth(), dashPattern: model.dashPattern())
+            self.opacity = model.opacity()
+        }
+    }
+    
+    private static var _i_keys: Set<AnyHashable>?
+    override func keysForValuesToObserveForUndo() -> Set<AnyHashable>! {
+        if (CPDFInkAnnotation._i_keys == nil) {
+            CPDFInkAnnotation._i_keys = super.keysForValuesToObserveForUndo()
+            _ = CPDFInkAnnotation._i_keys?.insert(CPDFAnnotationPathsKey)
+        }
+        return CPDFInkAnnotation._i_keys
+    }
+    
+    override func lineWidth() -> CGFloat {
+        return self.borderWidth
+    }
+    
+    override func isResizable() -> Bool {
+        return true
+    }
+    
+    override func isMovable() -> Bool {
+        return true
+    }
+    
+    class func addPoint(_ point: NSPoint, toCNotesPath path: NSBezierPath) {
+        let count = path.elementCount
+        if (count == 0) {
+            path.move(to: point)
+        } else if (count == 1) {
+            path.line(to: point)
+        } else {
+            var elt: NSBezierPath.ElementType?
+            var points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
+            
+            var diff: NSPoint = NSZeroPoint
+            var controlPoint: NSPoint = NSZeroPoint
+            var point0: NSPoint = NSZeroPoint
+            var point1: NSPoint = NSZeroPoint
+            var t: CGFloat = CGFLOAT_MAX
+            var dInv: CGFloat = CGFLOAT_MAX
+            var d0: CGFloat = CGFLOAT_MAX
+            var d1: CGFloat = CGFLOAT_MAX
+            
+            elt = path.element(at: count-2, associatedPoints: points)
+            point0 = elt == .curveTo ? points[2] : points[0]
+            
+            elt = path.element(at: count-1, associatedPoints: points)
+            point1 = elt == .curveTo ? points[2] : points[0]
+            
+            diff.x = point.x - point0.x
+            diff.y = point.y - point0.y
+            
+            d0 = abs((point1.x - point0.x) * diff.x + (point1.y - point0.y) * diff.y);
+            d1 = abs((point.x - point1.x) * diff.x + (point.y - point1.y) * diff.y);
+            dInv = d0 + d1 > 0.0 ? 1.0 / (3.0 * (d0 + d1)) : 0.0;
+            
+            t = d0 * dInv;
+            controlPoint.x = point1.x - t * diff.x;
+            controlPoint.y = point1.y - t * diff.y;
+            
+            if (elt == .curveTo) {
+                points[1] = controlPoint;
+                path.setAssociatedPoints(points, at: count-1)
+            } else if (count == 2) {
+                path.removeAllPoints()
+                path.move(to: point0)
+                path.curve(to: point1, controlPoint1: point0, controlPoint2: controlPoint)
+            }
+            
+            t = d1 * dInv
+            controlPoint.x = point1.x + t * diff.x
+            controlPoint.y = point1.y + t * diff.y
+            
+            path.curve(to: point, controlPoint1: controlPoint, controlPoint2: point)
+        }
+    }
+    
+    class func annotationImage(annotationModel: CPDFAnnotationModel) -> NSImage? {
+        let bounds = annotationModel.annotationImageBounds()
+        let image = NSImage(size: bounds.size)
+        image.lockFocus()
+        NSGraphicsContext.current?.imageInterpolation = .high
+        let context = NSGraphicsContext.current?.cgContext
+        let lineWidth = annotationModel.lineWidth()
+        if (annotationModel.annotationType == .eraser) {
+            context?.setStrokeColor(red: 0, green: 0, blue: 0, alpha: 1.0)
+            context?.setLineWidth(1.0)
+            context?.addArc(center: NSPoint(x: CGRectGetMidX(bounds), y: CGRectGetMidY(bounds)) , radius: lineWidth, startAngle: 0, endAngle: Double.pi * 2, clockwise: true)
+            context?.setStrokeColor(NSColor.gray.cgColor)
+            context?.setFillColor(NSColor.gray.cgColor)
+            context?.fillPath()
+        } else {
+            let width: CGFloat = image.size.width/3.0
+            let height = image.size.height/2.0
+            context?.move(to: CGPoint(x: 0, y: height))
+            context?.addCurve(to: CGPoint(x: width*3, y: height), control1: CGPoint(x: width, y: height+25), control2: CGPoint(x: width*2.0, y: height-25))
+            context?.setLineWidth(annotationModel.lineWidth())
+            let color = annotationModel.color() ?? NSColor.white
+            var red: CGFloat = 0
+            var green: CGFloat = 0
+            var blue: CGFloat = 0
+            var alpha: CGFloat = 0
+            color.usingColorSpaceName(.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
+            let noteColor = NSColor(red: red, green: green, blue: blue, alpha: annotationModel.opacity())
+            context?.setStrokeColor(noteColor.cgColor)
+            if (annotationModel.style() == .dashed) {
+                if let dashPattern = annotationModel.dashPattern(), dashPattern.count > 0 {
+                    let count = annotationModel.dashPattern().count
+                    var lengths: [CGFloat] = []
+                    for i in 0 ..< count {
+                        if let data = annotationModel.dashPattern()[i] as? NSNumber {
+                            lengths.append(CGFloat(data.floatValue))
+                        }
+                    }
+                    context?.setLineDash(phase: 0, lengths: lengths)
+                }
+            }
+            context?.strokePath()
+            NSGraphicsContext.current?.imageInterpolation = .default
+        }
+        image.unlockFocus()
+        return image
+    }
+    
+    class func pathsImage(_ annotation: CPDFInkAnnotation?) -> NSImage? {
+        guard let _anno = annotation else {
+            return nil
+        }
+        
+        guard let model = CPDFAnnotationModel(pdfAnnotations: [_anno]) else {
+            return nil
+        }
+        var minX: CGFloat = CGFLOAT_MAX
+        var minY: CGFloat = CGFLOAT_MAX
+        var maxX: CGFloat = CGFLOAT_MAX
+        var maxY: CGFloat = CGFLOAT_MAX
+        
+        var count = 0
+        for i in 0 ..< _anno.paths.count {
+            let tempArray = _anno.paths[i]
+            for j in 0 ..< tempArray.count {
+                if let data = tempArray[j] as? NSNumber {
+                    let point = data.pointValue
+                    //获取最大值和最小值
+                    if (point.x < minX) {
+                        minX = point.x
+                    }
+                    if (point.y < minY) {
+                        minY = point.y
+                    }
+                    if (point.x > maxX) {
+                        maxX = point.x
+                    }
+                    if (point.y > maxY) {
+                        maxY = point.y
+                    }
+                    count += 1
+                }
+            }
+        }
+        if (count == 0) {
+            return nil
+        }
+        
+        if (count <= 2) {
+            minX = minX - 10
+            maxX = maxX + 10
+            minY = minY - 10
+            maxY = maxY + 10
+        }
+
+        let lineWidth = model.lineWidth()
+        minX = minX - lineWidth * 2.0
+        maxX = maxX + lineWidth * 2.0
+        minY = minY - lineWidth * 2.0
+        maxY = maxY + lineWidth * 2.0
+        
+        let color = model.color()
+        let isDashed = model.style() == .dashed
+        //绘制
+        let image = NSImage(size: CGSizeMake(maxX - minX, maxY - minY))
+        image.lockFocus()
+        
+        let path = NSBezierPath()
+        path.removeAllPoints()
+        
+        for i in 0 ..< _anno.paths.count {
+            let tempArray = _anno.paths[i]
+            for j in 0 ..< tempArray.count {
+                if let data = tempArray[j] as? NSNumber {
+                    let point = data.pointValue
+                    if (i == 0 && j == 0) {
+                        path.move(to: point)
+                    } else {
+                        path.line(to: NSMakePoint(point.x - minX, point.y - minY))
+                    }
+                }
+            }
+        }
+        
+        if (isDashed) {
+            let pattern: [CGFloat] = [5.0, 5.0]
+            path.setLineDash(pattern, count: 2, phase: 0.0)
+        }
+        color?.setStroke()
+        path.lineWidth = lineWidth
+        path.stroke()
+        image.unlockFocus()
+        
+        if let cgImageRef = image.cgImage(forProposedRect: nil, context: nil, hints: nil) {
+            let finalImage = NSImage(cgImage: cgImageRef, size: NSZeroSize)
+            return finalImage
+        }
+        return nil
+    }
+
+    /*
+     - (id)initPDFListViewNoteWithPaths:(NSArray <NSBezierPath *>*)paths document:(CPDFDocument *)pdfDocument{
+         self = [self initWithDocument:pdfDocument];
+         if (self) {
+             [self setBezierPaths:paths];
+             CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:CAnnotationTypeInk];
+             self.color = annotationModel.color;
+             self.borderWidth = annotationModel.lineWidth;
+             CPDFBorder *cBorder = [[CPDFBorder alloc] initWithStyle:annotationModel.style lineWidth:annotationModel.lineWidth dashPattern:annotationModel.dashPattern];
+             self.border = cBorder;
+             self.opacity = annotationModel.opacity;
+             [self updateAppearanceInkWithIsAdd:NO];
+         }
+         return self;
+     }
+     */
+}

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -24,7 +24,6 @@
 #import "CPDFListEditAnnotationViewController.h"
 
 #import "CPDFListView+Extension.h"
-#import "CPDFInkAnnotation+PDFListView.h"
 #import "CPDFLineAnnotation+PDFListView.h"
 #import "CPDFMarkupAnnotation+PDFListView.h"
 #import "CSelfSignAnnotationFreeText.h"

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/ComPDFUIKit.h

@@ -17,7 +17,6 @@
 #import "CPDFAnnotationModel.h"
 #import "ComPDFUIConfig.h"
 
-#import "CPDFInkAnnotation+PDFListView.h"
 #import "CPDFTextAnnotation+PDFListView.h"
 #import "CPDFStampAnnotation+PDFListView.h"
 #import "CPDFLineAnnotation+PDFListView.h"