Browse Source

【页面编辑】附件png图片无法拖拽插入到页面编辑中(已修复);更新ComPDFKit库(V1.8.0.1)

tangchao 1 year ago
parent
commit
8a620c7904

+ 18 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -2003,6 +2003,9 @@
 		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 */; };
@@ -4314,6 +4317,8 @@
 		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>"; };
@@ -7595,6 +7600,15 @@
 			path = Tools;
 			sourceTree = "<group>";
 		};
+		BB02D6162A56AB1800114991 /* CPDFDocumentExtensions */ = {
+			isa = PBXGroup;
+			children = (
+				BB02D61C2A56AB9E00114991 /* CPDFDocument+KMExtension.h */,
+				BB02D61D2A56AB9E00114991 /* CPDFDocument+KMExtension.m */,
+			);
+			path = CPDFDocumentExtensions;
+			sourceTree = "<group>";
+		};
 		BB0A551B2A3078EB00B6E84B /* Designs */ = {
 			isa = PBXGroup;
 			children = (
@@ -9257,6 +9271,7 @@
 		F37322AD292DF9410013862C /* CPDFKitExtensions */ = {
 			isa = PBXGroup;
 			children = (
+				BB02D6162A56AB1800114991 /* CPDFDocumentExtensions */,
 				F37322AE292DF9410013862C /* CPDFSelectionExtensions */,
 				F37322AF292DF9410013862C /* CPDFPageExtensions */,
 				F37322B2292DF9410013862C /* CPDFAnnotationExtensions */,
@@ -10714,6 +10729,7 @@
 				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 */,
@@ -11910,6 +11926,7 @@
 				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 */,
@@ -12778,6 +12795,7 @@
 				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 */,

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

@@ -206,8 +206,8 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1557"
-            endingLineNumber = "1557"
+            startingLineNumber = "1556"
+            endingLineNumber = "1556"
             landmarkName = "pdfViewEditingCropBoundsDidChanged(_:editing:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -222,8 +222,8 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1566"
-            endingLineNumber = "1566"
+            startingLineNumber = "1565"
+            endingLineNumber = "1565"
             landmarkName = "pdfViewEditingAddImageArea(_:add:add:)"
             landmarkType = "7">
          </BreakpointContent>

+ 2 - 2
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowser.swift

@@ -39,7 +39,7 @@ import Cocoa
             let currentDocument = tabStripModel.tabContents(at: Int32(numberOfTabViewItem-1)) as! KMMainDocument
             if (currentDocument.isHome == false) {
                 currentDocument.mainViewController?.savePageNumberIfNeed()
-                if let _ = currentDocument.mainViewController?.listView.isEdited(), !currentDocument.isDocumentEdited {
+                if let _isEdited = currentDocument.mainViewController?.listView.isEdited(), _isEdited, !currentDocument.isDocumentEdited {
                     currentDocument.updateChangeCount(.changeDone)
                 }
             }
@@ -120,7 +120,7 @@ import Cocoa
             let currentDocument = tabContents(at: Int32(index)) as! KMMainDocument
             if (currentDocument.isHome == false) {
                 currentDocument.mainViewController?.savePageNumberIfNeed()
-                if let _ = currentDocument.mainViewController?.listView.isEdited(), !currentDocument.isDocumentEdited {
+                if let _isEdited = currentDocument.mainViewController?.listView.isEdited(), _isEdited, !currentDocument.isDocumentEdited {
                     currentDocument.updateChangeCount(.changeDone)
                 }
             }

+ 4 - 2
PDF Office/PDF Master/Class/Common/Base/KMBaseViewController.swift

@@ -255,7 +255,8 @@ class KMBaseViewController: NSViewController {
                         index += 1
                         let document = CPDFDocument()
                         let image = NSImage(contentsOfFile: imageUrl.path)
-                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+//                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+                        document?.km_insertPage(image!.size, withImage: imageUrl.path, at: 0)
                         _documents.append(document!)
                         
                         if let _callback = progressBlock { // 回调进度
@@ -288,7 +289,8 @@ class KMBaseViewController: NSViewController {
                         index += 1
                         let document = CPDFDocument()
                         let image = NSImage(contentsOfFile: imageUrl.path)
-                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+//                        document?.insertPage(image!.size, withImage: imageUrl.path, at: 0)
+                        document?.km_insertPage(image!.size, withImage: imageUrl.path, at: 0)
                         _documents.append(document!)
                         
                         if let _callback = progressBlock { // 回调进度

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

@@ -0,0 +1,18 @@
+//
+//  CPDFDocument+KMExtension.h
+//  PDF Master
+//
+//  Created by tangchao on 2023/7/6.
+//
+
+#import <ComPDFKit/ComPDFKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CPDFDocument (KMExtension)
+
+- (BOOL)km_insertPage:(CGSize)pageSize withImage:(NSString *)imagePath atIndex:(NSUInteger)index;
+
+@end
+
+NS_ASSUME_NONNULL_END

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

@@ -0,0 +1,52 @@
+//
+//  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;
+    }
+    // 插入失败
+    // 转换为data
+    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

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

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

BIN
PDF Office/PDF Master/Class/PDFWindowController/PDFSDK/ComPDFKit.framework/Versions/A/ComPDFKit


+ 4 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFSDK/ComPDFKit.framework/Versions/A/Headers/CPDFView+Editing.h

@@ -174,6 +174,10 @@ typedef NS_OPTIONS(NSInteger, CEditingLoadType) {
 
 - (void)setCurrentSelectionAlignment:(NSTextAlignment)alignment withTextArea:(CPDFEditTextArea *)editArea;
 
+- (void)clearEditingSelectCharItem;
+
+- (void)clearEditingSelectCharRange;
+
 #pragma mark - Edit Image
 
 - (BOOL)createImagePath:(NSString *)filePath rect:(CGRect)rect page:(CPDFPage *)page;

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFSDK/ComPDFKit.framework/Versions/A/_CodeSignature/CodeResources

@@ -892,11 +892,11 @@
 		<dict>
 			<key>hash</key>
 			<data>
-			YNbKDnv/tbchNjR/ptrY68t523E=
+			Bz0XK+Eg6XkVVOhuoiq5rtXyKIo=
 			</data>
 			<key>hash2</key>
 			<data>
-			U1vZLKT8deq1lCos2jJuuF5JFSRWSdbOi8WpYazuEig=
+			RX27f9dF6obneoOPn6rAC76+EPdYt1OK9uFCOdpTzBo=
 			</data>
 		</dict>
 		<key>Headers/CPDFView+Utilities.h</key>

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

@@ -362,7 +362,6 @@ import Cocoa
             return event
         }
         
-        
         //是否弹出登录窗口
         self.needShowRegisterView()
     }