Browse Source

【OCToSwift】KMDrawView

lizhe 1 year ago
parent
commit
e56475d630

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

@@ -19,9 +19,6 @@
 		8931683A296E436B0073EA59 /* KMSignatureWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316829296E436A0073EA59 /* KMSignatureWindowController.m */; };
 		8931683B296E436B0073EA59 /* KMSignatureWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316829296E436A0073EA59 /* KMSignatureWindowController.m */; };
 		8931683C296E436B0073EA59 /* KMSignatureWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316829296E436A0073EA59 /* KMSignatureWindowController.m */; };
-		89316843296E436B0073EA59 /* KMDrawView.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316831296E436B0073EA59 /* KMDrawView.m */; };
-		89316844296E436B0073EA59 /* KMDrawView.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316831296E436B0073EA59 /* KMDrawView.m */; };
-		89316845296E436B0073EA59 /* KMDrawView.m in Sources */ = {isa = PBXBuildFile; fileRef = 89316831296E436B0073EA59 /* KMDrawView.m */; };
 		8931684C296E436B0073EA59 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 89316836296E436B0073EA59 /* KMSignatureWindowController.xib */; };
 		8931684D296E436B0073EA59 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 89316836296E436B0073EA59 /* KMSignatureWindowController.xib */; };
 		8931684E296E436B0073EA59 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 89316836296E436B0073EA59 /* KMSignatureWindowController.xib */; };
@@ -1858,6 +1855,9 @@
 		ADDEEA662AD3C4BE00EF675D /* KMPDFSignatureImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA652AD3C4BE00EF675D /* KMPDFSignatureImageView.swift */; };
 		ADDEEA672AD3C4BE00EF675D /* KMPDFSignatureImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA652AD3C4BE00EF675D /* KMPDFSignatureImageView.swift */; };
 		ADDEEA682AD3C4BF00EF675D /* KMPDFSignatureImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA652AD3C4BE00EF675D /* KMPDFSignatureImageView.swift */; };
+		ADDEEA6A2AD3CF3A00EF675D /* KMDrawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA692AD3CF3A00EF675D /* KMDrawView.swift */; };
+		ADDEEA6B2AD3CF3A00EF675D /* KMDrawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA692AD3CF3A00EF675D /* KMDrawView.swift */; };
+		ADDEEA6C2AD3CF3A00EF675D /* KMDrawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADDEEA692AD3CF3A00EF675D /* KMDrawView.swift */; };
 		ADE3C19F29A3894900793B13 /* KMSearchTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE3C19E29A3894900793B13 /* KMSearchTableRowView.swift */; };
 		ADE3C1A029A3894900793B13 /* KMSearchTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE3C19E29A3894900793B13 /* KMSearchTableRowView.swift */; };
 		ADE3C1A129A3894900793B13 /* KMSearchTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE3C19E29A3894900793B13 /* KMSearchTableRowView.swift */; };
@@ -3518,8 +3518,6 @@
 		89316829296E436A0073EA59 /* KMSignatureWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMSignatureWindowController.m; sourceTree = "<group>"; };
 		8931682B296E436A0073EA59 /* NSImage+CustomImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+CustomImage.h"; sourceTree = "<group>"; };
 		8931682F296E436B0073EA59 /* KMSignatureWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMSignatureWindowController.h; sourceTree = "<group>"; };
-		89316831296E436B0073EA59 /* KMDrawView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMDrawView.m; sourceTree = "<group>"; };
-		89316833296E436B0073EA59 /* KMDrawView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMDrawView.h; sourceTree = "<group>"; };
 		89316836296E436B0073EA59 /* KMSignatureWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMSignatureWindowController.xib; sourceTree = "<group>"; };
 		8931684F296E45CA0073EA59 /* KMImageAccessoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMImageAccessoryController.h; sourceTree = "<group>"; };
 		89316850296E45CA0073EA59 /* KMImageAccessoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMImageAccessoryController.m; sourceTree = "<group>"; };
@@ -4215,6 +4213,7 @@
 		ADDEEA5D2AD39DC500EF675D /* KMSignatureManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSignatureManager.swift; sourceTree = "<group>"; };
 		ADDEEA612AD3A6E700EF675D /* KMPDFSignatureTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFSignatureTextView.swift; sourceTree = "<group>"; };
 		ADDEEA652AD3C4BE00EF675D /* KMPDFSignatureImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFSignatureImageView.swift; sourceTree = "<group>"; };
+		ADDEEA692AD3CF3A00EF675D /* KMDrawView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMDrawView.swift; sourceTree = "<group>"; };
 		ADE3C19E29A3894900793B13 /* KMSearchTableRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSearchTableRowView.swift; sourceTree = "<group>"; };
 		ADE3C1A929A4779E00793B13 /* KMPrintAccessoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPrintAccessoryController.swift; sourceTree = "<group>"; };
 		ADE3C1AA29A4779E00793B13 /* KMPrintAccessoryController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPrintAccessoryController.xib; sourceTree = "<group>"; };
@@ -5038,8 +5037,7 @@
 				BB7F7BF429AA469F00A3E4E7 /* KMSigntureViewItem.h */,
 				BB7F7BF529AA469F00A3E4E7 /* KMSigntureViewItem.m */,
 				BB7F7BF629AA469F00A3E4E7 /* KMSigntureViewItem.xib */,
-				89316833296E436B0073EA59 /* KMDrawView.h */,
-				89316831296E436B0073EA59 /* KMDrawView.m */,
+				ADDEEA692AD3CF3A00EF675D /* KMDrawView.swift */,
 				ADDEEA652AD3C4BE00EF675D /* KMPDFSignatureImageView.swift */,
 				ADDEEA612AD3A6E700EF675D /* KMPDFSignatureTextView.swift */,
 				ADDEEA592AD399BB00EF675D /* KMSignature.swift */,
@@ -10653,7 +10651,6 @@
 				AD9527EE295578BD0039D2BC /* KMBaseTextFieldPresenter.swift in Sources */,
 				F356720529AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */,
 				F37322F6292DF9410013862C /* CSelfSignAnnotation.m in Sources */,
-				89316843296E436B0073EA59 /* KMDrawView.m in Sources */,
 				BB49ED1D293F4FB200C82CA2 /* KMConvertPPTsSettingView.swift in Sources */,
 				F37322ED292DF9410013862C /* CPDFMarkupAnnotation+PDFListView.m in Sources */,
 				BB146FD2299DC0D100784A6A /* GTLRDateTime.m in Sources */,
@@ -11147,6 +11144,7 @@
 				9F1FE4A229406E4700E952CA /* CTToolbarController.m in Sources */,
 				BB147041299DC0D200784A6A /* OIDClientMetadataParameters.m in Sources */,
 				ADCB98C52924730000B51A03 /* KMBatchProcessingTableViewModel.swift in Sources */,
+				ADDEEA6A2AD3CF3A00EF675D /* KMDrawView.swift in Sources */,
 				BB1A34A8295EA30100B80B3E /* NSBitmapImageRep_SKExtensions.m in Sources */,
 				9F0CB4FD298655F600007028 /* KMDesignToken+BorderColor.swift in Sources */,
 				BBB1A3A629F6B66400E54E47 /* NSPanel+KMExtension.swift in Sources */,
@@ -11458,7 +11456,6 @@
 				AD9527EF295578BD0039D2BC /* KMBaseTextFieldPresenter.swift in Sources */,
 				F356720629AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */,
 				8942F80029260EC700389627 /* KMLeftMethodMode.swift in Sources */,
-				89316844296E436B0073EA59 /* KMDrawView.m in Sources */,
 				BB49ED1E293F4FB200C82CA2 /* KMConvertPPTsSettingView.swift in Sources */,
 				9FA607DA28F8227500B46586 /* KMBox.swift in Sources */,
 				BB146FD3299DC0D100784A6A /* GTLRDateTime.m in Sources */,
@@ -11916,6 +11913,7 @@
 				F35B484C29A4903300756255 /* NSPointerArray+PDFListView.m in Sources */,
 				BBB14A542978DD5400936EDB /* KMRedactTools.swift in Sources */,
 				BB5F8A1229BB04F000365ADB /* GBDeviceInfo_Common.m in Sources */,
+				ADDEEA6B2AD3CF3A00EF675D /* KMDrawView.swift in Sources */,
 				BBAFC83D2985194800D0648E /* KMPDFEditAppendWindow.m in Sources */,
 				BBBB6CDF2AD174080035AA66 /* CPDFInkAnnotation+PDFListView.swift in Sources */,
 				89E4E6F62963D1E9002DBA6F /* KMAnnotationPropertiesColorManager.m in Sources */,
@@ -12457,6 +12455,7 @@
 				BBFE6E89293210AB00142C01 /* KMCompressCellView.swift in Sources */,
 				8931683C296E436B0073EA59 /* KMSignatureWindowController.m in Sources */,
 				BB147040299DC0D200784A6A /* OIDEndSessionResponse.m in Sources */,
+				ADDEEA6C2AD3CF3A00EF675D /* KMDrawView.swift in Sources */,
 				ADE614B729861CCC00F62ED7 /* KMBatchSelectedFilesView.swift in Sources */,
 				9F1F82EC2935D02E0092C4B4 /* KMComboBox.swift in Sources */,
 				8997012128F41AB8009AF911 /* KMLeftSideViewController.swift in Sources */,
@@ -12617,7 +12616,6 @@
 				89D2D2C329495D2100BFF5FE /* KMFormModel.swift in Sources */,
 				BBFE6E67293097A600142C01 /* KMPageRangePickerWindowController.swift in Sources */,
 				BB88E43D294023CB002B3655 /* KMDocumentModel.swift in Sources */,
-				89316845296E436B0073EA59 /* KMDrawView.m in Sources */,
 				BB146FF8299DC0D100784A6A /* OIDAuthorizationService+Mac.m in Sources */,
 				BB897267294C724D0045787C /* KMWatermarkAdjectiveOutsideView.swift in Sources */,
 				AD9527EC2955520C0039D2BC /* KMBaseTextFieldModel.swift in Sources */,

File diff suppressed because it is too large
+ 772 - 3
PDF Office/PDF Master.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist


+ 0 - 40
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMDrawView.h

@@ -1,40 +0,0 @@
-//
-//  KMDrawView.h
-//  PDF Reader
-//
-//  Created by wangshuai on 13-3-12.
-//  Copyright (c) 2013年 zhangjie. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@class KMDrawView;
-
-@protocol KMDrawViewDelegate <NSObject>
-
-@optional
-- (void)drawViewDidFinishTouchMode:(KMDrawView *)view;
-
-@end
-
-@interface KMDrawView : NSView
-
-@property (nonatomic,assign) id<KMDrawViewDelegate> delegate;
-
-@property (nonatomic,retain) NSColor *drawColor;
-@property (nonatomic,retain) NSImage *drawImage;
-@property (nonatomic,assign) float strokeRadius;
-
-@property (nonatomic,assign) BOOL isAcceptsTouch;
-
-@property (nonatomic,retain) NSBezierPath *drawBezierPath;
-
-- (void)clearImage;
-
-- (NSImage *)signatureImage;
-
-@property (nonatomic,copy) void (^changeDrawCallback) (BOOL isTure);
-
-@property (nonatomic,copy) void (^touchEndCallback) (BOOL isClear);
-
-@end

+ 0 - 433
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMDrawView.m

@@ -1,433 +0,0 @@
-//
-//  KMDrawView.m
-//  PDF Reader
-//
-//  Created by lxy on 2023/1/10.
-//
-
-#import "KMDrawView.h"
-
-static NSInteger _index;
-static CGPoint _points[5];
-
-@interface KMDrawView ()
-
-@property (nonatomic,assign) BOOL cursorIsHidden;
-@property (nonatomic,assign) BOOL mouseIsInView;
-
-@property (nonatomic,retain) NSTouch *activeTouch;
-
-@property (nonatomic,retain) NSBezierPath *bezierPath;
-
-@end
-
-@implementation KMDrawView
-
-- (void)dealloc
-{
-    _delegate = nil;
-}
-
-- (id)initWithFrame:(NSRect)frameRect
-{
-    if (self = [super initWithFrame:frameRect]) {
-        self.drawImage = [[NSImage alloc] initWithSize:self.frame.size];
-        self.drawColor = [NSColor colorWithDeviceRed:0 green:0 blue:0 alpha:1];
-        self.strokeRadius = 0.3;
-        
-        _bezierPath = [[NSBezierPath alloc] init];
-        
-        self.wantsLayer = YES;
-        self.layer.borderWidth = 1.0;
-        self.layer.borderColor =[NSColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.05].CGColor;
-
-    }
-    return self;
-}
-
-- (NSBezierPath *)drawBezierPath {
-    _drawBezierPath = _bezierPath;
-    
-    CGRect rect = self.bezierPath.bounds;
-    NSAffineTransform *transform = [NSAffineTransform transform];
-    [transform translateXBy:- rect.origin.x + +self.bezierPath.lineWidth/2.0 yBy:-rect.origin.y + self.bezierPath.lineWidth/2.0];
-    [_drawBezierPath transformUsingAffineTransform:transform];
-    
-    return _drawBezierPath;
-}
-
-/*
- ** - (BOOL) acceptsFirstResponder
- **
- ** Make sure the view will receive
- ** events.
- **
- ** Input: none
- **
- ** Output: YES to accept, NO to reject
- */
-- (BOOL)acceptsFirstResponder
-{
-    return YES;
-}
-
-- (void)setIsAcceptsTouch:(BOOL)isAcceptsTouch
-{
-    _isAcceptsTouch = isAcceptsTouch;
-    
-    // Accept trackpad events
-    [self setAcceptsTouchEvents:isAcceptsTouch];
-    
-    size_t screenHeight = CGDisplayPixelsHigh(CGMainDisplayID());
-    NSRect frameToWindow = [self convertRect:self.bounds toView:nil];
-    NSRect frameToScreen = [self.window convertRectToScreen:frameToWindow];
-    if (isAcceptsTouch) {
-        // If the mouse cursor is not already hidden,
-        if (!self.cursorIsHidden) {
-            frameToScreen.origin.x = frameToScreen.origin.x+5;
-            frameToScreen.origin.y = screenHeight-frameToScreen.origin.y-5;
-            CGWarpMouseCursorPosition(frameToScreen.origin);
-
-            // Detach the mouse cursor from the mouse
-            // hardware so that moving the mouse (or a
-            // single finger) will not move the cursor
-            CGAssociateMouseAndMouseCursorPosition(false);
-            
-            // Hide the mouse cursor
-            [NSCursor hide];
-            
-            // Remember that we detached and hid the
-            // mouse cursor
-            self.cursorIsHidden = YES;
-        }
-    } else {
-        frameToScreen.origin.y = screenHeight-frameToScreen.origin.y;
-        CGWarpMouseCursorPosition(frameToScreen.origin);
-
-        // Attach the mouse cursor to the mouse
-        // hardware so that moving the mouse (or a
-        // single finger) will move the cursor
-        CGAssociateMouseAndMouseCursorPosition(true);
-        
-        // Show the mouse cursor
-        [NSCursor unhide];
-        
-        // Remember that we attached and unhid the
-        // mouse cursor so that the next touch that
-        // begins will detach and hide it
-        self.cursorIsHidden = NO;
-    }
-}
-
-- (void)clearImage
-{
-    self.drawImage = nil;
-    [self.bezierPath removeAllPoints];
-    [self setNeedsDisplay:YES];
-    if (self.touchEndCallback) {
-        self.touchEndCallback(YES);
-    }
-}
-
-- (void)setDrawColor:(NSColor *)drawColor
-{
-    _drawColor = drawColor;
-    [self setNeedsDisplay:YES];
-}
-
-- (void)setStrokeRadius:(float)strokeRadius
-{
-    _strokeRadius = strokeRadius;
-    [self setNeedsDisplay:YES];
-}
-
-
-- (NSImage *)signatureImage {
-    CGRect rect = CGRectZero;
-
-    if (self.bezierPath.empty) {
-        return nil;
-    } else {
-        rect = self.bezierPath.bounds;
-    }
-    
-    CGSize size = CGSizeMake(rect.size.width+self.bezierPath.lineWidth,
-                             rect.size.height+self.bezierPath.lineWidth);
-    //修改崩溃 “签名,触摸板,再选中左下角触摸板,崩溃了”
-    if (size.width <= 0 && size.height <= 0) {
-        return nil;
-    }
-    NSImage *image = [[NSImage alloc] initWithSize:size];
-    [image lockFocus];
-    
-    [self.drawColor set];
-    [self.drawBezierPath setLineWidth:self.strokeRadius * 2];
-    [self.drawBezierPath setLineCapStyle:kCGLineCapRound];
-    [self.drawBezierPath setLineJoinStyle:kCGLineJoinRound];
-    [self.drawBezierPath stroke];
-
-    [image unlockFocus];
-
-    return image;
-}
-
-#pragma mark Draw
-- (void)drawRect:(NSRect)dirtyRect {
-    [super drawRect:dirtyRect];
-    
-    [NSGraphicsContext saveGraphicsState];
-    [[NSColor clearColor] set];
-
-    if (([[self window] firstResponder] == self) && self.mouseIsInView) {
-        NSSetFocusRingStyle(NSFocusRingAbove);
-    }
-    [[NSBezierPath bezierPathWithRect:[self bounds]] fill];
-    
-    [NSGraphicsContext restoreGraphicsState];
-
-    if (self.drawImage) {
-        CGRect imageFrame = [self imageFrameInRect:dirtyRect];
-        [self.drawImage drawInRect:imageFrame];
-    }
-    
-    [self.drawColor set];
-    [self.bezierPath setLineWidth:self.strokeRadius * 2];
-    [self.bezierPath setLineCapStyle:kCGLineCapRound];
-    [self.bezierPath setLineJoinStyle:kCGLineJoinRound];
-    [self.bezierPath stroke];
-}
-
-- (CGRect)imageFrameInRect:(CGRect)rect {
-    CGRect imageRect;
-    if (self.drawImage.size.width < rect.size.width &&
-        self.drawImage.size.height < rect.size.height) {
-        imageRect.origin.x = (rect.size.width-self.drawImage.size.width)/2.0;
-        imageRect.origin.y = (rect.size.height-self.drawImage.size.height)/2.0;
-        imageRect.size = self.drawImage.size;
-    } else {
-        if (self.drawImage.size.width/self.drawImage.size.height >
-            rect.size.width/rect.size.height) {
-            imageRect.size.width = rect.size.width;
-            imageRect.size.height = rect.size.width*self.drawImage.size.height/self.drawImage.size.width;
-        } else {
-            imageRect.size.height = rect.size.height;
-            imageRect.size.width = rect.size.height*self.drawImage.size.width/self.drawImage.size.height;
-        }
-        imageRect.origin.x = (rect.size.width-imageRect.size.width)/2.0;
-        imageRect.origin.y = (rect.size.height-imageRect.size.height)/2.0;
-    }
-    return imageRect;
-}
-
-#pragma mark Touch
-
-- (void)touchesBeganWithEvent:(NSEvent *)event
-{
-    [super touchesBeganWithEvent:event];
-    
-    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:self];
-    self.activeTouch = [touches anyObject];
-    
-    CGPoint point = [self.activeTouch normalizedPosition];
-    point.x = point.x * self.bounds.size.width;
-    point.y = point.y * self.bounds.size.height;
-    _index = 0;
-    _points[0] = point;
-    [self setNeedsDisplay:YES];
-    
-    if (!self.cursorIsHidden) {
-        CGAssociateMouseAndMouseCursorPosition(false);
-        
-        [NSCursor hide];
-        self.cursorIsHidden = YES;
-    }
-    
-    if (self.changeDrawCallback) {
-        self.changeDrawCallback(YES);
-    }
-}
-
-- (void)touchesMovedWithEvent:(NSEvent *)event
-{
-    [super touchesMovedWithEvent:event];
-    
-    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:self];
-    
-    BOOL isTouch = NO;
-    for (NSTouch *touch in touches) {
-        if (touch.identity == self.activeTouch.identity) {
-            isTouch = YES;
-            self.activeTouch = touch;
-        }
-    }
-    
-    if (!isTouch) {
-        return;
-    }
-    
-    NSPoint point = [self.activeTouch normalizedPosition];
-    point.x = point.x * self.bounds.size.width;
-    point.y = point.y * self.bounds.size.height;
-    
-    _index++;
-    _points[_index] = point;
-    
-    if (_index == 4) {
-        _points[3] = CGPointMake((_points[2].x + _points[4].x)/2.0,
-                                 (_points[2].y + _points[4].y)/2.0);
-        [self.bezierPath moveToPoint:_points[0]];
-        
-        [self.bezierPath curveToPoint:_points[3]
-                        controlPoint1:_points[1]
-                        controlPoint2:_points[2] ];
-        _points[0] = _points[3];
-        _points[1] = _points[4];
-        _index = 1;
-        [self setNeedsDisplay:YES];
-    }
-}
-
-- (void)touchesEndedWithEvent:(NSEvent *)event
-{
-    [super touchesEndedWithEvent:event];
-    
-    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:self];
-    
-    for (NSTouch *touch in touches) {
-        if (touch.identity == self.activeTouch.identity) {
-            self.activeTouch = nil;
-        }
-    }
-    
-    if (_index < 4) {
-        for (int i=0; i<_index; i++) {
-            [self.bezierPath moveToPoint:_points[i]];
-        }
-        [self setNeedsDisplay:YES];
-    }
-    
-//    NSImage *image = [self signatureImage];
-//    if (self.changeDrawCallback) {
-//        self.changeDrawCallback(image);
-//    }
-    if (self.touchEndCallback) {
-        self.touchEndCallback(NO);
-    }
-}
-
-- (void)touchesCancelledWithEvent:(NSEvent *)event
-{
-    [super touchesCancelledWithEvent:event];
-    
-    for (int i=0; i<_index; i++) {
-        [self.bezierPath moveToPoint:_points[i]];
-    }
-    self.activeTouch = nil;
-    [self setNeedsDisplay:YES];
-}
-
-#pragma mark Mouse
-- (void)viewDidMoveToWindow
-{
-    if ([self window] != nil) {
-        [self addTrackingRect:[self bounds]
-                        owner:self
-                     userData:NULL
-                 assumeInside:NO];
-    }
-}
-
-- (void)mouseEntered:(NSEvent *)theEvent
-{
-    [[self window] makeFirstResponder:self];
-
-//    self.mouseIsInView = YES;
-    [self setNeedsDisplay:YES];
-}
-
-- (void)mouseExited:(NSEvent *)theEvent
-{
-//    self.mouseIsInView = NO;
-    
-    [self setNeedsDisplay:YES];
-}
-
-- (void)mouseDown:(NSEvent *)theEvent
-{
-    if ([self acceptsTouchEvents]) {
-        return;
-    }
-
-    CGPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
-    _index = 0;
-    _points[0] = point;
-}
-
-- (void)mouseDragged:(NSEvent *)theEvent
-{
-    if ([self acceptsTouchEvents]) {
-        return;
-    }
-    
-    NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
-    
-    _index++;
-    _points[_index] = point;
-
-    if (_index == 4) {
-        _points[3] = CGPointMake((_points[2].x + _points[4].x)/2.0,
-                                 (_points[2].y + _points[4].y)/2.0);
-        [self.bezierPath moveToPoint:_points[0]];
-        
-        [self.bezierPath curveToPoint:_points[3]
-                        controlPoint1:_points[1]
-                        controlPoint2:_points[2] ];
-        _points[0] = _points[3];
-        _points[1] = _points[4];
-        _index = 1;
-        [self setNeedsDisplay:YES];
-        
-        if (self.changeDrawCallback) {
-            self.changeDrawCallback(YES);
-        }
-    }
-}
-
-- (void)mouseUp:(NSEvent *)theEvent
-{
-    if ([self acceptsTouchEvents]) {
-        return;
-    }
-    
-    if (_index < 4) {
-        for (int i=0; i<_index; i++) {
-            [self.bezierPath moveToPoint:_points[i]];
-        }
-        [self setNeedsDisplay:YES];
-    }
-    if (self.touchEndCallback) {
-        self.touchEndCallback(NO);
-    }
-}
-
-- (void)keyDown:(NSEvent *)theEvent
-{
-    NSString *chars = [theEvent characters];
-    if(chars.length > 0) {
-        unichar character = [chars characterAtIndex:0];
-        
-//        if (character == 27) {
-            if (self.isAcceptsTouch) {
-                self.isAcceptsTouch = NO;
-                if ([self.delegate respondsToSelector:@selector(drawViewDidFinishTouchMode:)]) {
-                    [self.delegate drawViewDidFinishTouchMode:self];
-                }
-                return;
-            }
-//        }
-    }
-    
-    [super keyDown:theEvent];
-}
-
-@end

+ 245 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMDrawView.swift

@@ -0,0 +1,245 @@
+//
+//  KMDrawView.swift
+//  PDF Master
+//
+//  Created by lizhe on 2023/10/9.
+//
+
+import Cocoa
+
+private var _index: Int = 0
+private var _points: [CGPoint] = [CGPoint](repeating: .zero, count: 5)
+
+@objc protocol KMDrawViewDelegate: NSObjectProtocol {
+    func drawViewDidFinishTouchMode(_ drawView: KMDrawView)
+}
+
+@objcMembers class KMDrawView: NSView {
+    private var drawImage: NSImage?
+    var drawColor: NSColor = NSColor(red: 0, green: 0, blue: 0, alpha: 1) {
+        didSet {
+            self.needsDisplay = true
+        }
+    }
+    var strokeRadius: CGFloat = 0.3 {
+        didSet {
+            self.needsDisplay = true
+        }
+    }
+    private var bezierPath: NSBezierPath = NSBezierPath()
+    var isAcceptsTouch: Bool = false
+    private var cursorIsHidden: Bool = false
+    private var mouseIsInView: Bool = false
+    private var activeTouch: NSTouch?
+    
+    weak var delegate: KMDrawViewDelegate?
+    
+    var drawBezierPath: NSBezierPath {
+        return bezierPath
+    }
+    
+    var touchEndCallback: ((Bool) -> Void)?
+    var changeDrawCallback: ((Bool) -> Void)?
+    
+//    override func acceptsFirstResponder() -> Bool {
+//        return true
+//    }
+    
+    override init(frame frameRect: NSRect) {
+        super.init(frame: frameRect)
+        
+        self.drawImage = NSImage(size: self.frame.size)
+        self.drawColor = NSColor(red: 0, green: 0, blue: 0, alpha: 1)
+        self.strokeRadius = 0.3
+        
+        self.wantsLayer = true
+        self.layer?.borderWidth = 1.0
+        self.layer?.borderColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.05).cgColor
+    }
+    
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    
+    func clearImage() {
+        self.drawImage = nil
+        self.bezierPath.removeAllPoints()
+        self.needsDisplay = true
+        if let touchEndCallback = self.touchEndCallback {
+            touchEndCallback(true)
+        }
+    }
+    
+    func signatureImage() -> NSImage? {
+        var rect = CGRect.zero
+        
+        if bezierPath.isEmpty {
+            return nil
+        } else {
+            rect = bezierPath.bounds
+        }
+        
+        let size = CGSize(width: rect.size.width + bezierPath.lineWidth,
+                          height: rect.size.height + bezierPath.lineWidth)
+        
+        if size.width <= 0 && size.height <= 0 {
+            return nil
+        }
+        
+        let image = NSImage(size: size)
+        image.lockFocus()
+        
+        drawColor.set()
+        drawBezierPath.lineWidth = strokeRadius * 2
+        drawBezierPath.lineCapStyle = .round
+        drawBezierPath.lineJoinStyle = .round
+        drawBezierPath.stroke()
+        
+        image.unlockFocus()
+        
+        return image
+    }
+    
+    override func draw(_ dirtyRect: NSRect) {
+        super.draw(dirtyRect)
+
+        NSGraphicsContext.saveGraphicsState()
+        NSColor.clear.set()
+
+        if window?.firstResponder == self && mouseIsInView {
+            focusRingType = .`default`
+        }
+        
+        NSBezierPath(rect: bounds).fill()
+        
+        NSGraphicsContext.restoreGraphicsState()
+
+        if let drawImage = self.drawImage {
+            let imageFrame = imageFrameInRect(rect: dirtyRect)
+            drawImage.draw(in: imageFrame)
+        }
+
+        drawColor.set()
+        bezierPath.lineWidth = strokeRadius * 2
+        bezierPath.lineCapStyle = .round
+        bezierPath.lineJoinStyle = .round
+        bezierPath.stroke()
+    }
+
+    
+    private func imageFrameInRect(rect: CGRect) -> CGRect {
+        var originX: CGFloat
+        var originY: CGFloat
+        var width: CGFloat
+        var height: CGFloat
+        
+        if drawImage?.size.width ?? 0 < rect.size.width &&
+           drawImage?.size.height ?? 0 < rect.size.height {
+            originX = (rect.size.width - (drawImage?.size.width ?? 0)) / 2.0
+            originY = (rect.size.height - (drawImage?.size.height ?? 0)) / 2.0
+            width = drawImage?.size.width ?? 0
+            height = drawImage?.size.height ?? 0
+        } else {
+            if (drawImage?.size.width ?? 0) / (drawImage?.size.height ?? 0) >
+                rect.size.width / rect.size.height {
+                width = rect.size.width
+                height = (rect.size.width * (drawImage?.size.height ?? 0)) / (drawImage?.size.width ?? 0)
+            } else {
+                height = rect.size.height
+                width = (rect.size.height * (drawImage?.size.width ?? 0)) / (drawImage?.size.height ?? 0)
+            }
+            originX = (rect.size.width - width) / 2.0
+            originY = (rect.size.height - height) / 2.0
+        }
+        
+        let rect = CGRectMake(originX, originY, width, height)
+        
+        return rect
+    }
+    
+    override func viewDidMoveToWindow() {
+        if window != nil {
+            addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false)
+        }
+    }
+    
+    override func mouseEntered(with event: NSEvent) {
+        window?.makeFirstResponder(self)
+        // self.mouseIsInView = true
+        needsDisplay = true
+    }
+    
+    override func mouseExited(with event: NSEvent) {
+        // self.mouseIsInView = false
+        needsDisplay = true
+    }
+    
+    override func mouseDown(with event: NSEvent) {
+        if acceptsTouchEvents {
+            return
+        }
+        
+        let point = convert(event.locationInWindow, from: nil)
+        _index = 0
+        _points[0] = point
+    }
+    
+    override func mouseDragged(with event: NSEvent) {
+        if acceptsTouchEvents {
+            return
+        }
+        
+        let point = convert(event.locationInWindow, from: nil)
+        _index += 1
+        _points[_index] = point
+        
+        if _index == 4 {
+            _points[3] = CGPoint(x: (_points[2].x + _points[4].x) / 2.0,
+                                 y: (_points[2].y + _points[4].y) / 2.0)
+            bezierPath.move(to: _points[0])
+            bezierPath.curve(to: _points[3], controlPoint1: _points[1], controlPoint2: _points[2])
+            _points[0] = _points[3]
+            _points[1] = _points[4]
+            _index = 1
+            needsDisplay = true
+            
+            if let changeDrawCallback = self.changeDrawCallback {
+                changeDrawCallback(true)
+            }
+        }
+    }
+    
+    override func mouseUp(with event: NSEvent) {
+        if acceptsTouchEvents {
+            return
+        }
+        
+        if _index < 4 {
+            for i in 0..<_index {
+                bezierPath.move(to: _points[i])
+            }
+            needsDisplay = true
+        }
+        
+        if let touchEndCallback = self.touchEndCallback {
+            touchEndCallback(false)
+        }
+    }
+    
+    override func keyDown(with event: NSEvent) {
+        if let characters = event.characters, characters.count > 0 {
+            let character = characters.first!
+            // if character == "\u{1B}" { // Check for the Escape key
+            if isAcceptsTouch {
+                isAcceptsTouch = false
+                if let delegate = self.delegate {
+                    delegate.drawViewDidFinishTouchMode(self)
+                }
+                return
+            }
+            // }
+        }
+        
+        super.keyDown(with: event)
+    }
+}

+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMPDFSignatureImageView.swift

@@ -41,6 +41,10 @@ let KMSignatureMaxHeight = 300.0
         layer?.backgroundColor = NSColor(red: 1, green: 1, blue: 1, alpha: 0.9).cgColor
         registerForDraggedTypes([.fileURL])
     }
+    
+    override init(frame frameRect: NSRect) {
+        super.init(frame: frameRect)
+    }
 
     override func awakeFromNib() {
         super.awakeFromNib()

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMSignatureWindowController.m

@@ -7,7 +7,6 @@
 //
 
 #import "KMSignatureWindowController.h"
-#import "KMDrawView.h"
 #import "NSImage+CustomImage.h"
 #import "KMPopUpButton.h"
 #import "CPDFListView.h"

+ 8 - 7
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMSignatureWindowController.xib

@@ -34,7 +34,7 @@
                 <outlet property="keyboardColorBtn4" destination="kZy-e9-ulI" id="rNV-zO-koV"/>
                 <outlet property="keyboardColorSelView" destination="6Ca-vS-p1m" id="Efb-U6-4K4"/>
                 <outlet property="keyboardView" destination="y6e-Mr-PoK" id="3bq-wa-eTs"/>
-                <outlet property="pictureBackView" destination="fH0-Z8-dC3" id="2KK-mq-EhE"/>
+                <outlet property="pictureBackView" destination="fH0-Z8-dC3" id="oxy-hk-0eU"/>
                 <outlet property="pictureButton" destination="zDE-1j-UZ0" id="evZ-1X-Twm"/>
                 <outlet property="pictureClearBackBtn" destination="0Ld-zN-h2r" id="RwN-eb-dDN"/>
                 <outlet property="pictureHelpButton" destination="zHh-uI-saB" id="qxg-kU-mtE"/>
@@ -360,15 +360,15 @@ Gw
             <rect key="frame" x="0.0" y="0.0" width="468" height="230"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <customView translatesAutoresizingMaskIntoConstraints="NO" id="y6e-Mr-PoK" customClass="KMPDFSignatureTextView">
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="y6e-Mr-PoK" customClass="KMPDFSignatureTextView" customModule="PDF_Master" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="48" width="468" height="182"/>
                     <subviews>
-                        <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4mg-CI-O88" customClass="KMSignayureTextField">
+                        <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4mg-CI-O88" customClass="KMSignayureTextField" customModule="PDF_Master" customModuleProvider="target">
                             <rect key="frame" x="182" y="83" width="104" height="17"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="100" id="PKU-Zg-SXA"/>
                             </constraints>
-                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" focusRingType="none" alignment="center" placeholderString="Sign Here" id="n2U-Jv-ECn" customClass="KMVerticallyCenteredSecureTextFieldCell">
+                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" focusRingType="none" alignment="center" placeholderString="Sign Here" id="n2U-Jv-ECn" customClass="KMVerticallyCenteredSecureTextFieldCell" customModule="PDF_Master" customModuleProvider="target">
                                 <font key="font" metaFont="system" size="14"/>
                                 <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                 <color key="backgroundColor" white="1" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -398,7 +398,8 @@ Gw
                     </constraints>
                     <connections>
                         <outlet property="labelWidthLayoutConstraint" destination="PKU-Zg-SXA" id="Dy4-cC-pYh"/>
-                        <outlet property="nameTextFiled" destination="4mg-CI-O88" id="YF4-Za-aOC"/>
+                        <outlet property="nameTextFiled" destination="4mg-CI-O88" id="0XP-nb-DvD"/>
+                        <outlet property="verticalLineBox" destination="3GF-Y1-2QB" id="n6y-zc-TP9"/>
                     </connections>
                 </customView>
                 <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="OX0-YE-NCd">
@@ -521,7 +522,7 @@ Gw
             <rect key="frame" x="0.0" y="0.0" width="468" height="230"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <customView translatesAutoresizingMaskIntoConstraints="NO" id="I2h-gk-zBq" customClass="KMDrawView">
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="I2h-gk-zBq" customClass="KMDrawView" customModule="PDF_Master" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="48" width="468" height="182"/>
                 </customView>
                 <button focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="pqR-eZ-KlX">
@@ -681,7 +682,7 @@ Gw
             <rect key="frame" x="0.0" y="0.0" width="468" height="230"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <customView translatesAutoresizingMaskIntoConstraints="NO" id="fH0-Z8-dC3" customClass="KMPDFSignatureImageView">
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="fH0-Z8-dC3" customClass="KMPDFSignatureImageView" customModule="PDF_Master" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="48" width="468" height="182"/>
                     <subviews>
                         <customView translatesAutoresizingMaskIntoConstraints="NO" id="Z9Y-kq-Z1X">