Browse Source

【OCToSwift】KMOCToolClass

lizhe 1 year ago
parent
commit
db583d0c47

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

@@ -70,9 +70,6 @@
 		8942F80329262B2E00389627 /* KMSideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80229262B2E00389627 /* KMSideViewController.swift */; };
 		8942F80429262B2E00389627 /* KMSideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80229262B2E00389627 /* KMSideViewController.swift */; };
 		8942F80529262B2E00389627 /* KMSideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80229262B2E00389627 /* KMSideViewController.swift */; };
-		8942F80929275CBC00389627 /* KMOCToolClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80829275CBC00389627 /* KMOCToolClass.m */; };
-		8942F80A29275CBC00389627 /* KMOCToolClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80829275CBC00389627 /* KMOCToolClass.m */; };
-		8942F80B29275CBC00389627 /* KMOCToolClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80829275CBC00389627 /* KMOCToolClass.m */; };
 		8942F80E29277BAF00389627 /* NSMenu+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80D29277BAE00389627 /* NSMenu+Category.m */; };
 		8942F80F29277BAF00389627 /* NSMenu+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80D29277BAE00389627 /* NSMenu+Category.m */; };
 		8942F81029277BAF00389627 /* NSMenu+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 8942F80D29277BAE00389627 /* NSMenu+Category.m */; };
@@ -1437,6 +1434,9 @@
 		ADA9102E2A272CEA003352F0 /* KMImageOptimization.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA9102D2A272CEA003352F0 /* KMImageOptimization.swift */; };
 		ADA9102F2A272CEA003352F0 /* KMImageOptimization.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA9102D2A272CEA003352F0 /* KMImageOptimization.swift */; };
 		ADA910302A272CEA003352F0 /* KMImageOptimization.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADA9102D2A272CEA003352F0 /* KMImageOptimization.swift */; };
+		ADAC0DE12AC273D600FD4F52 /* KMOCToolClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAC0DE02AC273D600FD4F52 /* KMOCToolClass.swift */; };
+		ADAC0DE22AC273D600FD4F52 /* KMOCToolClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAC0DE02AC273D600FD4F52 /* KMOCToolClass.swift */; };
+		ADAC0DE32AC273D600FD4F52 /* KMOCToolClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAC0DE02AC273D600FD4F52 /* KMOCToolClass.swift */; };
 		ADB1FE28297006DF00ED072D /* KMBatchWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB1FE26297006DF00ED072D /* KMBatchWindowController.swift */; };
 		ADB1FE29297006DF00ED072D /* KMBatchWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB1FE26297006DF00ED072D /* KMBatchWindowController.swift */; };
 		ADB1FE2A297006DF00ED072D /* KMBatchWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB1FE26297006DF00ED072D /* KMBatchWindowController.swift */; };
@@ -3607,8 +3607,6 @@
 		8942F7F72926089200389627 /* KMSignatureViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMSignatureViewController.xib; sourceTree = "<group>"; };
 		8942F7FE29260EC700389627 /* KMLeftMethodMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMLeftMethodMode.swift; sourceTree = "<group>"; };
 		8942F80229262B2E00389627 /* KMSideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSideViewController.swift; sourceTree = "<group>"; };
-		8942F80729275CBC00389627 /* KMOCToolClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KMOCToolClass.h; sourceTree = "<group>"; };
-		8942F80829275CBC00389627 /* KMOCToolClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KMOCToolClass.m; sourceTree = "<group>"; };
 		8942F80C29277BAE00389627 /* NSMenu+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMenu+Category.h"; sourceTree = "<group>"; };
 		8942F80D29277BAE00389627 /* NSMenu+Category.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMenu+Category.m"; sourceTree = "<group>"; };
 		8942F816292B678100389627 /* KMAnnotationTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMAnnotationTableCellView.swift; sourceTree = "<group>"; };
@@ -4163,6 +4161,7 @@
 		ADA08A8929F21A53009B2A7B /* KMPDFViewAnnotationOnceModeStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMPDFViewAnnotationOnceModeStore.swift; sourceTree = "<group>"; };
 		ADA910292A272CE2003352F0 /* KMEditPDFTextManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMEditPDFTextManager.swift; sourceTree = "<group>"; };
 		ADA9102D2A272CEA003352F0 /* KMImageOptimization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMImageOptimization.swift; sourceTree = "<group>"; };
+		ADAC0DE02AC273D600FD4F52 /* KMOCToolClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMOCToolClass.swift; sourceTree = "<group>"; };
 		ADB1FE26297006DF00ED072D /* KMBatchWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchWindowController.swift; sourceTree = "<group>"; };
 		ADB1FE27297006DF00ED072D /* KMBatchWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMBatchWindowController.xib; sourceTree = "<group>"; };
 		ADB1FE30297008E800ED072D /* KMBatchCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchCollectionView.swift; sourceTree = "<group>"; };
@@ -5256,8 +5255,7 @@
 		8942F80629275C7A00389627 /* OC_Tool */ = {
 			isa = PBXGroup;
 			children = (
-				8942F80729275CBC00389627 /* KMOCToolClass.h */,
-				8942F80829275CBC00389627 /* KMOCToolClass.m */,
+				ADAC0DE02AC273D600FD4F52 /* KMOCToolClass.swift */,
 			);
 			path = OC_Tool;
 			sourceTree = "<group>";
@@ -11262,13 +11260,13 @@
 				9F0CB51D2986569B00007028 /* KMDesignToken+BorderRadiusBottomRight.swift in Sources */,
 				AD8DD2A32A9C35B2007CC9D0 /* KMThumbnailManager.swift in Sources */,
 				F34BF9532953DA91002C25A2 /* NSGeometry+PDFListView.m in Sources */,
+				ADAC0DE12AC273D600FD4F52 /* KMOCToolClass.swift in Sources */,
 				BB86C1FD28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */,
 				BB14702C299DC0D100784A6A /* OIDEndSessionRequest.m in Sources */,
 				9F0CB4A7296CF19600007028 /* KMPropertiesPanelListMenuSubVC.swift in Sources */,
 				BB146FE7299DC0D100784A6A /* GTLRQuery.m in Sources */,
 				BB49ED21293F527700C82CA2 /* KMConvertExcelSettingView.swift in Sources */,
 				BBAFC85829851AF200D0648E /* KMBlankView.m in Sources */,
-				8942F80929275CBC00389627 /* KMOCToolClass.m in Sources */,
 				BB8F4569295ABDC10037EA22 /* KMWatermarkAdjectiveBaseModel.swift in Sources */,
 				9F0CB5392986570600007028 /* KMDesignToken+BoxShadow.swift in Sources */,
 				9F0CB4B52977BC1000007028 /* KMPropertiesPanelPreviewSubVC.swift in Sources */,
@@ -11786,6 +11784,7 @@
 				AD9527BF295294E20039D2BC /* KMPrintPageModel.swift in Sources */,
 				BB8F457B295AFB330037EA22 /* KMHeaderFooterFontInfoView.swift in Sources */,
 				BBB5C80829F4CEE40054F261 /* KMLinkAnnotationPropertyEmptyController.swift in Sources */,
+				ADAC0DE22AC273D600FD4F52 /* KMOCToolClass.swift in Sources */,
 				9FDD0F892952FCC6000C4DAD /* KMCompLightParser.swift in Sources */,
 				BBD1F78C296FACA300343885 /* KMPageEditExtractSettingView.swift in Sources */,
 				ADBC375129CAE27900D93208 /* KMComparativeOutlineRowView.swift in Sources */,
@@ -11961,7 +11960,6 @@
 				F3732324292DFFFE0013862C /* CPDFListView+Extension.m in Sources */,
 				ADB5E5132A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift in Sources */,
 				AD68782229A5FADC005B5210 /* KMLightMemberCache.swift in Sources */,
-				8942F80A29275CBC00389627 /* KMOCToolClass.m in Sources */,
 				AD8F06182999DB5900D93CBC /* KMPrintDrawPage.swift in Sources */,
 				BB147030299DC0D200784A6A /* OIDTokenUtilities.m in Sources */,
 				BB86C21528F560D1005AD968 /* NSGraphics_SKExtensions.m in Sources */,
@@ -12841,7 +12839,6 @@
 				9FBC48BA299B44C600CA39D7 /* KMSecondaryViewController.m in Sources */,
 				AD1CA3F92A05FCB60070541F /* KMAnnotationScreenViewController.swift in Sources */,
 				9F1FE4EC29406E4700E952CA /* NSBezierPath+MCAdditions.m in Sources */,
-				8942F80B29275CBC00389627 /* KMOCToolClass.m in Sources */,
 				9F5664892988B16F00020985 /* KMTextfieldVC.swift in Sources */,
 				BBD1F77E296F9BE000343885 /* KMPageEditSettingBaseWindowController.swift in Sources */,
 				9F080B25298FCB0D00FC27DA /* KMDesignToken+Action.swift in Sources */,
@@ -12957,6 +12954,7 @@
 				ADB1FE8829752F4C00ED072D /* KMBatchWatermarkView.swift in Sources */,
 				BBAFC846298519A500D0648E /* KMFileAttribute.m in Sources */,
 				F37322F8292DF9410013862C /* CSelfSignAnnotation.m in Sources */,
+				ADAC0DE32AC273D600FD4F52 /* KMOCToolClass.swift in Sources */,
 				BB8F457C295AFB330037EA22 /* KMHeaderFooterFontInfoView.swift in Sources */,
 				AD68782329A5FADC005B5210 /* KMLightMemberCache.swift in Sources */,
 				BB8F4584295B0F900037EA22 /* KMHeaderFooterMarginInfoView.swift in Sources */,

+ 0 - 43
PDF Office/PDF Master/Class/PDFWindowController/OC_Tool/KMOCToolClass.h

@@ -1,43 +0,0 @@
-//
-//  KMOCToolClass.h
-//  PDF Master
-//
-//  Created by lxy on 2022/11/18.
-//
-
-#import <Foundation/Foundation.h>
-#import "ComPDFKit/ComPDFKit.h"
-
-struct MwcFlags {
-    unsigned int caseInsensitiveSearch:1;
-    unsigned int wholeWordSearch:1;
-    unsigned int settingUpWindow:1;
-};
-
-@interface KMOCToolClass : NSObject
-
-+ (NSArray *)filterAnnotation:(NSArray *)annotations types:(NSArray *)types;
-
-+ (NSArray *)filterAnnotation:(NSArray *)annotations colors:(NSArray *)color;
-
-+ (NSArray *)filterAnnotation:(NSArray *)annotations authors:(NSArray *)authors;
-
-+ (BOOL)arrayContains:(NSArray *)array annotation:(id)item;
-
-+ (NSInteger)arrayIndexOf:(NSArray *)array annotation:(id)item;
-
-+ (NSString *)exproString:(CPDFAnnotation *)annotation;
-
-+ (NSMutableArray <NSString*>*)scannerCharaterString:(NSString *)string;
-
-+ (NSMutableAttributedString *)getAttributedStringWithSelection:(CPDFSelection *)selection
-                                                        keyword:(NSString *)keyword;
-
-+ (BOOL)wholeWordWithSelection:(CPDFSelection *)selection
-                       keyword:(NSString *)keyword;
-
-+ (NSPredicate *)annotationSortPredicate:(NSArray *)soreArray;
-
-@end
-
-

+ 0 - 211
PDF Office/PDF Master/Class/PDFWindowController/OC_Tool/KMOCToolClass.m

@@ -1,211 +0,0 @@
-//
-//  KMOCToolClass.m
-//  PDF Master
-//
-//  Created by lxy on 2022/11/18.
-//
-
-#import "KMOCToolClass.h"
-
-@implementation KMOCToolClass
-+ (NSArray *)filterAnnotation:(NSArray *)annotations types:(NSArray *)types {
-    NSMutableArray *array = [NSMutableArray arrayWithArray:annotations];
-    NSExpression *leftExpression = [NSExpression expressionForKeyPath:@"type"];
-    NSExpression *rightExpression = [NSExpression expressionForConstantValue:types];
-    NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:leftExpression
-                                                                rightExpression:rightExpression
-                                                                       modifier:NSDirectPredicateModifier
-                                                                           type:NSInPredicateOperatorType
-                                                                        options:NSDiacriticInsensitivePredicateOption];
-    return [array filteredArrayUsingPredicate:predicate];
-}
-
-+ (NSArray *)filterAnnotation:(NSArray *)annotations colors:(NSArray *)colors {
-    NSMutableArray *array = [NSMutableArray arrayWithArray:annotations];
-    if ([array containsObject:[NSColor clearColor]]) {
-        [array removeObject:[NSColor clearColor]];
-    }
-    NSExpression *leftExpression = [NSExpression expressionForKeyPath:@"color"];
-    NSExpression *rightExpression = [NSExpression expressionForConstantValue:colors];
-    NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:leftExpression
-                                                                rightExpression:rightExpression
-                                                                       modifier:NSDirectPredicateModifier
-                                                                           type:NSInPredicateOperatorType
-                                                                        options:NSDiacriticInsensitivePredicateOption];
-    return [array filteredArrayUsingPredicate:predicate];
-}
-
-+ (NSArray *)filterAnnotation:(NSArray *)annotations authors:(NSArray *)authors {
-    NSMutableArray *array = [NSMutableArray arrayWithArray:annotations];
-    NSExpression *leftExpression = [NSExpression expressionForKeyPath:@"userName"];
-    NSExpression *rightExpression = [NSExpression expressionForConstantValue:authors];
-    NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:leftExpression
-                                                                rightExpression:rightExpression
-                                                                       modifier:NSDirectPredicateModifier
-                                                                           type:NSInPredicateOperatorType
-                                                                        options:NSDiacriticInsensitivePredicateOption];
-    return [array filteredArrayUsingPredicate:predicate];
-}
-
-+ (BOOL)arrayContains:(NSArray *)array annotation:(id)item {
-    if (!array || array.count == 0 || !item) {
-        return NO;
-    }
-    return [array containsObject:item];
-}
-
-+ (NSInteger)arrayIndexOf:(NSArray *)array annotation:(id)item {
-    if (!array || array.count == 0 || !item) {
-        return 0;
-    }
-    return [array indexOfObject:item];
-}
-
-+ (NSString *)exproString:(CPDFAnnotation *)annotation {
-    NSString *exproString = @"";
-    if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
-        CPDFPage *page = annotation.page;
-        NSArray *points =  [(CPDFMarkupAnnotation *)annotation quadrilateralPoints];
-        NSInteger count = 4;
-        for (NSUInteger i=0; i+count <= points.count;) {
-            CGPoint ptlt = [points[i++] pointValue];
-            CGPoint ptrt = [points[i++] pointValue];
-            CGPoint ptlb = [points[i++] pointValue];
-            CGPoint ptrb = [points[i++] pointValue];
-            CGRect rect = CGRectMake(ptlb.x, ptlb.y, ptrt.x - ptlb.x, ptrt.y - ptlb.y);
-            NSString *string = [page stringForRect:rect];
-            if (string && string.length >0) {
-                if (exproString) {
-                    exproString = [exproString stringByAppendingString:@"\n"];
-                    exproString = [exproString stringByAppendingString:string];
-                } else {
-                    exproString = string;
-                }
-            }
-        }
-    }
-    return exproString;
-}
-
-+ (NSMutableArray *)scannerCharaterString:(NSString *)string {
-    NSScanner *scanner = [NSScanner scannerWithString:string];
-    NSMutableArray *words = [NSMutableArray array];
-    NSString *word;
-    [scanner setCharactersToBeSkipped:nil];
-    while ([scanner isAtEnd] == NO) {
-        if ('"' == [[scanner string] characterAtIndex:[scanner scanLocation]]) {
-            [scanner setScanLocation:[scanner scanLocation] + 1];
-            if ([scanner scanUpToString:@"\"" intoString:&word])
-                [words addObject:word];
-            if ([scanner isAtEnd] == NO)
-                [scanner setScanLocation:[scanner scanLocation] + 1];
-        } else if ([scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&word]) {
-            [words addObject:word];
-        }
-        [scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL];
-    }
-    return words;
-}
-
-+ (NSMutableAttributedString *)getAttributedStringWithSelection:(CPDFSelection *)selection
-                                                        keyword:(NSString *)keyword
-{
-    CPDFPage * currentPage = selection.page;
-    NSRange range = selection.range;
-    NSUInteger startLocation = 0;
-    NSUInteger maxLocation = 10;
-    NSUInteger maxEndLocation = 50;
-
-    NSInteger keyLocation = 0;
-    if (range.location > maxLocation) {
-        startLocation = range.location - maxLocation;
-        keyLocation = maxLocation;
-    } else {
-        startLocation = 0;
-        keyLocation = range.location;
-    }
-    NSUInteger endLocation = 0;
-    if (range.location + maxEndLocation > currentPage.numberOfCharacters) {
-        endLocation = currentPage.numberOfCharacters;
-    } else {
-        endLocation = range.location + maxEndLocation;
-    }
-    
-    NSMutableAttributedString * attributed  = nil;
-    if (endLocation> startLocation) {
-        NSString * string = [currentPage stringForRange:NSMakeRange(startLocation, endLocation - startLocation)];
-        NSString *currentString = @"...";
-        NSArray *stringArr = [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
-        for (NSString *s in stringArr) {
-            if (s.length == 0)
-                currentString = [currentString stringByAppendingString:@"  "];
-            else
-                currentString = [currentString stringByAppendingString:s];
-        }
-
-        NSRange tRange = NSMakeRange(keyLocation+3, keyword.length);
-        if (tRange.location != NSNotFound) {
-            attributed = [[NSMutableAttributedString alloc] initWithString:currentString];
-            
-            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
-            paragraphStyle.firstLineHeadIndent = 10.0;
-            paragraphStyle.headIndent = 10.0;
-            paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
-            paragraphStyle.lineHeightMultiple = 1.32;
-            NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"SFProText-Regular" size:14.0],NSFontAttributeName,[NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1],NSForegroundColorAttributeName,paragraphStyle,NSParagraphStyleAttributeName,nil];
-            
-            NSRange range = [[attributed string] rangeOfString:[attributed string]];
-            [attributed setAttributes:dic range:range];
-            
-            //hightlight string
-            dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor colorWithRed:1.0 green:0.9 blue:0.0 alpha:1.0],NSBackgroundColorAttributeName,nil];
-            if (attributed.length > tRange.length + tRange.location) {
-                [attributed addAttributes:dic range:tRange];
-            }
-        }
-    }
-    return attributed;
-}
-
-+ (BOOL)wholeWordWithSelection:(CPDFSelection *)selection
-                       keyword:(NSString *)keyword {
-    CPDFPage * currentPage = selection.page;
-    NSRange range = selection.range;
-    NSUInteger startLocation = 0;
-    NSUInteger maxLocation = 10;
-    NSUInteger maxEndLocation = 80;
-    NSInteger keyLocation = 0;
-    if (range.location > maxLocation) {
-        startLocation = range.location - maxLocation;
-        keyLocation = maxLocation;
-    } else {
-        startLocation = 0;
-        keyLocation = range.location;
-    }
-    NSUInteger endLocation = 0;
-    if (range.location + maxEndLocation > currentPage.numberOfCharacters) {
-        endLocation = currentPage.numberOfCharacters;
-    } else {
-        endLocation = range.location + maxEndLocation;
-    }
-    if (endLocation> startLocation) {
-        NSString * string = [currentPage stringForRange:NSMakeRange(startLocation, endLocation - startLocation)];
-        NSString *currentString = @"";
-        NSArray *stringArr = [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
-        for (NSString *s in stringArr) {
-            if (s.length == 0)
-                currentString = [currentString stringByAppendingString:@"  "];
-            else
-                currentString = [currentString stringByAppendingString:s];
-        }
-        
-        char leftChar = [currentString characterAtIndex:keyLocation == 0 ? 0 : keyLocation-1];
-        char rightChar = [currentString characterAtIndex:(keyLocation+keyword.length)];
-        if (leftChar == 32 && rightChar == 32) {
-            return YES;
-        }
-    }
-    return NO;
-}
-
-@end

+ 178 - 0
PDF Office/PDF Master/Class/PDFWindowController/OC_Tool/KMOCToolClass.swift

@@ -0,0 +1,178 @@
+//
+//  KMOCToolClass.swift
+//  PDF Master
+//
+//  Created by lizhe on 2023/9/26.
+//
+
+import Cocoa
+
+struct MwcFlags {
+    var caseInsensitiveSearch: Int = 1
+    var wholeWordSearch: Int = 1
+    var settingUpWindow: Int = 1
+}
+
+
+class KMOCToolClass {
+    class func filterAnnotation(annotations: [Any], types: [Any]) -> [Any] {
+        let array = annotations
+        let leftExpression = NSExpression(forKeyPath: "type")
+        let rightExpression = NSExpression(forConstantValue: types)
+        let predicate = NSComparisonPredicate(
+            leftExpression: leftExpression,
+            rightExpression: rightExpression,
+            modifier: .direct,
+            type: .in,
+            options: .diacriticInsensitive
+        )
+        return (array as NSArray).filtered(using: predicate)
+    }
+    
+    class func filterAnnotation(annotations: [Any], colors: [Any]) -> [Any] {
+        var array = annotations
+        if array.contains(where: { $0 is NSColor && ($0 as! NSColor) == NSColor.clear }) {
+            array.removeAll { $0 is NSColor && ($0 as! NSColor) == NSColor.clear }
+        }
+        let leftExpression = NSExpression(forKeyPath: "color")
+        let rightExpression = NSExpression(forConstantValue: colors)
+        let predicate = NSComparisonPredicate(
+            leftExpression: leftExpression,
+            rightExpression: rightExpression,
+            modifier: .direct,
+            type: .in,
+            options: .diacriticInsensitive
+        )
+        return (array as NSArray).filtered(using: predicate)
+    }
+    
+    class func filterAnnotation(annotations: [Any], authors: [Any]) -> [Any] {
+        let array = annotations
+        let leftExpression = NSExpression(forKeyPath: "userName")
+        let rightExpression = NSExpression(forConstantValue: authors)
+        let predicate = NSComparisonPredicate(
+            leftExpression: leftExpression,
+            rightExpression: rightExpression,
+            modifier: .direct,
+            type: .in,
+            options: .diacriticInsensitive
+        )
+        return (array as NSArray).filtered(using: predicate)
+    }
+    
+    class func arrayContains(array: [Any]?, annotation item: Any?) -> Bool {
+        return array?.contains { $0 as AnyObject === item as AnyObject } ?? false
+    }
+    
+    class func arrayIndexOf<T: Equatable>(array: [T], item: T) -> Int? {
+        guard let index = array.firstIndex(of: item) else {
+            return nil // Return nil to indicate that the item was not found
+        }
+        return index
+    }
+    
+    class func exproString(annotation: CPDFAnnotation) -> String {
+        var exproString = ""
+        
+        if let markupAnnotation = annotation as? CPDFMarkupAnnotation,
+           let page = markupAnnotation.page,
+           let points = markupAnnotation.quadrilateralPoints as? [CGPoint], // Cast to [CGPoint]
+           points.count % 4 == 0 {
+            
+            for i in stride(from: 0, to: points.count, by: 4) {
+                let ptlt = points[i]
+                let ptrt = points[i + 1]
+                let ptlb = points[i + 2]
+                let ptrb = points[i + 3]
+                let rect = CGRect(x: ptlt.x, y: ptlt.y, width: ptrt.x - ptlt.x, height: ptrt.y - ptlt.y)
+                
+                if let string = page.string(for: rect), !string.isEmpty {
+                    if !exproString.isEmpty {
+                        exproString += "\n"
+                    }
+                    exproString += string
+                }
+            }
+        }
+        
+        return exproString
+    }
+    
+    class func getAttributedString(selection: CPDFSelection, keyword: String) -> NSMutableAttributedString {
+        guard let currentPage = selection.page else {
+            return NSMutableAttributedString()
+        }
+        
+        let range = selection.range
+        var startLocation = 0
+        let maxLocation: UInt = 10
+        let maxEndLocation: UInt = 50
+
+        var keyLocation = 0
+        
+        if range.location > maxLocation {
+            startLocation = range.location - Int(maxLocation)
+            keyLocation = Int(maxLocation)
+        } else {
+            startLocation = 0
+            keyLocation = range.location
+        }
+        
+        var endLocation: UInt = 0
+        
+        if range.location + Int(maxEndLocation) > currentPage.numberOfCharacters {
+            endLocation = UInt(currentPage.numberOfCharacters)
+        } else {
+            endLocation = UInt(range.location + Int(maxEndLocation))
+        }
+        
+        var attributed: NSMutableAttributedString = NSMutableAttributedString()
+        
+        if endLocation > UInt(startLocation) {
+            let string = currentPage.string(for: NSRange(location: startLocation, length: Int(endLocation) - startLocation))
+            var currentString = "..."
+            
+            let stringArr = string?.components(separatedBy: CharacterSet.newlines) ?? []
+            
+            for s in stringArr {
+                if s.isEmpty {
+                    currentString += "  "
+                } else {
+                    currentString += s
+                }
+            }
+
+            let tRange = NSRange(location: keyLocation + 3, length: keyword.count)
+            
+            if tRange.location != NSNotFound {
+                attributed = NSMutableAttributedString(string: currentString)
+                
+                let paragraphStyle = NSMutableParagraphStyle()
+                paragraphStyle.firstLineHeadIndent = 10.0
+                paragraphStyle.headIndent = 10.0
+                paragraphStyle.lineBreakMode = .byCharWrapping
+                paragraphStyle.lineHeightMultiple = 1.32
+                
+                let dic: [NSAttributedString.Key: Any] = [
+                    .font: NSFont(name: "SFProText-Regular", size: 14.0)!,
+                    .foregroundColor: NSColor(red: 0.145, green: 0.149, blue: 0.161, alpha: 1),
+                    .paragraphStyle: paragraphStyle
+                ]
+                
+                let fullRange = NSRange(location: 0, length: attributed.length)
+                attributed.setAttributes(dic, range: fullRange)
+                
+                // Highlight string
+                let highlightDic: [NSAttributedString.Key: Any] = [
+                    .backgroundColor: NSColor(red: 1.0, green: 0.9, blue: 0.0, alpha: 1.0)
+                ]
+                
+                if attributed.length > tRange.length + tRange.location {
+                    attributed.addAttributes(highlightDic, range: tRange)
+                }
+            }
+        }
+        
+        return attributed
+    }
+}

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationTool/KMBOTAAnnotationTool.swift

@@ -86,7 +86,7 @@ class KMBOTAAnnotationTool: NSObject {
             if annotation.isKind(of: CPDFMarkupAnnotation.self) {
                 var markupString : String = annotation.contents
                 if markupString.count == 0 {
-                    let exproString = KMOCToolClass.exproString(annotation)!
+                    let exproString = KMOCToolClass.exproString(annotation: annotation)
                     if exproString.count > 0 {
                         markupString = exproString
                     }

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationView/KMAnnotationOutlineView.swift

@@ -154,7 +154,7 @@ extension KMAnnotationOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegat
             if rowView.section != nil {
                 
             } else if rowView.model != nil {
-                if !KMOCToolClass.arrayContains(self.selectItems, annotation: item) ||
+                if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
                     self.selectItems.count == 1 {
                     self.selectItem(item: item as! KMBOTAAnnotationItem)
                 }

+ 4 - 4
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.swift

@@ -146,7 +146,7 @@ extension KMAnnotationViewController {
                 var annotationItemArray: [KMBOTAAnnotationItem] = []
                 let page = self.listView.document.page(at: i)
                 let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
-                var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(page!.annotations,types: types) as! [CPDFAnnotation]
+                var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(annotations: page!.annotations,types: types) as! [CPDFAnnotation]
                 //添加签名注释
                 for annotation in page!.annotations {
                    if annotation.isKind(of: CPDFSignatureAnnotation.self) {
@@ -227,13 +227,13 @@ extension KMAnnotationViewController {
                     if page!.annotations.count > 0 {
                         var filterAnnotations: [CPDFAnnotation] = page!.annotations
                         if typeArr.count > 0 {
-                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations, types: typeArr) as! [CPDFAnnotation])
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations, types: typeArr) as! [CPDFAnnotation])
                         }
                         if (colorArr.count > 0) {
-                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
                         }
                         if (authorArr.count > 0) {
-                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
                         }
                         
                         let section = KMBOTAAnnotationSection()

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMAnnotationTableCellView.swift

@@ -155,7 +155,7 @@ class KMAnnotationTableCellView: NSTableCellView {
         if annotation.isKind(of: CPDFMarkupAnnotation.self) {
             var text : String = annotation.contents
             if text.count == 0 {
-                let exproString = KMOCToolClass.exproString(annotation)!
+                let exproString = KMOCToolClass.exproString(annotation: annotation)
                 if exproString.count > 0 {
                     text = exproString
                 }

+ 3 - 3
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/BookMarks/KMBookMarkViewController.swift

@@ -106,7 +106,7 @@ class KMBookMarkViewController: NSViewController, NSTextFieldDelegate {
 
         _ = self.dataSource.contains { KMBookMarkItem in
             if KMBookMarkItem.bookMark == newBookMark.bookMark {
-                let index = KMOCToolClass.arrayIndex(of: self.dataSource, annotation: KMBookMarkItem)
+                let index = KMOCToolClass.arrayIndexOf(array: self.dataSource, item: KMBookMarkItem) ?? 0
                 self.didSelectItem(row: index, event: NSEvent())
                 self.renameBookWithRow(row: index)
                 return true
@@ -302,7 +302,7 @@ extension KMBookMarkViewController : NSTableViewDelegate,NSTableViewDataSource {
             }
             
             rowView.rightMouseDownAction = { [unowned self] (view, event) in
-                if !KMOCToolClass.arrayContains(self.selectItems, annotation: rowView.model) ||
+                if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: rowView.model) ||
                     self.selectItems.count == 1 {
                     self.selectIndex(index: row)
                 }
@@ -363,7 +363,7 @@ extension KMBookMarkViewController : NSTableViewDelegate,NSTableViewDataSource {
         for model in self.selectItems {
             self.dataSource.contains { KMBookMarkItem in
                 if KMBookMarkItem.bookMark == model.bookMark {
-                    let index = KMOCToolClass.arrayIndex(of: self.dataSource, annotation: KMBookMarkItem)
+                    let index = KMOCToolClass.arrayIndexOf(array: self.dataSource, item: KMBookMarkItem) ?? 0
                     if index != nil {
                         KMBookMarkItem.select = false
                         if self.bookTableView.rowView(atRow: index, makeIfNecessary: false) != nil {

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Outline/OutlineView/KMBOTAOutlineView.swift

@@ -181,7 +181,7 @@ extension KMBOTAOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegate {
         }
         
         rowView.rightMouseCallback = { [unowned self] (view, event) in
-            if !KMOCToolClass.arrayContains(self.selectItems, annotation: item) ||
+            if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
                 self.selectItems!.count == 1 {
                 self.selectItem(outlineItem: item as! KMBOTAOutlineItem)
             }

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -30,7 +30,7 @@ extension KMMainViewController {
                 for selection in selections {
                     let mode : KMSearchMode = KMSearchMode()
                     mode.selection = selection
-                    mode.attributedString = KMOCToolClass.getAttributedString(with: selection, keyword: searchString)
+                    mode.attributedString = KMOCToolClass.getAttributedString(selection: selection, keyword: searchString)
                     mode.selectionPageIndex = self.listView.document.index(for: selection.page)
                     self.searchResults.insert(mode, at: self.searchResults.count)
                 }

+ 0 - 1
PDF Office/PDF Master/PDF_Master-Bridging-Header.h

@@ -9,7 +9,6 @@
 
 #import "KMGOCRManager.h"
 
-#import "KMOCToolClass.h"
 #import "NSMenu+Category.h"
 #import "KMToolbarItem.h"
 #import "NSMenu+Category.h"