Bläddra i källkod

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

liujiajie 1 år sedan
förälder
incheckning
2c462a89b5

+ 3 - 3
PDF Office/PDF Master/Class/Batch/Tools/KMImageToPDFMethod.swift

@@ -133,7 +133,7 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
             if pdf!.isEncrypted {
                 options.updateValue(password, forKey: .userPasswordOption)
                 options.updateValue(password, forKey: .userPasswordOption)
-                isSucceed = ((pdf?.write(toFile: newPath, withOptions: options)) != nil)
+                isSucceed = pdf?.write(toFile: newPath, withOptions: options) ?? false
             } else {
                 isSucceed = pdf?.write(toFile: newPath) ?? false
             }
@@ -172,7 +172,7 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
 //            DispatchQueue.global().async {
                 var isSucceed = false
                 
-                isSucceed = ((pdf?.write(toFile: newpath)) != nil)
+                isSucceed = pdf?.write(toFile: newpath) ?? false
                 var pre: Float = 0
                 if self.photoArray?.count ?? 0 > 0{
                     pre = Float(self.convertIndex + 1) / Float(self.photoArray?.count ?? 1)
@@ -314,7 +314,7 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
                                 if ((appPDF?.isEncrypted) != nil) {
                                     attributes.setValue(self.password, forKey: (kCGPDFContextUserPassword as NSString) as String)
                                     attributes.setValue(self.password, forKey: (kCGPDFContextOwnerPassword as NSString) as String)
-                                    isSuccessfully = ((appPDF?.write(toFile: self.fileSavePath, withOptions: (attributes as? [CPDFDocumentWriteOption : Any]))) != nil)
+                                    isSuccessfully = appPDF?.write(toFile: self.fileSavePath, withOptions: (attributes as? [CPDFDocumentWriteOption : Any])) ?? false
                                 } else {
                                     isSuccessfully = appPDF?.write(toFile: self.fileSavePath) ?? false
                                 }

+ 1 - 1
PDF Office/PDF Master/Class/Batch/WindowController/KMBatchOperateLeftViewController.swift

@@ -287,7 +287,7 @@ class KMBatchOperateLeftViewController: NSViewController,NSTableViewDelegate,NST
             let com = PasswordWindowController(windowNibName: "PasswordWindowController")
             com.fileURL = URL(fileURLWithPath: filePath)
             self.km_beginSheet(windowC: com)
-            com.closeCallBack = { password in
+            com.closeCallBack = { [unowned self] password in
                 self.closePwd()
                 if !password.isEmpty {
                     let file = KMBatchOperateFile(filePath: filePath, type: self.type!)

+ 77 - 7
PDF Office/PDF Master/Class/Common/Category/NSResponder+KMExtension.swift

@@ -56,11 +56,11 @@ extension NSResponder: KMWindowSheetProtocol {
     
     func km_can_beginSheet(windowC: NSWindowController) -> Bool {
         guard let _ = windowC.window else {
-            KMPrint("窗口弹起失败, 窗口为空.")
+            self._log("窗口弹起失败, 窗口为空.", needAssert: false)
             return false
         }
         guard let _ = self.km_window() else {
-            KMPrint("窗口弹起失败, 当前窗口为空.")
+            self._log("窗口弹起失败, 当前窗口为空.", needAssert: false)
             return false
         }
         return true
@@ -68,7 +68,7 @@ extension NSResponder: KMWindowSheetProtocol {
     
     func km_can_endSheet() -> Bool {
         guard let _ = self.kmCurrentWindowC?.window else {
-            KMPrint("窗口收起失败, 当前窗口为空.")
+            self._log("窗口收起失败, 当前窗口为空.", needAssert: false)
             return false
         }
         
@@ -76,7 +76,7 @@ extension NSResponder: KMWindowSheetProtocol {
             return true
         }
         
-        KMPrint("窗口收起失败, sheetWindow为空.")
+        self._log("窗口收起失败, sheetWindow为空.", needAssert: false)
         return false
     }
     
@@ -86,6 +86,10 @@ extension NSResponder: KMWindowSheetProtocol {
         }
         // 强持有窗口控制器
         self.kmCurrentWindowC = windowC
+        // 反向弱持有
+        windowC._setSheetParentResponder(self)
+        // 存储哨兵
+        windowC.sheetFlag = true
         if let _window = windowC.window {
             self.km_window()?.beginSheet(_window)
         }
@@ -99,20 +103,50 @@ extension NSResponder: KMWindowSheetProtocol {
         if let _currentW = self.kmCurrentWindowC?.window {
             self._km_sheetParent()?.endSheet(_currentW)
         }
+        // 置空指针,避免野指针
+        self.kmCurrentWindowC?._setSheetParentResponder(nil)
+        // 释放哨兵
+        self.kmCurrentWindowC?.sheetFlag = false
         // 释放窗口控制器
         self.kmCurrentWindowC = nil
     }
     
+    func km_quick_endSheet() {
+        if let _ = self.kmCurrentWindowC {
+            self.km_endSheet()
+            return
+        }
+        
+        guard let windowC = self as? NSWindowController else {
+            self._log("windowC is nil")
+            return
+        }
+        
+        // 不是通过 km_endSheet 或 km_safe_beginSheet 方法弹出
+        if windowC.sheetFlag == false {
+            // 直接结束弹出就好,不需要处理数据
+            if let _win = windowC.window {
+                windowC.window?.sheetParent?.endSheet(_win)
+                return
+            }
+            self._log("windowC is nil")
+            return
+        }
+        
+        // 不是 km_endSheet 或 km_safe_beginSheet 的调起者
+        windowC.sheetParentResponder?.km_endSheet()
+    }
+    
     func km_safe_beginSheet(windowC: NSWindowController?) {
         guard let _windowC = windowC else {
-            #if DEBUG
-            assert(false, "windowC is nil")
-            #endif
+            self._log("windowC is nil")
             return
         }
         return self.km_beginSheet(windowC: _windowC)
     }
     
+    // MARK: - Private Methods
+    
     fileprivate func _km_sheetParent() -> NSWindow? {
         var sheetParent: NSWindow?
         if let data = self.km_window() {
@@ -123,7 +157,43 @@ extension NSResponder: KMWindowSheetProtocol {
         return sheetParent
     }
     
+    private func _log(_ string: String?, needAssert: Bool = true) {
+        #if DEBUG
+        if needAssert {
+            assert(false, string ?? "")
+        } else {
+            KMPrint(string as Any)
+        }
+        #endif
+    }
+    
     @objc func km_window() -> NSWindow? {
         return nil
     }
 }
+
+// MARK: - Sheet
+
+extension NSWindowController {
+    private static var _sheetParentResponderKey = "KMSheetParentResponderKey"
+    unowned var sheetParentResponder: NSResponder? {
+        get {
+            return objc_getAssociatedObject(self, &Self._sheetParentResponderKey) as? NSResponder
+        }
+    }
+    
+    private static var _sheetFlagKey = "KMSheetFlagKey"
+    var sheetFlag: Bool {
+        get {
+            return objc_getAssociatedObject(self, &Self._sheetFlagKey) as? Bool ?? false
+        }
+        set {
+            objc_setAssociatedObject(self, &Self._sheetFlagKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
+        }
+    }
+    
+    // MARK: - Private Methods
+    fileprivate func _setSheetParentResponder(_ newValue: NSResponder?) {
+        objc_setAssociatedObject(self, &Self._sheetParentResponderKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
+    }
+}

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

@@ -1137,9 +1137,11 @@ extension KMHomeViewController {
 //                    }
 //                }];
                 windowC.callback = { [unowned self] idx, params in
-                    if idx == 0 {
-                        self.km_endSheet()
-                        return
+                    self.km_endSheet()
+                    if params.count >= 2 {
+                        if let doc = params.first as? CPDFDocument {
+                            self.savePDFDocument(doc, password: params[1] as? String ?? "")
+                        }
                     }
                 }
                 self.km_beginSheet(windowC: windowC)
@@ -1147,6 +1149,45 @@ extension KMHomeViewController {
         }
     }
     
+    
+//    func savePDFDocument(_ pdf: CPDFDocument, password: String?) {
+////        KMProgressWindowController * vc = [[KMProgressWindowController alloc] init];
+////        [NSApp beginSheet:[vc window] modalForWindow:[NSApp mainWindow] modalDelegate:nil didEndSelector:nil contextInfo:NULL];
+//
+//        DispatchQueue.global().async {
+//            var isSuccessfully = false
+//            if (pdf.isEncrypted) {
+//                isSuccessfully = pdf.write(to: pdf.documentURL, withOptions: [.userPasswordOption : password ?? "", .ownerPasswordOption : password ?? ""])
+//            } else {
+//                isSuccessfully = pdf.write(to: pdf.documentURL)
+//            }
+//            if (!isSuccessfully) {
+////                isSuccessfully = [pdf.dataRepresentation writeToURL:pdf.documentURL atomically:YES];
+//                try?pdf.dataRepresentation().write(to: pdf.documentURL)
+//            }
+//
+//            Task { @MainActor in
+////                [NSApp endSheet:vc.window];
+////                [vc close];
+//
+//                if (isSuccessfully) {
+////                    BOOL autoOpen = [[NSUserDefaults standardUserDefaults] boolForKey:KMAutoOpenDocumentKey];
+////                    if (autoOpen) {
+////                        [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:pdf.documentURL display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
+////
+////                        }];
+////                    } else {
+//                    let workspace = NSWorkspace.shared
+//                    let url = URL(fileURLWithPath: pdf.documentURL.path)
+//                    workspace.activateFileViewerSelecting([url])
+////                    }
+//                } else {
+//                    _ = await KMAlertTool.runModel(message: KMLocalizedString("Failed to insert page(s)!", nil))
+//                }
+//            }
+//        }
+//    }
+    
     func fastTool_BreakUp() {   // 拆分
 //        let openPanel = NSOpenPanel()
 //        openPanel.prompt = "提取"

+ 1 - 48
PDF Office/PDF Master/Class/PDFTools/Insert/KMPDFInsertWindowController.swift

@@ -351,10 +351,7 @@ class KMPDFInsertWindowController: NSWindowController {
     @IBAction func buttonItemClicked_Cancel(_ sender: AnyObject?) {
         self._pdfDocument = nil
 
-        guard let block = self.callback else {
-            return
-        }
-        block(0)
+        self.km_quick_endSheet()
     }
     
     @IBAction func buttonItemClicked_OutputFolder(_ sender: AnyObject?) {
@@ -423,50 +420,6 @@ class KMPDFInsertWindowController: NSWindowController {
             self.window?.makeFirstResponder(self.pageRangeBox)
         }
     }
-
-    func savePDFDocument(_ pdf: CPDFDocument, password: String?) {
-//        KMProgressWindowController * vc = [[KMProgressWindowController alloc] init];
-//        [NSApp beginSheet:[vc window] modalForWindow:[NSApp mainWindow] modalDelegate:nil didEndSelector:nil contextInfo:NULL];
-        
-//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-//            BOOL isSuccessfully = NO;
-//            if ([pdf isEncrypted]) {
-//                NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
-//                                     password,kCGPDFContextUserPassword,
-//                                     password,kCGPDFContextOwnerPassword, nil];
-//                isSuccessfully = [pdf writeToURL:pdf.documentURL withOptions:dic];
-//            }else{
-//                 isSuccessfully = [pdf writeToURL:pdf.documentURL];
-//            }
-//            if (!isSuccessfully) {
-//                isSuccessfully = [pdf.dataRepresentation writeToURL:pdf.documentURL atomically:YES];
-//            }
-//            
-//            dispatch_async(dispatch_get_main_queue(), ^{
-//                [NSApp endSheet:vc.window];
-//                [vc close];
-//
-//                if (isSuccessfully) {
-//                    BOOL autoOpen = [[NSUserDefaults standardUserDefaults] boolForKey:KMAutoOpenDocumentKey];
-//                    if (autoOpen) {
-//                        [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:pdf.documentURL display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
-//                            
-//                        }];
-//                    } else {
-//                        NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
-//                        NSURL *url = [NSURL fileURLWithPath:[pdf.documentURL path]];
-//                        [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
-//                    }
-//                } else {
-//                    NSAlert *alert = [[NSAlert alloc] init];
-//                    [alert setAlertStyle:NSAlertStyleCritical];
-//                    [alert setMessageText:[NSString stringWithFormat:NSLocalizedString(@"Failed to insert page(s)!", nil)]];
-//                    [alert runModal];
-//                    [alert release];
-//                }
-//            });
-//        });
-    }
 }
 
 extension KMPDFInsertWindowController: NSTextFieldDelegate {

+ 4 - 0
PDF Office/PDF Master/Class/PDFTools/Print/Model/KMPrintPaperModel.swift

@@ -42,6 +42,10 @@ struct KMPrintPaperInfo {
         return KMPaperType.paperSize(type: type, px: true)
     }
     
+//    var showSize: CGSize {
+//        return KMPaperType.paperSize(type: type, px: false)
+//    }
+    
     enum KMPaperType: String, CaseIterable {
         case Actual = "Actual Size"
         case A3 = "A3"

+ 47 - 3
PDF Office/PDF Master/Class/PDFTools/Print/Presenter/KMPrintPresenter.swift

@@ -410,7 +410,6 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                     
                     page.page.draw(with: PDFDisplayBox.cropBox, to: context)
 //                    page.transform(context, for: PDFDisplayBox.cropBox)
-                    
                     if border {
                         var dirtyRect = rect
                         if rotate == 90 ||
@@ -428,6 +427,51 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
             }
         }
     }
+    
+    func drawLabelTextContextSize(context: CGContext) {
+        let pageSize = CGSize(width: 0, height: 0)
+        let KBlankA4W = pageSize.width
+        let KBlankA4H = pageSize.height
+        
+        var contextString: String
+//        if let labelString = PDFPrint.labelString, !labelString.isEmpty {
+//            contextString = labelString
+//        } else {
+            let date = Date()
+            let formatter = DateFormatter()
+            formatter.dateFormat = "YYYY-MM-dd hh:mm:ss"
+        contextString = "(\("1"),\("1")) \("filePath.lastPathComponent") \(formatter.string(from: date))"
+//        }
+        
+        let fontSize = 12.0 * (max(KBlankA4W, KBlankA4H) / 842)
+        let font = NSFont.systemFont(ofSize: fontSize)
+        let color = NSColor.black
+        
+        var size = NSSize.zero
+        var style = NSMutableParagraphStyle()
+        style.alignment = .center
+        style.lineBreakMode = .byCharWrapping
+        var attributes = [NSAttributedString.Key: Any]()
+        attributes[.paragraphStyle] = style
+        attributes[.foregroundColor] = color
+        attributes[.font] = font
+        size = contextString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude),
+                                          options: [.usesLineFragmentOrigin, .usesFontLeading],
+                                          attributes: attributes).size
+        
+//        if PDFPrint.splitType == .pageNumber {
+            contextString.draw(in: CGRect(x: 10 + 10,
+                                          y: KBlankA4H - 10 + size.height,
+                                          width: size.width, height: size.height),
+                                withAttributes: attributes)
+//        } else {
+//            contextString.draw(in: CGRect(x: PDFPrint.edgeInsets.left + 10,
+//                                          y: KBlankA4H - PDFPrint.edgeInsets.top + size.height,
+//                                          width: size.width, height: size.height),
+//                                withAttributes: attributes)
+//        }
+    }
+
 }
 
 protocol KMPrintPresenterPage {}
@@ -957,12 +1001,12 @@ extension KMPrintPresenter: KMPrintPresenterDraw {
 protocol KMPrintPresenterPrivate {}
 extension KMPrintPresenter: KMPrintPresenterPrivate {
     func isAnnoationStamp(type: String) -> Bool {
-        let annotationStamp: [String] = ["Square"]
+        let annotationStamp: [String] = ["Square", "Stamp"]
         return annotationStamp.contains(type)
     }
     
     func isAnnoationMarkup(type: String) -> Bool {
-        let annotationStamp: [String] = ["Widget", "Freehand"]
+        let annotationStamp: [String] = ["Widget", "Freehand", "Highlight", "Underline", "Squiggly", "Circle", "StrikeOut", "Ink"]
         return annotationStamp.contains(type)
     }
     

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/View/Preview/KMPrintPreviewView.swift

@@ -94,7 +94,7 @@ class KMPrintPreviewView: KMBaseXibView {
             self.pageCountLabel.stringValue = self.previewView.document.pageCount.description
             
             if page != nil {
-                self.titleLabel.stringValue = NSLocalizedString("size", comment: "") + ":" + String(Int(page!.size.width / 28.3 * 10)) + NSLocalizedString("mm", comment: "") + "*" + String(Int(page!.size.height / 28.3 * 10)) + NSLocalizedString("mm", comment: "")
+                self.titleLabel.stringValue = NSLocalizedString("size", comment: "") + ":" + page!.size.width.description + NSLocalizedString("mm", comment: "") + "*" + String(page!.size.height.description) + NSLocalizedString("mm", comment: "")
             }
         }
     }

+ 8 - 0
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/KMPrintSettingView.swift

@@ -31,6 +31,14 @@ class KMPrintSettingView: KMBaseXibView {
         defaultView.printSettingChange = { [unowned self] view, model in
             self.printSettingChange?(self, model)
         }
+        
+        posterView.pageSettingChangeAction = { [unowned self] view, model in
+            self.pageSettingChange?(self, model)
+        }
+        
+        posterView.printSettingChangeAction = { [unowned self] view, model in
+            self.printSettingChange?(self, model)
+        }
     }
     
     override func reloadData() {

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

@@ -7,6 +7,10 @@
 
 import Cocoa
 
+typealias KMPrintPosterViewPageSettingChange = (_ view: KMPrintPosterView, _ model: KMPrintModel) -> Void
+typealias KMPrintPosterViewPrintSettingChange = (_ view: KMPrintPosterView, _ model: KMPrintModel) -> Void
+
+
 class KMPrintPosterView: KMBaseXibView {
 
     @IBOutlet weak var scaleTextField: NSTextField!
@@ -51,11 +55,14 @@ class KMPrintPosterView: KMBaseXibView {
     
     var preview: KMPDFPosterPrintContentView?
     
-    lazy var viewModel: KMPrintViewModel = KMPrintViewModel()
+    var pageSettingChangeAction: KMPrintPosterViewPageSettingChange?
+    var printSettingChangeAction: KMPrintPosterViewPrintSettingChange?
     
+    lazy var viewModel: KMPrintViewModel = KMPrintViewModel()
     
     override func setup() {
-
+        viewModel.model.page.operation.type = .poster
+        
         scaleTextField.stringValue = "100"
         scaleTextField.formatter = TextFieldFormatter()
 
@@ -83,7 +90,7 @@ class KMPrintPosterView: KMBaseXibView {
         
         unitComboBox.selectItem(at: 1)
 
-        var paperArray = KMPrintPaperInfo.KMPaperType.allValues()
+        let paperArray = KMPrintPaperInfo.KMPaperType.allValues()
         var tPaperArray = paperArray
         tPaperArray.removeFirst()
         
@@ -93,7 +100,7 @@ class KMPrintPosterView: KMBaseXibView {
         pageWidthTextField.isEnabled = false
         pageHeightTextField.isEnabled = false
 
-        var tFileArray = paperArray
+        let tFileArray = paperArray
         filePageSizeBox.addItems(withObjectValues: tFileArray)
         filePageSizeBox.selectItem(at: 0)
         filePageSizeBox.isEditable = false
@@ -152,14 +159,15 @@ class KMPrintPosterView: KMBaseXibView {
 
         tableView.tabViewItem(at: 0).label = NSLocalizedString("Tile", comment: "")
         tableView.tabViewItem(at: 1).label = NSLocalizedString("Split", comment: "")
+        tableView.delegate = self
 
-        var paperArray = KMPrintPaperInfo.KMPaperType.allValues() /*KMPageSizeTool.paperSize()*/
+        let paperArray = KMPrintPaperInfo.KMPaperType.allValues() /*KMPageSizeTool.paperSize()*/
         var tPaperArray = paperArray
         tPaperArray.removeFirst()
         splitSizeComboBox.removeAllItems()
         splitSizeComboBox.addItems(withObjectValues: tPaperArray)
 
-        var tFileArray = paperArray
+        let tFileArray = paperArray
         filePageSizeBox.removeAllItems()
         filePageSizeBox.addItems(withObjectValues: tFileArray)
 
@@ -168,23 +176,98 @@ class KMPrintPosterView: KMBaseXibView {
     }
     
     override func reloadData() {
+        let model = viewModel.model
+        
         let poster: KMPrintPageOperation.Poster = viewModel.model.page.operation.poster
         
         columnCountText.stringValue = "\(poster.pageOfPaper.point.x)"
         lineCountText.stringValue = "\(poster.pageOfPaper.point.y)"
+        
+        //pageRange
+        var range: KMPrintPageRange = self.viewModel.model.page.range
+        if range.type == .allPage {
+            pageRangeComboBox.isEditable = false
+            pageRangeComboBox.selectItem(at: 0)
+        } else if range.type == .oddPage {
+            pageRangeComboBox.isEditable = false
+            pageRangeComboBox.selectItem(at: 1)
+        } else if range.type == .evenPage {
+            pageRangeComboBox.isEditable = false
+            pageRangeComboBox.selectItem(at: 2)
+        } else if range.type == .custom {
+            pageRangeComboBox.isEditable = true
+            pageRangeComboBox.selectItem(at: 3)
+            pageRangeComboBox.stringValue = range.pageString
+        }
+        
+        //paper Type
+        if model.paper.info.type == .Actual {
+            filePageSizeBox.selectItem(at: 0)
+            paperWidthTextField.isEnabled = false
+            paperHeightTextField.isEnabled = false
+        } else if model.paper.info.type == .custom {
+            splitSizeComboBox.selectItem(at: splitSizeComboBox.numberOfItems)
+            pageWidthTextField.isEnabled = true
+            pageHeightTextField.isEnabled = true
+            
+            filePageSizeBox.selectItem(at: filePageSizeBox.numberOfItems)
+            paperWidthTextField.isEnabled = true
+            paperHeightTextField.isEnabled = true
+        } else {
+            splitSizeComboBox.selectItem(withObjectValue: model.paper.info.type.rawValue)
+            pageWidthTextField.isEnabled = false
+            pageHeightTextField.isEnabled = false
+            
+            filePageSizeBox.selectItem(withObjectValue: model.paper.info.type.rawValue)
+            paperWidthTextField.isEnabled = false
+            paperHeightTextField.isEnabled = false
+            
+            paperWidthTextField.stringValue = model.paper.info.size.width.description
+            paperHeightTextField.stringValue = model.paper.info.size.height.description
+            
+            pageWidthTextField.stringValue = model.paper.info.size.width.description
+            pageHeightTextField.stringValue = model.paper.info.size.height.description
+        }
+        
+        //page per
+        if model.page.operation.poster.pageOfPaper.type == .custom {
+            columnCountText.isEditable = true
+            lineCountText.isEditable = true
+            columnCountText.isSelectable = true
+            lineCountText.isSelectable = true
+        } else {
+            columnCountText.isEditable = false
+            lineCountText.isEditable = false
+            columnCountText.isSelectable = false
+            lineCountText.isSelectable = false
+            
+            lineCountText.stringValue = model.page.operation.poster.pageOfPaper.point.x.description
+            columnCountText.stringValue = model.page.operation.poster.pageOfPaper.point.y.description
+        }
     }
     
-    
+    func updatePDFView(isPageChange: Bool = true) {
+        debugPrint("需要刷新PDFView")
+        self.reloadData()
+        if isPageChange {
+            self.pageSettingChangeAction?(self, self.viewModel.model)
+        } else {
+            self.printSettingChangeAction?(self, self.viewModel.model)
+        }
+    }
+}
+
+extension KMPrintPosterView {
     //MARK: Action
     @IBAction func buttonItemClickCutMarks(_ sender: NSButton) {
         self.viewModel.posterCutMarkAction(isSelect: cutMarksButton.state == .on, completion: { success, model in
-                
+            self.updatePDFView()
         })
     }
 
     @IBAction func buttonItemClickLabels(_ sender: NSButton) {
         self.viewModel.posterTagsAction(isSelect: cutMarksButton.state == .on, tags:[labelTextField.stringValue]) { success, model in
-            
+            self.updatePDFView(isPageChange: false)
         }
     }
 
@@ -197,7 +280,7 @@ class KMPrintPosterView: KMBaseXibView {
         }
         
         self.viewModel.printDirectionAction(type: direction, completion: { success, model in
-            
+            self.updatePDFView(isPageChange: false)
         })
     }
 
@@ -205,11 +288,8 @@ class KMPrintPosterView: KMBaseXibView {
     @IBAction func comboBoxItemClickPageRange(_ sender: NSComboBox) {
         var range: KMPrintPageRange = KMPrintPageRange()
         if sender.indexOfSelectedItem == 0 ||
-            sender.indexOfSelectedItem == 1 || 
+            sender.indexOfSelectedItem == 1 ||
             sender.indexOfSelectedItem == 2 {
-            window?.makeFirstResponder(self)
-            sender.isEditable = false
-            
             if sender.indexOfSelectedItem == 0 {
                 range.type = .allPage
             } else if sender.indexOfSelectedItem == 1 {
@@ -219,59 +299,41 @@ class KMPrintPosterView: KMBaseXibView {
             }
         } else if sender.indexOfSelectedItem == 3 {
             sender.stringValue = ""
-            sender.isEditable = true
             window?.makeFirstResponder(sender)
             
             range.type = .custom
             range.pageString = sender.stringValue
         }
         self.viewModel.pageRangeAction(range: range) { success, model in
-            
+            self.updatePDFView()
         }
     }
 
     @IBAction func comboBoxItemClickSplitSize(_ sender: NSComboBox) {
         overlapTextField.stringValue = "0"
-        var customSize = CGSize(width: 595, height: 842)
+        let customSize = CGSize(width: 595, height: 842)
 //        self.PDFPrint.splitSize = CGSizeMake(tSize.width * 595.0/210, tSize.height * 842.0/297.0);
-        if splitSizeComboBox.indexOfSelectedItem == splitSizeComboBox.numberOfItems - 1 {
-            pageWidthTextField.isEnabled = true
-            pageHeightTextField.isEnabled = true
-        } else {
-            pageWidthTextField.isEnabled = false
-            pageHeightTextField.isEnabled = false
-        }
 
         let type = KMPrintPaperInfo.KMPaperType(rawValue: sender.stringValue) ?? .A4
         self.viewModel.printPaperTypeAction(type: type, customSize: customSize, completion: { success, model in
-            
+            self.updatePDFView()
         })
         
     }
 
     @IBAction func comboBoxItemClickFullPageSize(_ sender: NSComboBox) {
         var customSize = CGSize(width: 595, height: 842)
-        if filePageSizeBox.indexOfSelectedItem == 0 {
-            paperWidthTextField.isEnabled = false
-            paperHeightTextField.isEnabled = false
-        } else if filePageSizeBox.indexOfSelectedItem == filePageSizeBox.numberOfItems - 1 {
-            paperWidthTextField.isEnabled = true
-            paperHeightTextField.isEnabled = true
-        } else {
-            paperWidthTextField.isEnabled = false
-            paperHeightTextField.isEnabled = false
-        }
 
         overlapTextField.stringValue = "0"
         let type = KMPrintPaperInfo.KMPaperType(rawValue: sender.stringValue) ?? .A4
         self.viewModel.printPaperTypeAction(type: type, posterType: .breakUp, customSize: customSize, completion: { success, model in
-            
+            self.updatePDFView()
         })
     }
 
     @IBAction func buttonItemClickReversePage(_ sender: NSButton) {
         self.viewModel.printReverseAction(isSelect: reverseButton.state == .on) { success, model in
-            
+            self.updatePDFView()
         }
     }
 
@@ -292,7 +354,7 @@ class KMPrintPosterView: KMBaseXibView {
         
         overlapTextField.stringValue = "0"
         self.viewModel.printOverlapChangeAction(value: overlapTextField.floatValue, completion: { success, model in
-            
+            self.reloadData()
         })
     }
 
@@ -307,28 +369,18 @@ class KMPrintPosterView: KMBaseXibView {
         }
         
         self.viewModel.printContentAction(type: type, completion: { success, model in
-            
+            self.updatePDFView()
         })
     }
 
     @IBAction func comboBoxItemClickPagesPer(_ sender: NSComboBox) {
-        if selectPerComboBox.indexOfSelectedItem != 5 {
-            columnCountText.isEditable = false
-            lineCountText.isEditable = false
-            columnCountText.isSelectable = false
-            lineCountText.isSelectable = false
-        } else {
-            columnCountText.isEditable = true
-            lineCountText.isEditable = true
-            columnCountText.isSelectable = true
-            lineCountText.isSelectable = true
-        }
-        
         self.viewModel.printPagePerChangeAction(type: KMPrintPageOperation.PageOfPaper.PageType(rawValue: selectPerComboBox.stringValue) ?? .page, completion: { success, model in
-            
+            self.updatePDFView()
         })
     }
+}
 
+extension KMPrintPosterView: NSTabViewDelegate {
     func tabView(_ tabView: NSTabView, willSelect tabViewItem: NSTabViewItem?) {
         overlapTextField.stringValue = "0"
         self.viewModel.printOverlapChangeAction(value: overlapTextField.floatValue, completion: { success, model in
@@ -338,16 +390,18 @@ class KMPrintPosterView: KMBaseXibView {
         if let identifier = tabViewItem?.identifier as? String {
             if identifier == "1" {
                 self.viewModel.posterTypeAction(type: .tile) { success, model in
-                    
+                    self.updatePDFView()
                 }
             } else {
                 self.viewModel.posterTypeAction(type: .breakUp) { success, model in
-                    
+                    self.updatePDFView()
                 }
             }
         }
     }
-    
+}
+
+extension KMPrintPosterView  {
     @objc func controlTextDidEndEditing(_ notification: Notification) {
         guard let textField = notification.object as? NSTextField else {
             return
@@ -411,7 +465,7 @@ class KMPrintPosterView: KMBaseXibView {
             var size = self.viewModel.model.paper.info.size
             size.width = over
             self.viewModel.printPaperTypeAction(type: .custom, customSize: size, completion: { success, model in
-                
+                self.updatePDFView()
             })
             
         } else if textField == pageHeightTextField || textField == paperHeightTextField {
@@ -430,7 +484,7 @@ class KMPrintPosterView: KMBaseXibView {
             var size = self.viewModel.model.paper.info.size
             size.width = over
             self.viewModel.printPaperTypeAction(type: .custom, customSize: size, completion: { success, model in
-                
+                self.updatePDFView()
             })
         }
     }
@@ -468,7 +522,6 @@ class KMPrintPosterView: KMBaseXibView {
             }
         }
     }
-
 }
 
 

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

@@ -209,7 +209,6 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
         fontSizeCombobox.addItems(withObjectValues: ["9","10","11","12","13","14","18","24","36","48","64","72","96","144","288"])
         fontSizeCombobox.formatter = TextFieldFormatter()
         
-        watermarkStringTextView.string = watermark.text 
         watermarkStringTextView.delegate = self
         
         pageRangeComboBox.removeAllItems()
@@ -246,7 +245,6 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
         verticalIconButton.toolTip = NSLocalizedString("Vertical Distance", comment: "")
         fontSizeLabel.stringValue = "\(NSLocalizedString("Font Size", comment: "")):"
         colorLabel.stringValue = "\(NSLocalizedString("Color", comment: "")):"
-        colorWell.color = watermark.getTextColor()
         templateNameTextField.stringValue = watermark.watermarkID ?? ""
         
         appearanceBox.title = NSLocalizedString("Appearance", comment: "")
@@ -278,6 +276,9 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
         guard let pdfDocument = pdfDocument else { return }
         let opacity = round(watermark.opacity * 100) / 100
         
+        watermarkStringTextView.string = watermark.text
+        colorWell.color = watermark.getTextColor()
+        
         totalPageCountLabel.stringValue = "/ \(pdfDocument.pageCount)"
         
         fontSizeCombobox.stringValue = "\(watermark.getTextFontSize())"