Просмотр исходного кода

Merge branch 'develop_PDFReaderProNew' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderProNew

tangchao 1 год назад
Родитель
Сommit
bd37bf91cf

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

@@ -892,7 +892,8 @@ extension KMHomeViewController {
 //        openPanel.canChooseFiles = false
 //        openPanel.canChooseDirectories = true
 //        openPanel.canCreateDirectories = true
-        openPanel.beginSheetModal(for: self.view.window!) { [self] (result) in
+        
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
             if result == NSApplication.ModalResponse.OK {
                 openImageToPdfWindow(urls: openPanel.urls)
             }

+ 11 - 10
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -691,18 +691,19 @@ extension KMHomeViewController {
     }
     
     func newFromImages() {
-        let openPanel = NSOpenPanel()
-        openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
+        fastTool_ImageToPDF()
+//        let openPanel = NSOpenPanel()
+//        openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
 //        if IAPProductsManager.defaultManager().isAvailableAllFunction {
 //            openPanel.allowsMultipleSelection = true
 //        } else {
 //            openPanel.allowsMultipleSelection = false
 //        }
-        openPanel.message = NSLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on the keyboard and click on the target files one by one.", comment: "")
-        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
-            if result == .OK {
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
-                    debugPrint("缺少图片转PDF")
+//        openPanel.message = NSLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on the keyboard and click on the target files one by one.", comment: "")
+//        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+//            if result == .OK {
+//                DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+//                    debugPrint("缺少图片转PDF")
 //                    let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
 //                    var arr: [KMBatchOperateFile] = []
 //                    for url in openPanel.urls {
@@ -719,8 +720,8 @@ extension KMHomeViewController {
 //                    if #available(macOS 10.13, *) {
 //                        baseWindowController.release()
 //                    }
-                }
-            }
-        }
+//                }
+//            }
+//        }
     }
 }

+ 7 - 1
PDF Office/PDF Master/Class/PDFTools/Print/Model/KMPrintPageModel.swift

@@ -97,7 +97,13 @@ struct KMPrintPageOperation {
     var pageOfPaper: PageOfPaper = PageOfPaper()
     
     struct PageOfPaper {
-        var type: PageType = .page
+        var type: PageType = .page {
+            didSet {
+                if type != .custom {
+                    self.point = PageType.pointWithType(type)
+                }
+            }
+        }
         var point: CGPoint = CGPoint(x: 1, y: 1)
         
         enum PageType: String, CaseIterable {

+ 15 - 10
PDF Office/PDF Master/Class/PDFTools/Print/Presenter/KMPrintPresenter.swift

@@ -351,9 +351,9 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
         let columnAndRow = self.fetchPageColumnAndRow(data.page) //行 列数量
         let columnAndRowSpace = CGPoint(x: 2, y: 2) //行 列之间的空间
 
-        for i in 0...Int(columnAndRow.x) - 1 {
-            for j in 0...(Int(columnAndRow.y) - 1) {
-                let index = j + i * Int(columnAndRow.x)
+        for i in 0..<Int(columnAndRow.x) {
+            for j in 0..<(Int(columnAndRow.y)) {
+                let index = j + i * Int(columnAndRow.y)
                 if index < pages.count {
                     //参数
                     let page: KMPrintDrawPage = pages[index]
@@ -381,15 +381,15 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                     var origin = rect.origin
 
                     //多页Page自动旋转
-                    if autoSize {
+//                    if autoSize {
                         switch pageOrder {
                         case .horizontal:
-                            origin.x = (pageSize.width + columnAndRowSpace.x) * CGFloat(j) + paperInset.left + center.x
+                            origin.x = (pageSize.width + columnAndRowSpace.x) * CGFloat(i) + paperInset.left + center.x
                             //页面内容高度 + 下边的行间距 - 第几个cell的高度 +居中
-                            origin.y = paperSize.height - (pageSize.height + columnAndRowSpace.y) * (CGFloat(i) + 1) + center.y  + columnAndRowSpace.y
+                            origin.y = paperSize.height - (pageSize.height + columnAndRowSpace.y) * (CGFloat(j) + 1) + center.y  + columnAndRowSpace.y
                         case .horizontalReverseSequence:
-                            origin.x = paperSize.width - (pageSize.width + columnAndRowSpace.x) * (CGFloat(j) + 1) + center.x + columnAndRowSpace.x
-                            origin.y = paperSize.height - (pageSize.height + columnAndRowSpace.y) * (CGFloat(i) + 1) + center.y + paperInset.bottom + columnAndRowSpace.y
+                            origin.x = paperSize.width - (pageSize.width + columnAndRowSpace.x) * (CGFloat(i) + 1) + center.x + columnAndRowSpace.x
+                            origin.y = paperSize.height - (pageSize.height + columnAndRowSpace.y) * (CGFloat(j) + 1) + center.y + paperInset.bottom + columnAndRowSpace.y
                         case .vertical:
                             origin.x = (pageSize.width + columnAndRowSpace.x)  * CGFloat(i) + paperInset.left + center.x
                             origin.y = paperSize.height - (pageSize.height + columnAndRowSpace.y) * (CGFloat(j) + 1) + center.y + paperInset.bottom + columnAndRowSpace.y
@@ -400,8 +400,9 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                             KMPrint("未找到")
                             break
                         }
-                    }
+//                    }
                     
+                    NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false)
                     NSGraphicsContext.saveGraphicsState()
                     //平移
                     context.translateBy(x: origin.x, y: origin.y)
@@ -409,7 +410,7 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                     context.scaleBy(x: CGFloat(scale), y: CGFloat(scale))
                     
                     page.page.draw(with: PDFDisplayBox.cropBox, to: context)
-//                    page.transform(context, for: PDFDisplayBox.cropBox)
+                    page.page.transform(context, for: PDFDisplayBox.cropBox)
                     if border {
                         var dirtyRect = rect
                         if rotate == 90 ||
@@ -423,6 +424,10 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                     }
                     NSGraphicsContext.restoreGraphicsState()
 //                        page.setBounds(NSRect(x: 0, y: 0, width: pageRect.size.width, height: pageRect.size.height), for: .cropBox)
+                    print("--------------------------")
+                    print(page.page)
+                    print(origin)
+                    print(scale)
                 }
             }
         }

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/View/Custom/KMPrintDefaultView.swift

@@ -35,7 +35,7 @@ class KMPrintDefaultView: KMBaseXibView {
     var printSettingChange: KMPrintDefaultViewPrintSettingChange?
     
     override func setup() {
-        
+        viewModel.model.page.operation.type = .size
     }
     
     override func updateLanguage() {

+ 33 - 13
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/View/Multipage/KMPrintMultipageView.swift

@@ -85,7 +85,7 @@ class KMPrintMultipageView: KMBaseXibView, NSComboBoxDelegate {
     }
     
     override func setup() {
-        
+        viewModel.model.page.operation.type = .multipage
     }
     
     override func updateLanguage() {
@@ -250,32 +250,40 @@ extension KMPrintMultipageView {
     // MARK: - Button Event Action
     @IBAction func buttonItemClickPageBorder(_ sender: Any) {
         self.viewModel.multipageBorderChangeAction(isBorder: (borderCheckButton.state == .on)) { success, model in
-            self.updatePDFView()
+            if success {
+                self.updatePDFView()
+            }
         }
     }
 
     @IBAction func buttonItemClickAutoRoate(_ sender: Any) {
         self.viewModel.multipageAutoRotateChangeAction(isRotate: (autoRotaCheckButton.state == .on)) { success, model in
-            self.updatePDFView()
+            if success {
+                self.updatePDFView()
+            }
         }
     }
 
     @IBAction func buttonItemClickReversePage(_ sender: Any) {
         self.viewModel.printReverseAction(isSelect: (reverseButton.state == .on)) { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         }
     }
 
     @IBAction func buttonItemClickOrientation(_ sender: Any) {
         var type: KMPrintPaperDirectionType = .vertical
         if landscapeButton.state == .on {
-            type = .vertical
-        } else if portraitButton.state == .on {
             type = .horizontal
+        } else if portraitButton.state == .on {
+            type = .vertical
         }
         
         self.viewModel.printDirectionAction(type: type) { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         }
     }
 
@@ -318,7 +326,9 @@ extension KMPrintMultipageView {
         })
         
         self.viewModel.multipageEdgeInsetChangeAction(edgeInset: inset) { success, model in
-            self.updatePDFView()
+            if success {
+                self.updatePDFView()
+            }
         }
     }
 
@@ -352,7 +362,9 @@ extension KMPrintMultipageView {
         }
         
         self.viewModel.multipagePageOrderChangeAction(type: type) { success, model in
-            self.updatePDFView()
+            if success {
+                self.updatePDFView()
+            }
         }
     }
 
@@ -380,14 +392,18 @@ extension KMPrintMultipageView {
         }
         
         self.viewModel.printPagePerChangeAction(type: type) { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         }
     }
 
     @IBAction func comboBoxItemClickSplitSize(_ sender: NSComboBox) {
         let type = KMPrintPaperInfo.KMPaperType(rawValue: sender.stringValue) ?? .A4
         self.viewModel.printPaperTypeAction(type: type, completion: { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         })
     }
 
@@ -402,7 +418,9 @@ extension KMPrintMultipageView {
         }
         
         self.viewModel.printUnitChangeAction(unit: unit) { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         }
     }
 
@@ -417,7 +435,9 @@ extension KMPrintMultipageView {
         }
         
         self.viewModel.printContentAction(type: type, completion: { success, model in
-            self.updatePDFView(isPageChange: false)
+            if success {
+                self.updatePDFView(isPageChange: false)
+            }
         })
     }
 }

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/View/Poster/KMPrintPosterView.swift

@@ -416,7 +416,7 @@ extension KMPrintPosterView  {
                 scaleTextField.stringValue = "100"
             }
             
-            self.viewModel.posterScaleAction(value: scaleTextField.floatValue / 100.0) { success, model in
+            self.viewModel.posterScaleAction(value: CGFloat(scaleTextField.floatValue) / 100.0) { success, model in
                 
             }
         } else if textField == pageRangeComboBox {

+ 72 - 4
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/ViewModel/KMPrintViewModel.swift

@@ -7,7 +7,7 @@
 
 import Cocoa
 
-typealias KMPrintViewModelCompletion = (_ success: Bool, _ model: KMPrintModel) -> Void
+typealias KMPrintViewModelCompletion = (_ success: Bool, _ model: KMPrintModel?) -> Void
 
 class KMPrintViewModel: NSObject {
     lazy var model: KMPrintModel = KMPrintModel()
@@ -55,6 +55,11 @@ extension KMPrintViewModel {
     
     //页面范围
     func pageRangeAction(range: KMPrintPageRange, completion: KMPrintViewModelCompletion) {
+        if range.type == model.page.range.type {
+            completion(false, nil)
+            return
+        }
+        
         model.page.range.type = range.type
         model.page.range.pageString = range.pageString
         
@@ -63,6 +68,10 @@ extension KMPrintViewModel {
     
     //打印方向
     func printDirectionAction(type: KMPrintPaperDirectionType, completion: KMPrintViewModelCompletion) {
+        if type == model.paper.direction {
+            completion(false, nil)
+            return
+        }
         model.paper.direction = type
         
         completion(true, model)
@@ -70,6 +79,10 @@ extension KMPrintViewModel {
     
     //打印内容
     func printContentAction(type: KMPrintContentType, completion: KMPrintViewModelCompletion) {
+        if type == self.model.page.contentType {
+            completion(false, nil)
+            return
+        }
         self.model.page.contentType = type
         
         completion(true, model)
@@ -77,6 +90,10 @@ extension KMPrintViewModel {
     
     //逆页面打印
     func printReverseAction(isSelect: Bool, completion: KMPrintViewModelCompletion) {
+        if isSelect == self.model.page.range.reversePrintOrder {
+            completion(false, nil)
+            return
+        }
         self.model.page.range.reversePrintOrder = isSelect
         
         completion(true, model)
@@ -84,6 +101,10 @@ extension KMPrintViewModel {
     
     //打印页面偏移
     func printOverlapChangeAction(value: Float, completion: KMPrintViewModelCompletion) {
+        if value == self.model.page.operation.poster.overlap {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.poster.overlap = value
         
         completion(true, model)
@@ -91,6 +112,11 @@ extension KMPrintViewModel {
     
     //单位
     func printUnitChangeAction(unit: KMPrintPaperInfoUnit, completion: KMPrintViewModelCompletion) {
+        if unit == self.model.paper.info.unit {
+            completion(false, nil)
+            return
+        }
+        
         self.model.paper.info.unit = unit
         
         completion(true, model)
@@ -105,6 +131,10 @@ extension KMPrintViewModel {
     
     //纸张类型
     func printPaperTypeAction(type: KMPrintPaperInfo.KMPaperType, posterType: KMPrintPageOperation.Poster.PosterType = .tile, customSize: CGSize = CGSizeZero, completion: KMPrintViewModelCompletion) {
+        if type == self.model.paper.info.type {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.poster.overlap = 0
         self.model.page.operation.poster.type = posterType
         self.model.paper.info.type = type
@@ -120,8 +150,13 @@ extension KMPrintViewModel {
     
     //页面
     func printPagePerChangeAction(type: KMPrintPageOperation.PageOfPaper.PageType, customPoint: CGPoint = CGPoint(x: 2, y: 2), completion: KMPrintViewModelCompletion) {
-        self.model.page.operation.pageOfPaper.type = type
+        if type == self.model.page.operation.pageOfPaper.type {
+            completion(false, nil)
+            return
+        }
+        
         self.model.page.operation.pageOfPaper.point = customPoint
+        self.model.page.operation.pageOfPaper.type = type
         
         completion(true, model)
     }
@@ -130,12 +165,20 @@ extension KMPrintViewModel {
 //Poster
 extension KMPrintViewModel {
     func posterCutMarkAction(isSelect: Bool, completion: KMPrintViewModelCompletion) {
+        if isSelect == self.model.page.operation.poster.isCutMark {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.poster.isCutMark = isSelect
         
         completion(true, model)
     }
     
     func posterTagsAction(isSelect: Bool, tags: [String], completion: KMPrintViewModelCompletion) {
+        if isSelect == self.model.page.operation.poster.isTags {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.poster.isTags = isSelect
         self.model.page.operation.poster.tags = tags
         
@@ -143,13 +186,21 @@ extension KMPrintViewModel {
     }
     
     func posterTypeAction(type: KMPrintPageOperation.Poster.PosterType, completion: KMPrintViewModelCompletion) {
+        if type == self.model.page.operation.poster.type {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.poster.type = type
         
         completion(true, model)
     }
     
-    func posterScaleAction(value: Float, completion: KMPrintViewModelCompletion) {
-        self.model.page.operation.poster.scale = CGFloat(value)
+    func posterScaleAction(value: CGFloat, completion: KMPrintViewModelCompletion) {
+        if value == self.model.page.operation.poster.scale {
+            completion(false, nil)
+            return
+        }
+        self.model.page.operation.poster.scale = value
         
         completion(true, model)
     }
@@ -158,6 +209,10 @@ extension KMPrintViewModel {
 //Multipage
 extension KMPrintViewModel {
     func multipageBorderChangeAction(isBorder: Bool, completion: KMPrintViewModelCompletion) {
+        if isBorder == self.model.page.operation.multipage.isBorder {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.multipage.isBorder = isBorder
         
         completion(true, model)
@@ -176,18 +231,31 @@ extension KMPrintViewModel {
     }
     
     func multipagelineSpacingChangeAction(value: CGFloat, completion: KMPrintViewModelCompletion) {
+        if value == self.model.page.operation.multipage.lineSpacing {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.multipage.lineSpacing = value
         
         completion(true, model)
     }
     
     func multipagecolumnsSpacingChangeAction(value: CGFloat, completion: KMPrintViewModelCompletion) {
+        if value == self.model.page.operation.multipage.columnsSpacing {
+            completion(false, nil)
+            return
+        }
         self.model.page.operation.multipage.columnsSpacing = value
         
         completion(true, model)
     }
     
     func multipagePageOrderChangeAction(type: KMPrintPageOperation.Multipage.Order, completion: KMPrintViewModelCompletion) {
+        if type == self.model.page.operation.multipage.orderType {
+            completion(false, nil)
+            return
+        }
+        
         self.model.page.operation.multipage.orderType = type
         
         completion(true, model)