// // KMPrintPreviewView.swift // PDF Reader Pro // // Created by lizhe on 2022/12/8. // import Cocoa class KMPrintPreviewView: KMBaseXibView { @IBOutlet weak var previewContentView: NSView! @IBOutlet weak var previewView: PDFView! @IBOutlet weak var posterPreView: KMPrintPosterPreviewView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var previousButton: NSButton! @IBOutlet weak var nextButton: NSButton! @IBOutlet weak var currentPageTextField: KMBaseTextField! @IBOutlet weak var pageCountLabel: NSTextField! @IBOutlet weak var partitionLabel: NSTextField! var isPrintPreView: Bool = true var reversePrintOrder: Bool = false var password: String = "" var model: KMPrintModel? { didSet { self.reloadData() } } private lazy var presenter: KMPrintPreviewPresenter = KMPrintPreviewPresenter() var pdfDocument: PDFDocument? { didSet { self.previewView.document = pdfDocument //PDFDocument(url: pdfDocument!.documentURL) self.previewView.document?.unlock(withPassword: password) self.previewView.autoScales = true self.previewView.displayMode = .singlePage self.previewView.documentView?.enclosingScrollView?.scrollerStyle = .overlay if model?.page.operation.type == .poster { // self.presenter.pdfView = self.previewView self.presenter.initPresenter(delegate: self, view: self.previewView) } else { self.presenter.initPresenter(delegate: self, view: self.previewView) } self.reloadData() } // didSet { // // if self.previewView.document != nil { // self.previewView.needsDisplay = true // self.reloadData() // } else { // // var pdfDocument2 = PDFDocument(url: pdfDocument!.documentURL) // var tempDocument = PDFDocument() // // var pages: [PDFPage] = [] // for i in 0.. Void { // self.reloadData() } } protocol KMPrintPreviewViewAction { } extension KMPrintPreviewView: KMPrintPreviewViewAction { @IBAction func nextButton(_ sender: NSButton) { self.presenter.nextPage() } @IBAction func previousAction(_ sender: NSButton) { self.presenter.previousPage() } func toPageIndex(_ index: UInt = 0) { self.presenter.toPage(index: Int(index)) } } extension KMPrintPreviewView: KMPrintPreviewPresenterDelegate { func dataDidChange(presenter: KMPrintPreviewPresenter, view: PDFView) { self.reloadData() } func documentDidChange(presenter: KMPrintPreviewPresenter, document: PDFDocument) { self.previewView.document = document self.reloadData() } } extension KMPrintPreviewView { func updatePosterPreView() { guard let model = model else { return } if model.page.operation.type == .poster { var size = self.previewView.frame.size let rect = self.previewView.currentPage?.bounds(for: .cropBox) let scale = self.previewView.scaleFactor let offest = CGPointMake((rect?.origin.x)! * scale, (rect?.origin.y)! * scale) size = CGSizeMake(rect!.size.width * scale, rect!.size.height * scale) var point = CGPoint(x: 1, y: 1) if model.page.operation.poster.type == .tile { point = model.page.operation.poster.tilePoint } else { point = model.page.operation.pageOfPaper.point } var horizontals: [Int] = [] var verticals: [Int] = [] let pointX: Int = Int(point.x) let pointY: Int = Int(point.y) for i in 0..