// // KMMainViewController+UI.swift // PDF Reader Pro // // Created by wanjun on 2022/12/15. // import Foundation extension KMMainViewController { // MARK: - 退出全屏 @IBAction func startSpeaking(_ sender: Any) { self.showTTSWindow() let ttsView = KMTTSWindowController.share ttsView.buttonItemClick_Play(ttsView.playButton) } @IBAction func stopSpeaking(_ sender: Any) { let ttsWindowC = KMTTSWindowController.share if ttsWindowC.pdfView?.document?.documentURL.path == self.listView.document?.documentURL.path { if let data = ttsWindowC.window?.isVisible, data { ttsWindowC.stopSpeaking() ttsWindowC.close() } } } } extension KMMainViewController { //通知 func preferenceDidChangeNotification(notification:Notification) { let info : [AnyHashable : Any] = notification.userInfo ?? [:] if info.keys.contains(KMPreference.viewZoomScaleTypeKey) { self.selectZoom(KMPreferenceManager.shared.viewZoomScaleType) } if notification.name.rawValue == "pdfViewDocumentDidLoaded" || info.keys.contains(KMPreference.viewPageDisplayTypeKey) { } if info.keys.contains(KMPreference.displayBackgroundNormalColorKey) || notification.name.rawValue == "pdfViewDocumentDidLoaded" { self.listView.backgroundColor = KMPreferenceManager.shared.displayBackgroundNormalColor self.listView.layoutDocumentView() } if (info.keys.contains(KMPreference.generalAuthorNameKey)) { // 作者名称 CPDFKitConfig.sharedInstance().setAnnotationAuthor((info[KMPreference.generalAuthorNameKey] as! String)) } if (info.keys.contains(KMPreference.highlightLinksKey)) { let hlLink = info[KMPreference.highlightLinksKey] as? Bool CPDFKitConfig.sharedInstance().setEnableLinkFieldHighlight(hlLink == nil ? false : hlLink!) self.listView.setNeedsDisplayForVisiblePages() } if info.keys.contains(KMPreference.thumbPageSizeKey) { self.leftSideViewController.refreshUIOfThumbnailIfNeed(preference: true) } if info.keys.contains(KMPreference.thumbSnapshotSizeKey) { self.leftSideViewController.refreshUIOfSnapshotIfNeed(preference: true) } if info.keys.contains(KMPreference.outlineFontSizeKey) { self.leftSideViewController.updateTableFont() } if info.keys.contains(KMPreference.greekThresholdKey) { let value = KMPreference.shared.greekThreshold.cgFloat self.listView.setGreekingThreshold(value) } if info.keys.contains(KMPreference.antiAliasTextKey) { self.listView.setShouldAntiAlias(KMPreference.shared.antiAliasText) self.listView.applyDefaultInterpolationQuality() } if info.keys.contains(KMPreference.markupColorHighlightKey) { } if info.keys.contains(KMPreference.markupColorUnderlineKey) { } if info.keys.contains(KMPreference.markupColorStrikthroughKey) { } if info.keys.contains(KMPreference.markupColorPenKey) { } if info.keys.contains(KMPreference.editPDFPopWindowShowKey) { let show = KMPreference.shared.editPDFPopWindowIsShow let win = KMEditPDFPopToolBarWindow.shared if !show && win.isVisible { win.orderOut(nil) win.setIsVisible(false) } } } func showConvertNotesProgress() { guard let pdfDocument = self.document else { return } guard let _ = self.listView.document else { return } guard let _ = self.view.window else { return } let isNewCreated = (self.myDocument as? KMMainDocument)?.isNewCreated ?? false if isNewCreated { return } self.model.needConvertNotes = false Task { @MainActor in self.convertNotesUsingPDFDocument(pdfDocument) } } func convertNotesUsingPDFDocument(_ pdfDocument: CPDFDocument, callback: (()->Void)? = nil) { guard let doc = self.listView.document else { return } DispatchQueue.main.async { self.beginProgressSheet(withMessage: "", maxValue: 0) let count = pdfDocument.pageCount DispatchQueue.global().async { self.model.addAnnotations.removeAll() self.model.removeAnnotations.removeAll() for i in 0..") { let table = KMTableAnnotation(KMNoteBounds: inkAnnotation.bounds, document: doc) table.border = inkAnnotation.border table.color = inkAnnotation.color table.createForm(withList: inkAnnotation.contents, andPaths: inkAnnotation.bezierPaths()) table.updateAppearanceInk(withIsAdd: false) table.contents = annotation.contents newAnnotation = table } if let newAnnotation = newAnnotation { self.model.addAnnotations.append(newAnnotation) self.model.removeAnnotations.append(annotation) } } } DispatchQueue.main.async { for i in 0.. NSRect { if isMiniaturize && self.interactionMode != .presentation { if self.interactionMode != .legacyFullScreen && self.model.leftPanelOpen == false { self.toggleLeftPane() } else if self.interactionMode == .legacyFullScreen { } var row = NSNotFound for (i,sp) in self.leftSideViewController.snapshots.enumerated() { if controller.isEqual(sp.windowC) { row = i } } if (row != NSNotFound) { if self.leftSideViewController.type.methodType != .snapshot { self.leftSideViewController.leftView.segmentedControl.selectedSegment = 5 } else { self.leftSideViewController.refreshUIOfSnapshotIfNeed() } self.leftSideViewController.snapshotTableView.scrollRowToVisible(row) } } return self.leftSideViewController.snapshotController(controller, miniaturizedRect: isMiniaturize) } func snapshotControllerDidFinishSetup(_ controller: KMSnapshotWindowController) { self.leftSideViewController.snapshotControllerDidFinishSetup(controller) } } // MARK: - CPDFDocumentDelegate extension KMMainViewController: CPDFDocumentDelegate { func documentDidBeginDocumentFind(_ document: CPDFDocument!) { self.leftSideViewController.documentDidBeginFind() } func documentDidEndDocumentFind(_ document: CPDFDocument!) { self.leftSideViewController.documentDidEndFind() } } // MAKR: - CPDFViewDelegate,CPDFListViewDelegate