Explorar o código

【fix】【合并】导入图片,添加损坏的图片,无任何错误提示

tangchao hai 5 meses
pai
achega
089cb05b57

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

@@ -222,7 +222,7 @@ class KMBaseViewController: NSViewController {
                         let document = CPDFDocument()
                         let document = CPDFDocument()
                         let image = NSImage(contentsOfFile: imageUrl.path)
                         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)
+                        document?.km_insertPage(image?.size ?? .zero, withImage: imageUrl.path, at: 0)
                         _documents.append(document!)
                         _documents.append(document!)
                         
                         
                         if let _callback = progressBlock { // 回调进度
                         if let _callback = progressBlock { // 回调进度

+ 2 - 2
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -1151,9 +1151,9 @@ extension KMHomeViewController {
         } else {
         } else {
             baseWindowController.showWindow(nil)
             baseWindowController.showWindow(nil)
         }
         }
-        if arr.count > 0 {
+//        if arr.count > 0 {
             baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: .CreatePDF, files: arr)
             baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: .CreatePDF, files: arr)
-        }
+//        }
     }
     }
     
     
     func isDamageImage(image: NSImage?, path: String) -> Bool {
     func isDamageImage(image: NSImage?, path: String) -> Bool {

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -755,7 +755,7 @@ extension KMWatermarkView {
                     })
                     })
                 } else {
                 } else {
                     let image = NSImage(contentsOfFile: url.path)
                     let image = NSImage(contentsOfFile: url.path)
-                    if self.isDamageImage(image, imagePath: url.path) {
+                    if image == nil || self.isDamageImage(image, imagePath: url.path) {
                         let alert = NSAlert()
                         let alert = NSAlert()
                         alert.alertStyle = .critical
                         alert.alertStyle = .critical
                         alert.messageText = "The file \"\(url.lastPathComponent)\" could not be opened."
                         alert.messageText = "The file \"\(url.lastPathComponent)\" could not be opened."

+ 14 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/Signature/KMPDFSignatureImageView.swift

@@ -335,8 +335,9 @@ let KMSignatureMaxHeight = 300.0
                         return
                         return
                     }
                     }
                 }
                 }
-
-                if let image = NSImage(contentsOfFile: url.path), self?.isDamageImage(image, imagePath: url.path) == true {
+                
+                let image = NSImage(contentsOfFile: url.path)
+                if image == nil || self?.isDamageImage(image!, imagePath: url.path) == true {
                     let alert = NSAlert()
                     let alert = NSAlert()
                     alert.alertStyle = .critical
                     alert.alertStyle = .critical
                     alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), url.path.lastPathComponent)
                     alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), url.path.lastPathComponent)
@@ -407,6 +408,17 @@ let KMSignatureMaxHeight = 300.0
                     continue
                     continue
                 }
                 }
                 if supportedImageTypes().contains(_url.pathExtension.lowercased()) {
                 if supportedImageTypes().contains(_url.pathExtension.lowercased()) {
+                    let image = NSImage(contentsOfFile: _url.path)
+                    if image == nil || self.isDamageImage(image!, imagePath: _url.path) == true {
+                        let alert = NSAlert()
+                        alert.alertStyle = .critical
+                        alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), _url.path.lastPathComponent)
+                        alert.informativeText = NSLocalizedString("It may be damaged or use a file format that PDF Reader Pro doesn’t recognize.", comment: "")
+                        alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
+                        alert.runModal()
+                        return false
+                    }
+                    
                     loadImageViewPath(_url, isRemoveBGColor: clearBackground)
                     loadImageViewPath(_url, isRemoveBGColor: clearBackground)
                     changeSignatureImageCallback?(true)
                     changeSignatureImageCallback?(true)
                     return true
                     return true

+ 2 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/KMAnnotationStampViewController.swift

@@ -872,7 +872,8 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
     }
     }
     
     
     func addImageStamp(withFilePath filePath: String, removeBGColor: Bool) {
     func addImageStamp(withFilePath filePath: String, removeBGColor: Bool) {
-        if let image = NSImage(contentsOfFile: filePath), isDamageImage(image, imagePath: filePath) {
+        let image = NSImage(contentsOfFile: filePath)
+        if image == nil || isDamageImage(image!, imagePath: filePath) {
             let alert = NSAlert()
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.alertStyle = .critical
             alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), (filePath as NSString).lastPathComponent)
             alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), (filePath as NSString).lastPathComponent)