Quellcode durchsuchen

【OCToSwift】NSDocument+KMExtension

tangchao vor 1 Jahr
Ursprung
Commit
6f94cd67f0

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

@@ -2005,9 +2005,6 @@
 		BB003035298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB003034298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift */; };
 		BB003036298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB003034298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift */; };
 		BB003037298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB003034298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift */; };
-		BB02D61E2A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */; };
-		BB02D61F2A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */; };
-		BB02D6202A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */; };
 		BB0542152965705D00F2665C /* KMCropTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0542142965705D00F2665C /* KMCropTipView.swift */; };
 		BB0542162965705D00F2665C /* KMCropTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0542142965705D00F2665C /* KMCropTipView.swift */; };
 		BB0542172965705D00F2665C /* KMCropTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0542142965705D00F2665C /* KMCropTipView.swift */; };
@@ -2293,6 +2290,9 @@
 		BB3198122AC5142900107371 /* NSMenu+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198112AC5142900107371 /* NSMenu+KMExtension.swift */; };
 		BB3198132AC5142900107371 /* NSMenu+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198112AC5142900107371 /* NSMenu+KMExtension.swift */; };
 		BB3198142AC5142900107371 /* NSMenu+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198112AC5142900107371 /* NSMenu+KMExtension.swift */; };
+		BB3198162AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198152AC55E6D00107371 /* CPDFDocument+KMExtension.swift */; };
+		BB3198172AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198152AC55E6D00107371 /* CPDFDocument+KMExtension.swift */; };
+		BB3198182AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3198152AC55E6D00107371 /* CPDFDocument+KMExtension.swift */; };
 		BB32BF232A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
 		BB32BF242A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
 		BB32BF252A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
@@ -2571,9 +2571,6 @@
 		BB86C1F228F54535005AD968 /* CPDFListView+KeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1F128F54535005AD968 /* CPDFListView+KeyEvent.m */; };
 		BB86C1F328F54535005AD968 /* CPDFListView+KeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1F128F54535005AD968 /* CPDFListView+KeyEvent.m */; };
 		BB86C1F428F54535005AD968 /* CPDFListView+KeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1F128F54535005AD968 /* CPDFListView+KeyEvent.m */; };
-		BB86C1FD28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1FB28F54923005AD968 /* NSEvent_SKExtensions.m */; };
-		BB86C1FE28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1FB28F54923005AD968 /* NSEvent_SKExtensions.m */; };
-		BB86C1FF28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = BB86C1FB28F54923005AD968 /* NSEvent_SKExtensions.m */; };
 		BB88401E2A132C6B0062446B /* ObjectiveDropboxOfficial.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBB9B335299A5F35004F3235 /* ObjectiveDropboxOfficial.framework */; };
 		BB88401F2A132C6B0062446B /* ObjectiveDropboxOfficial.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BBB9B335299A5F35004F3235 /* ObjectiveDropboxOfficial.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		BB88E43B294023CB002B3655 /* KMDocumentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB88E43A294023CB002B3655 /* KMDocumentModel.swift */; };
@@ -4285,8 +4282,6 @@
 		BB00302C298D315E002DD1A0 /* KMPreferenceMarkupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPreferenceMarkupController.swift; sourceTree = "<group>"; };
 		BB00302D298D315E002DD1A0 /* KMPreferenceMarkupController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPreferenceMarkupController.xib; sourceTree = "<group>"; };
 		BB003034298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPreferenceMarkupColorView.swift; sourceTree = "<group>"; };
-		BB02D61C2A56AB9E00114991 /* CPDFDocument+KMExtension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPDFDocument+KMExtension.h"; sourceTree = "<group>"; };
-		BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CPDFDocument+KMExtension.m"; sourceTree = "<group>"; };
 		BB0542142965705D00F2665C /* KMCropTipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCropTipView.swift; sourceTree = "<group>"; };
 		BB0A550F2A302DB700B6E84B /* KMTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMTextField.swift; sourceTree = "<group>"; };
 		BB0A55132A3052F800B6E84B /* KMCustomTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCustomTextField.swift; sourceTree = "<group>"; };
@@ -4453,6 +4448,7 @@
 		BB2F61562966B69D001CB369 /* KMWatermarkPropertyHomeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMWatermarkPropertyHomeController.swift; sourceTree = "<group>"; };
 		BB2F61572966B69D001CB369 /* KMWatermarkPropertyHomeController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMWatermarkPropertyHomeController.xib; sourceTree = "<group>"; };
 		BB3198112AC5142900107371 /* NSMenu+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMenu+KMExtension.swift"; sourceTree = "<group>"; };
+		BB3198152AC55E6D00107371 /* CPDFDocument+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CPDFDocument+KMExtension.swift"; sourceTree = "<group>"; };
 		BB32BF222A5EA05900D11348 /* KMAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMAnalytics.swift; sourceTree = "<group>"; };
 		BB332D522995D8B500CABB58 /* KMCloudDocumentTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCloudDocumentTools.swift; sourceTree = "<group>"; };
 		BB35C4972974E18C00D46EE2 /* CustomAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAlertView.h; sourceTree = "<group>"; };
@@ -4564,8 +4560,6 @@
 		BB86C1EC28F544F4005AD968 /* CPDFListView+Event.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CPDFListView+Event.m"; sourceTree = "<group>"; };
 		BB86C1F028F54535005AD968 /* CPDFListView+KeyEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPDFListView+KeyEvent.h"; sourceTree = "<group>"; };
 		BB86C1F128F54535005AD968 /* CPDFListView+KeyEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CPDFListView+KeyEvent.m"; sourceTree = "<group>"; };
-		BB86C1FB28F54923005AD968 /* NSEvent_SKExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSEvent_SKExtensions.m; sourceTree = "<group>"; };
-		BB86C1FC28F54923005AD968 /* NSEvent_SKExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSEvent_SKExtensions.h; sourceTree = "<group>"; };
 		BB88E43A294023CB002B3655 /* KMDocumentModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMDocumentModel.swift; sourceTree = "<group>"; };
 		BB88E453294045B4002B3655 /* KMPDFConvertManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFConvertManager.swift; sourceTree = "<group>"; };
 		BB88E45729404752002B3655 /* KMPDFConvert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFConvert.swift; sourceTree = "<group>"; };
@@ -7589,8 +7583,7 @@
 		BB02D6162A56AB1800114991 /* CPDFDocumentExtensions */ = {
 			isa = PBXGroup;
 			children = (
-				BB02D61C2A56AB9E00114991 /* CPDFDocument+KMExtension.h */,
-				BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */,
+				BB3198152AC55E6D00107371 /* CPDFDocument+KMExtension.swift */,
 			);
 			path = CPDFDocumentExtensions;
 			sourceTree = "<group>";
@@ -7926,7 +7919,6 @@
 			children = (
 				BB8B173F2907CE2A001C5EA5 /* NSView */,
 				BB86C20628F5566C005AD968 /* AppKitCategories */,
-				BB86C1F528F5476C005AD968 /* NSEvent_Extensions */,
 			);
 			path = ToolsLibrary;
 			sourceTree = "<group>";
@@ -8394,15 +8386,6 @@
 			path = images;
 			sourceTree = "<group>";
 		};
-		BB86C1F528F5476C005AD968 /* NSEvent_Extensions */ = {
-			isa = PBXGroup;
-			children = (
-				BB86C1FC28F54923005AD968 /* NSEvent_SKExtensions.h */,
-				BB86C1FB28F54923005AD968 /* NSEvent_SKExtensions.m */,
-			);
-			path = NSEvent_Extensions;
-			sourceTree = "<group>";
-		};
 		BB86C20628F5566C005AD968 /* AppKitCategories */ = {
 			isa = PBXGroup;
 			children = (
@@ -10670,7 +10653,6 @@
 				F34BF949295310AB002C25A2 /* NSUserDefaults+PDFListView.m in Sources */,
 				9F81ADC629B9B12C002251F4 /* NSButton+DesignToken.swift in Sources */,
 				BBEC00C7295C319400A26C98 /* KMBatesManager.swift in Sources */,
-				BB02D61E2A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */,
 				BB147020299DC0D100784A6A /* OIDServiceDiscovery.m in Sources */,
 				9F0201652A176AF200C9B673 /* KMDottedLineView.swift in Sources */,
 				BB5DF1F12959C9F00025CDA1 /* KMHeaderFooterPropertyMainController.swift in Sources */,
@@ -11017,6 +10999,7 @@
 				BB003015298CA446002DD1A0 /* KMPreferenceGeneralController.swift in Sources */,
 				BBB9B32E299A5D6D004F3235 /* GTMAppAuthFetcherAuthorization.m in Sources */,
 				F3732305292DF9410013862C /* CPDFSquareAnnotation+PDFListView.m in Sources */,
+				BB3198162AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */,
 				894A00F22976314C0070ED83 /* KMPDFViewPanelSetViewController.swift in Sources */,
 				BB135C2A29B6CD9A00FD5965 /* KMTools.swift in Sources */,
 				89D2D2BD29486D2400BFF5FE /* KMSignatureCellView.swift in Sources */,
@@ -11060,7 +11043,6 @@
 				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 */,
@@ -11477,6 +11459,7 @@
 				BB86C1EE28F544F4005AD968 /* CPDFListView+Event.m in Sources */,
 				9F81ADC729B9B12C002251F4 /* NSButton+DesignToken.swift in Sources */,
 				BB74DA7C2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */,
+				BB3198172AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */,
 				BBEC00C8295C319400A26C98 /* KMBatesManager.swift in Sources */,
 				ADA9102B2A272CE2003352F0 /* KMEditPDFTextManager.swift in Sources */,
 				BB147021299DC0D100784A6A /* OIDServiceDiscovery.m in Sources */,
@@ -11792,7 +11775,6 @@
 				9FBA0EEF28FFC716001117AF /* KMHomeFastToolViewController.swift in Sources */,
 				ADE8BC2629F7CCA600570F89 /* KMPageNumberDisplayView.swift in Sources */,
 				BB4DD048299B294000E80DF6 /* KMCloudFileEmptyView.swift in Sources */,
-				BB86C1FE28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */,
 				ADD272D129B9CFD30032B5D6 /* KMLightNoNetworkView.swift in Sources */,
 				89316847296E436B0073EA59 /* KMPDFSignatureImageView.m in Sources */,
 				BB49ECF7293F44DC00C82CA2 /* KMConvertExcelWindowController.swift in Sources */,
@@ -11865,7 +11847,6 @@
 				ADD1B6C82942E83000C3FFF7 /* KMPrintBottomView.swift in Sources */,
 				BB14702D299DC0D100784A6A /* OIDEndSessionRequest.m in Sources */,
 				9F0CB4A8296CF19600007028 /* KMPropertiesPanelListMenuSubVC.swift in Sources */,
-				BB02D61F2A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */,
 				BB146FE8299DC0D100784A6A /* GTLRQuery.m in Sources */,
 				ADD1B7032946C8AD00C3FFF7 /* KMBaseTextField.swift in Sources */,
 				BBAFC85929851AF200D0648E /* KMBlankView.m in Sources */,
@@ -12528,6 +12509,7 @@
 				89752D9C2936E675003FF08E /* KMToolBarBox.swift in Sources */,
 				ADC25DFB2923BA710080A3F6 /* KMImageToPDFWindowController.swift in Sources */,
 				BB4DD049299B294000E80DF6 /* KMCloudFileEmptyView.swift in Sources */,
+				BB3198182AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */,
 				BB147037299DC0D200784A6A /* OIDRegistrationResponse.m in Sources */,
 				9F221ED929A9EC0900978A59 /* KMFillSignTextPanel.swift in Sources */,
 				89752DC42937033F003FF08E /* KMPopMenuButtonCell.m in Sources */,
@@ -12687,7 +12669,6 @@
 				9F0CB4D32986550B00007028 /* KMDesignToken+Width.swift in Sources */,
 				BB4EEF4629764FEF003A3537 /* KMWatermarkAligementView.swift in Sources */,
 				9F0CB533298656EA00007028 /* KMDesignToken+BorderWidthBottom.swift in Sources */,
-				BB86C1FF28F54923005AD968 /* NSEvent_SKExtensions.m in Sources */,
 				BB49ED23293F527700C82CA2 /* KMConvertExcelSettingView.swift in Sources */,
 				9F0CB52B298656C900007028 /* KMDesignToken+BorderWidthTop.swift in Sources */,
 				ADA9102C2A272CE2003352F0 /* KMEditPDFTextManager.swift in Sources */,
@@ -12728,7 +12709,6 @@
 				AD68782329A5FADC005B5210 /* KMLightMemberCache.swift in Sources */,
 				BB8F4584295B0F900037EA22 /* KMHeaderFooterMarginInfoView.swift in Sources */,
 				BB49ED17293F489500C82CA2 /* KMConvertImageSettingView.swift in Sources */,
-				BB02D6202A56AB9E00114991 /* CPDFDocument+KMExtension.m in Sources */,
 				F373230D292DF9410013862C /* CPDFTextWidgetAnnotation+PDFListView.m in Sources */,
 				BB1EC80E2967DFE800EC0BC3 /* NSNumber_SKExtensions.m in Sources */,
 				899700EA28F3E4D3009AF911 /* MainWindowController.swift in Sources */,

+ 0 - 26
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFDocumentExtensions/CPDFDocument+KMExtension.h

@@ -1,26 +0,0 @@
-//
-//  CPDFDocument+KMExtension.h
-//  PDF Master
-//
-//  Created by tangchao on 2023/7/6.
-//
-
-#import <ComPDFKit/ComPDFKit.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface CPDFDocument (KMExtension)
-
-/*
- * 插入图片
- * @param pageSize 图片大小
- * @param imagePath 图片路径
- * @param index 插入的索引
- * @return 插入结果
- * @discussion [CPDFDocument insertPage:withImage:atIndex] 进一步封装。有兼容 png 格式
- */
-- (BOOL)km_insertPage:(CGSize)pageSize withImage:(NSString *)imagePath atIndex:(NSUInteger)index;
-
-@end
-
-NS_ASSUME_NONNULL_END

+ 0 - 54
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFDocumentExtensions/CPDFDocument+KMExtension.m

@@ -1,54 +0,0 @@
-//
-//  CPDFDocument+KMExtension.m
-//  PDF Master
-//
-//  Created by tangchao on 2023/7/6.
-//
-
-#import "CPDFDocument+KMExtension.h"
-
-@implementation CPDFDocument (KMExtension)
-
-- (BOOL)km_insertPage:(CGSize)pageSize withImage:(NSString *)imagePath atIndex:(NSUInteger)index {
-    if (![imagePath.pathExtension.lowercaseString isEqualToString:@"png"]) {
-        return [self insertPage:pageSize withImage:imagePath atIndex:index];
-    }
-    
-    // 图片格式为 png
-    if ([self insertPage:pageSize withImage:imagePath atIndex:index]) { // 尝试插入
-        return YES;
-    }
-    // 插入失败
-    // 转换为 jpg, 再插入到 document
-    NSData *data = [[[NSImage alloc] initWithContentsOfFile:imagePath] TIFFRepresentation];
-    if (!data) {
-        return NO;
-    }
-    // 创建 bitmap
-    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithData:data];
-    if (!bitmap) {
-        return NO;
-    }
-
-    NSData *jpgData = [bitmap representationUsingType:NSBitmapImageFileTypeJPEG properties:@{}];
-    NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
-    NSString *folderPath =  [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:appID] stringByAppendingPathComponent:@"KMTemp"];
-    if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath]) { // 路径不存在,则去创建
-        [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
-    }
-    NSString *filePath = [folderPath stringByAppendingPathComponent:@"temp_saveDocumentForCPDFDocumentInsertImage.jpg"];
-    
-    BOOL result = NO;
-    if ([jpgData writeToFile:filePath atomically:YES]) { // 将图片数据存入到临时路径
-        // 转换后再插入
-        result = [self insertPage:pageSize withImage:filePath atIndex:index];
-    }
-    
-    // 清除临时数据
-    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
-        [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
-    }
-    return result;
-}
-
-@end

+ 69 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFDocumentExtensions/CPDFDocument+KMExtension.swift

@@ -0,0 +1,69 @@
+//
+//  CPDFDocument+KMExtension.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/9/28.
+//
+
+import Foundation
+
+extension CPDFDocument {
+    
+    /*
+     * 插入图片
+     * @param pageSize 图片大小
+     * @param imagePath 图片路径
+     * @param index 插入的索引
+     * @return 插入结果
+     * @discussion [CPDFDocument insertPage:withImage:atIndex] 进一步封装。有兼容 png 格式
+     */
+    
+    func km_insertPage(_ pageSize: CGSize, withImage imagePath: String, at index: UInt) -> Bool {
+//        if (imagePath.deletingPathExtension)
+        guard let ext = imagePath.components(separatedBy: ".").last else {
+            return self.insertPage(pageSize, withImage: imagePath, at: index)
+        }
+        if (ext.lowercased() != "png") {
+            return self.insertPage(pageSize, withImage: imagePath, at: index)
+        }
+        
+        // 图片格式为 png
+        if (self.insertPage(pageSize, withImage: imagePath, at: index)) { // 尝试插入
+            return true
+        }
+        // 插入失败
+        // 转换为 jpg, 再插入到 document
+        guard let data = NSImage(contentsOfFile: imagePath)?.tiffRepresentation else {
+            return false
+        }
+        // 创建 bitmap
+        guard let bitmap =  NSBitmapImageRep(data: data) else {
+            return false
+        }
+        let jpgData = bitmap.representation(using: .jpeg, properties: [:])
+        let appID = Bundle.main.bundleIdentifier
+        let directory: String = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last as? String ?? ""
+        let folderPath = directory.stringByAppendingPathComponent(appID ?? "PDF Master bundleIdentifier").stringByAppendingPathComponent("KMTemp")
+        if (!FileManager.default.fileExists(atPath: folderPath)) {
+            try?FileManager.default.createDirectory(atPath: folderPath, withIntermediateDirectories: true)
+        }
+        let filePath = folderPath.stringByAppendingPathComponent("temp_saveDocumentForCPDFDocumentInsertImage.jpg")
+        var result = false
+        
+        do {
+            // 将图片数据存入到临时路径
+            try jpgData?.write(to: URL(fileURLWithPath: filePath))
+            // 转换后再插入
+            result = self.insertPage(pageSize, withImage: filePath, at: index)
+        } catch {
+            // nothing.
+        }
+        
+        // 清除临时数据
+        if (FileManager.default.fileExists(atPath: filePath)) {
+            try?FileManager.default.removeItem(atPath: filePath)
+        }
+        
+        return result
+    }
+}

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+MouseEvent.h

@@ -9,7 +9,6 @@
 
 #import "CPDFListView.h"
 
-#import "NSEvent_SKExtensions.h"
 #import "CPDFAnnotation+PDFListView.h"
 
 @interface CPDFListView (Event)

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

@@ -36,5 +36,3 @@
 #import "CPDFButtonWidgetAnnotation+PDFListView.h"
 #import "CPDFChoiceWidgetAnnotation+PDFListView.h"
 #import "CPDFSignatureWidgetAnnotation+PDFListView.h"
-
-#import "CPDFDocument+KMExtension.h"

+ 0 - 59
PDF Office/PDF Master/Class/ToolsLibrary/NSEvent_Extensions/NSEvent_SKExtensions.h

@@ -1,59 +0,0 @@
-//
-//  NSEvent_SKExtensions.h
-//  Skim
-//
-//  Created by Christiaan Hofman on 6/11/08.
-/*
- This software is Copyright (c) 2008-2018
- Christiaan Hofman. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- - Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in
-    the documentation and/or other materials provided with the
-    distribution.
-
- - Neither the name of Christiaan Hofman nor the names of any
-    contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Cocoa/Cocoa.h>
-
-enum {
-    SKSpaceCharacter = 0x0020,
-    SKEscapeCharacter = 0x001b
-};
-
-@interface NSEvent (SKExtensions)
-
-//+ (NSUInteger)standardModifierFlags;
-//- (NSUInteger)deviceIndependentModifierFlags;
-//- (NSUInteger)standardModifierFlags;
-
-//+ (NSPointingDeviceType)currentPointingDeviceType;
-//+ (void)setCurrentPointingDeviceType:(NSPointingDeviceType)newCurrentPointingDeviceType;
-
-//- (unichar)firstCharacter;
-
-//- (NSPoint)locationInView:(NSView *)view;
-
-@end

+ 0 - 76
PDF Office/PDF Master/Class/ToolsLibrary/NSEvent_Extensions/NSEvent_SKExtensions.m

@@ -1,76 +0,0 @@
-//
-//  NSEvent_SKExtensions.m
-//  Skim
-//
-//  Created by Christiaan Hofman on 6/11/08.
-/*
- This software is Copyright (c) 2008-2018
- Christiaan Hofman. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- - Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in
-    the documentation and/or other materials provided with the
-    distribution.
-
- - Neither the name of Christiaan Hofman nor the names of any
-    contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "NSEvent_SKExtensions.h"
-
-#define SKStandardModifierFlagsMask (NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask)
-
-@implementation NSEvent (SKExtensions)
-
-static NSPointingDeviceType currentPointingDeviceType = NSUnknownPointingDevice;
-
-+ (NSUInteger)standardModifierFlags {
-    return [self modifierFlags] & SKStandardModifierFlagsMask;
-}
-
-- (NSUInteger)deviceIndependentModifierFlags {
-    return [self modifierFlags] & NSDeviceIndependentModifierFlagsMask;
-}
-
-- (NSUInteger)standardModifierFlags {
-    return [self modifierFlags] & SKStandardModifierFlagsMask;
-}
-
-+ (NSPointingDeviceType)currentPointingDeviceType {
-    return currentPointingDeviceType;
-}
-
-+ (void)setCurrentPointingDeviceType:(NSPointingDeviceType)newCurrentPointingDeviceType {
-    currentPointingDeviceType = newCurrentPointingDeviceType;
-}
-
-- (unichar)firstCharacter {
-    NSString *characters = [self charactersIgnoringModifiers];
-    return [characters length] > 0 ? [characters characterAtIndex:0] : 0;
-}
-
-- (NSPoint)locationInView:(NSView *)view {
-    return [view convertPoint:[self locationInWindow] fromView:nil];
-}
-
-@end