// // KMCropController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/20. // import Cocoa import KMComponentLibrary class KMCropController: NSViewController { @IBOutlet var contendView: NSView! @IBOutlet var preInfoView: NSView! @IBOutlet var propertyInfoView: NSView! var pdfDocument: CPDFDocument? var documentPreview: KMEditDocumentController = KMEditDocumentController.init() var propertyController: KMCropPropertyController = KMCropPropertyController.init() var coverController: KMCropCoverController? override func viewDidLoad() { super.viewDidLoad() // Do view setup here. setup() } func setup() { view.wantsLayer = true view.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor documentPreview.view.frame = preInfoView.bounds documentPreview.view.autoresizingMask = [.width, .height] documentPreview.pdfView.pdfListViewDelegate = self preInfoView.addSubview(documentPreview.view) propertyController.view.frame = propertyInfoView.bounds propertyController.view.autoresizingMask = [.width, .height] propertyInfoView.addSubview(propertyController.view) // if coverController == nil { // coverController = KMCropCoverController.init() // } // coverController?.view.frame = CGRectInset(documentPreview.pdfView.bounds, 0, 0) // coverController?.view.autoresizingMask = [.width, .height] // preInfoView.addSubview(coverController!.view) } func reloadData() { guard let pdfDocument = pdfDocument else { return } documentPreview.pdfDocument = pdfDocument documentPreview.reloadData() let page = pdfDocument.page(at: 0) let bounds = page?.bounds ?? CGRectZero documentPreview.pdfView.toolMode = .selectToolMode documentPreview.pdfView.selectionRect = bounds propertyController.pdfView = documentPreview.pdfView propertyController.reloadData() } } extension KMCropController: CPDFListViewDelegate { func pdfListViewChangedSelectionOrMagnification(_ pdfListView: CPDFListView!) { print("pdfListViewChangedSelectionOrMagnification") propertyController.reloadData() } func pdfListViewDidSelectionEnd(_ pdfListView: CPDFListView!) { print("pdfListViewDidSelectionEnd") propertyController.reloadData() } }