KMMainDocument.swift 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. //
  2. // KMMainDocument.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/12/6.
  6. //
  7. import Cocoa
  8. import CoreFoundation
  9. @objc enum KMArchiveMask: Int {
  10. case diskImage = 1
  11. case email = 2
  12. }
  13. typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> ()
  14. @objcMembers class KMMainDocument: CTTabContents {
  15. struct MDFlags {
  16. var exportOption: UInt32 // assuming this is a 2-bit field, change to appropriate data type
  17. var exportUsingPanel: UInt32 // assuming this is a 1-bit field, change to appropriate data type
  18. var gettingFileType: UInt32 // assuming this is a 1-bit field, change to appropriate data type
  19. var convertingNotes: UInt32 // assuming this is a 1-bit field, change to appropriate data type
  20. var needsPasswordToConvert: UInt32 // assuming this is a 1-bit field, change to appropriate data type
  21. }
  22. var mainViewController: KMMainViewController?
  23. var homeWindowController: KMHomeWindowController?
  24. var homeViewController: KMHomeViewController?
  25. var bookmarkSheetController: KMBookmarkSheetController?
  26. var bookmarkController: KMBookmarkController?
  27. var isNewCreated: Bool = false
  28. var closedByUserGestureFlag: Bool = false // 标记 closedByUserGesture 这个状态需要延后存储(如果需要)
  29. var cloud: Bool = false
  30. var cloudUploadHanddler: KMMainDocumentCloudUploadHanddler?
  31. var isUnlockFromKeychain: Bool = false
  32. private var _saveAsing = false
  33. var fileUpdateChecker: SKFileUpdateChecker?
  34. var mdFlags: MDFlags?
  35. var currentDocumentSetup: [String: Any] {
  36. get {
  37. var tempSetup: [String: Any] = [:]
  38. var tempMainSetup: [String: Any] = mainViewController?.currentSetup() ?? [:]
  39. let data = (fileURL != nil) ? SKAlias.init(url: fileURL).data : nil
  40. let filePath = fileURL?.path ?? ""
  41. tempSetup.updateValue(filePath, forKey: KMDocumentSetupFileNameKey)
  42. if data != nil {
  43. tempSetup.updateValue(data!, forKey: KMDocumentSetupAliasKey)
  44. }
  45. if tempSetup.count != 0 {
  46. tempSetup.merge(tempMainSetup) { (_, new) in new }
  47. }
  48. return tempSetup
  49. }
  50. set {
  51. }
  52. }
  53. private var _saveToURL: URL?
  54. var saveToURL: URL? {
  55. get {
  56. return self._saveToURL
  57. }
  58. }
  59. weak var watermarkSaveDelegate: AnyObject?
  60. private var _trackEvents = IndexSet()
  61. override func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
  62. if (self.isNewCreated) {
  63. // if let data = self.mainViewController, !data.isPDFDocumentEdited && !data.needSave && !self.isDocumentEdited {
  64. self._km_save(to: url, ofType: typeName, for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  65. return
  66. // }
  67. }
  68. if (!self.needSaveWatermark()) {
  69. self._km_save(to: url, ofType: typeName, for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  70. return
  71. }
  72. var openAccessoryView = self.watermarkSaveDelegate != nil
  73. if (openAccessoryView) {
  74. if let _browser = self.watermarkSaveDelegate as? KMBrowser, _browser.isCloseAllTabViewItem {
  75. openAccessoryView = false
  76. }
  77. }
  78. self._km_saveForWatermark(openAccessoryView: openAccessoryView) { [unowned self] in
  79. self.trackEvents()
  80. } callback: { [unowned self] needSave, params in
  81. if (needSave) {
  82. self._km_save(to: url, ofType: typeName, for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  83. } else { // 水印保存
  84. if (self.watermarkSaveDelegate == nil) {
  85. if let data = params.first as? KMResult, data == .cancel {
  86. if let shouldClose = params.last as? Bool, shouldClose {
  87. DispatchQueue.main.async {
  88. self.mainViewController?.browserWindowController?.browser.windowDidBeginToClose()
  89. }
  90. }
  91. } else {
  92. DispatchQueue.main.async {
  93. self.mainViewController?.browserWindowController?.browser.windowDidBeginToClose()
  94. }
  95. }
  96. return
  97. }
  98. if let data = params.first as? KMResult, data == .cancel {
  99. if var shouldClose = params.last as? Bool {
  100. if let _browser = self.watermarkSaveDelegate as? KMBrowser, _browser.isCloseAllTabViewItem {
  101. shouldClose = true
  102. }
  103. (self.watermarkSaveDelegate as? KMBrowser)?.document(self, shouldClose: shouldClose, contextInfo: nil)
  104. }
  105. } else {
  106. (self.watermarkSaveDelegate as? KMBrowser)?.document(self, shouldClose: true, contextInfo: nil)
  107. }
  108. self.watermarkSaveDelegate = nil
  109. }
  110. }
  111. }
  112. override func makeWindowControllers() {
  113. // Returns the storyboard that contains your document window.
  114. if ((self.fileURL?.path) != nil) {
  115. if !self.fileURL!.path.isPDFValid() {
  116. let alert = NSAlert()
  117. alert.alertStyle = .critical
  118. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  119. alert.runModal()
  120. return
  121. }
  122. }
  123. let mainWindow = NSApp.mainWindow
  124. var currentWindowController: KMBrowserWindowController?
  125. if mainWindow != nil {
  126. let windowController = mainWindow!.windowController
  127. if windowController is KMBrowserWindowController {
  128. currentWindowController = (windowController as! KMBrowserWindowController)
  129. } else {
  130. for window in NSApp.windows {
  131. let windowController = window.windowController
  132. if windowController is KMBrowserWindowController {
  133. currentWindowController = (windowController as! KMBrowserWindowController)
  134. break
  135. }
  136. }
  137. }
  138. } else {
  139. for window in NSApp.windows {
  140. let windowController = window.windowController
  141. if windowController is KMBrowserWindowController {
  142. currentWindowController = (windowController as! KMBrowserWindowController)
  143. break
  144. }
  145. }
  146. }
  147. if (currentWindowController == nil) && (self.fileURL != nil) {
  148. let browser = KMBrowser.init() as KMBrowser
  149. browser.addHomeTabContents()
  150. browser.windowController = KMBrowserWindowController.init(browser: browser)
  151. currentWindowController = browser.windowController as? KMBrowserWindowController
  152. }
  153. if currentWindowController?.browser == nil && (self.fileURL != nil) {
  154. let browser: KMBrowser = KMBrowser.init()
  155. browser.windowController = KMBrowserWindowController.init(browser: browser)
  156. browser.addHomeTabContents()
  157. currentWindowController = browser.windowController as? KMBrowserWindowController
  158. browser.windowController.showWindow(self)
  159. }
  160. mainViewController = KMMainViewController.init()
  161. mainViewController?.myDocument = self
  162. if ((self.fileURL?.path) != nil) {
  163. let pdfDocument = CPDFDocument.init(url: URL(fileURLWithPath: self.fileURL!.path))
  164. mainViewController?.document = pdfDocument
  165. }
  166. self.view = mainViewController?.view
  167. if let currentBrowser = currentWindowController?.browser {
  168. // currentWindowController?.browser.add(self, at: Int32()-1, inForeground: true)
  169. // self.addWindowController(currentWindowController!)
  170. // mainViewController.browserWindowController = currentWindowController
  171. let activeBrowser = currentBrowser.activeTabContents()
  172. let activeIndex = currentBrowser.activeTabIndex()
  173. self.addWindowController(currentWindowController!)
  174. self.mainViewController?.browserWindowController = currentWindowController
  175. let ishome = activeBrowser?.isHome ?? false
  176. let isfirstTab = (activeIndex == 0)
  177. if ishome && !isfirstTab {
  178. // 替换 document
  179. currentWindowController?.browser.replaceTabContents(at: Int32(activeIndex), with: self)
  180. // 刷新标签
  181. currentWindowController?.browser.updateTabState(at: Int32(activeIndex))
  182. // 刷新 home icon
  183. if let tabStripController = currentWindowController?.tabStripController {
  184. if let view = tabStripController.view(at: UInt(activeIndex)) as? CTTabView {
  185. view.controller().isHome = self.isHome
  186. view.controller().isNewTab = self.isNewTab
  187. view.controller().updateUI()
  188. }
  189. }
  190. } else {
  191. if currentWindowController?.browser.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
  192. let window = NSWindow.currentWindow()
  193. if !KMDataManager.default.isTabbingWin{
  194. KMDataManager.default.isTabbingWin = true
  195. let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
  196. tabbingWin.selectCallBack = {[weak self] continueOrNot in
  197. KMDataManager.default.isTabbingWin = false
  198. if continueOrNot {
  199. self?.reopenDocument(forPaths: [])
  200. } else {
  201. }
  202. }
  203. window.km_beginSheet(windowC: tabbingWin)
  204. }
  205. }else {
  206. currentWindowController?.browser.add(self, at: Int32()-1, inForeground: true)
  207. }
  208. }
  209. }
  210. }
  211. func reopenDocument(forPaths paths: [String]) -> Void {
  212. let browser = KMBrowser.init() as KMBrowser
  213. browser.windowController = KMBrowserWindowController.init(browser: browser)
  214. browser.addHomeTabContents()
  215. browser.windowController.showWindow(self)
  216. }
  217. override func showWindows() {
  218. super.showWindows()
  219. self.setDataFromTmpData()
  220. }
  221. override func windowControllerDidLoadNib(_ aController: NSWindowController) {
  222. super.windowControllerDidLoadNib(aController)
  223. self.setDataFromTmpData()
  224. fileUpdateChecker = SKFileUpdateChecker.init(for: self)
  225. fileUpdateChecker?.isEnabled = true
  226. }
  227. override func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) async throws {
  228. do {
  229. try await super.save(to: url, ofType: typeName, for: saveOperation)
  230. } catch let outError {
  231. Swift.print(outError)
  232. }
  233. }
  234. override func write(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws {
  235. try self._km_write(to: url, ofType: typeName, for: saveOperation, originalContentsURL: absoluteOriginalContentsURL)
  236. }
  237. override func canClose(withDelegate delegate: Any, shouldClose shouldCloseSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
  238. let isPrompt = KMPreferenceManager.shared.closeFileIsPrompt()
  239. if (isPrompt) {
  240. super.canClose(withDelegate: delegate, shouldClose: shouldCloseSelector, contextInfo: contextInfo)
  241. return
  242. }
  243. if (self.isNewCreated) {
  244. self.save(nil)
  245. } else if (self.isDocumentEdited) {
  246. self.save(nil)
  247. } else if (mainViewController != nil) {
  248. if self.mainViewController!.isPDFDocumentEdited || self.mainViewController!.needSave {
  249. self.save(nil)
  250. }
  251. }
  252. super.canClose(withDelegate: delegate, shouldClose: shouldCloseSelector, contextInfo: contextInfo)
  253. }
  254. override func saveAs(_ sender: Any?) {
  255. if (!self.needSaveWatermark()) {
  256. self._km_saveAs(sender)
  257. return
  258. }
  259. self._km_saveForWatermark { [unowned self] needSave, _ in
  260. if (needSave) {
  261. self._km_saveAs(sender)
  262. }
  263. }
  264. }
  265. override func runModalSavePanel(for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
  266. if (self.isNewCreated) {
  267. // if let data = self.mainViewController, !data.isPDFDocumentEdited && !data.needSave && !self.isDocumentEdited {
  268. self._km_runModalSavePanel(for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  269. return
  270. // }
  271. }
  272. if (!self.needSaveWatermark()) {
  273. self._km_runModalSavePanel(for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  274. return
  275. }
  276. self._km_saveForWatermark { [unowned self] needSave, _ in
  277. if (needSave) {
  278. self._km_runModalSavePanel(for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  279. }
  280. }
  281. }
  282. override func save(_ sender: Any?) {
  283. if (!self.needSaveWatermark()) {
  284. self._km_save(sender)
  285. return
  286. }
  287. self._km_saveForWatermark { [unowned self] in
  288. self.trackEvents()
  289. } callback: { [unowned self] needSave, _ in
  290. if (needSave) {
  291. self._km_save(sender)
  292. }
  293. }
  294. }
  295. func systemInteractionMode() -> KMInteractionMode {
  296. let mainWindow = NSApp.mainWindow
  297. if mainWindow != nil {
  298. let windowController = mainWindow!.windowController
  299. if windowController?.window?.screen?.isEqual(NSScreen.screens[0]) ?? false{
  300. return mainViewController?.interactionMode ?? .normal
  301. }
  302. }
  303. return .normal
  304. }
  305. func saveForWatermark() {
  306. if (!self.needSaveWatermark()) {
  307. self._km_save(nil)
  308. return
  309. }
  310. self._km_saveForWatermark { [unowned self] in
  311. self.trackEvents()
  312. } callback: { [unowned self] needSave, params in
  313. if (needSave) {
  314. self._km_save(nil)
  315. } else { // 水印保存
  316. if (self.watermarkSaveDelegate == nil) {
  317. if let data = params.first as? KMResult, data == .cancel {
  318. if let shouldClose = params.last as? Bool, shouldClose {
  319. DispatchQueue.main.async {
  320. self.mainViewController?.browserWindowController?.browser.windowDidBeginToClose()
  321. }
  322. }
  323. } else {
  324. DispatchQueue.main.async {
  325. self.mainViewController?.browserWindowController?.browser.windowDidBeginToClose()
  326. }
  327. }
  328. return
  329. }
  330. if let data = params.first as? KMResult, data == .cancel {
  331. if var shouldClose = params.last as? Bool {
  332. if let _browser = self.watermarkSaveDelegate as? KMBrowser, _browser.isCloseAllTabViewItem {
  333. shouldClose = true
  334. }
  335. (self.watermarkSaveDelegate as? KMBrowser)?.document(self, shouldClose: shouldClose, contextInfo: nil)
  336. }
  337. } else {
  338. (self.watermarkSaveDelegate as? KMBrowser)?.document(self, shouldClose: true, contextInfo: nil)
  339. }
  340. self.watermarkSaveDelegate = nil
  341. }
  342. }
  343. }
  344. override func read(from absoluteURL: URL, ofType typeName: String) throws {
  345. do {
  346. try super.read(from: absoluteURL, ofType: typeName)
  347. updateChangeCount(.changeCleared)
  348. } catch let outError {
  349. Swift.print(outError)
  350. }
  351. }
  352. override func read(from data: Data, ofType typeName: String) throws {
  353. // Insert code here to read your document from the given data of the specified type, throwing an error in case of failure.
  354. // Alternatively, you could remove this method and override read(from:ofType:) instead. If you do, you should also override isEntireFileLoaded to return false if the contents are lazily loaded.
  355. let pdfDocument = CPDFDocument.init(data: data)
  356. if pdfDocument == nil {
  357. throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
  358. }
  359. }
  360. // MARK: Autosaving
  361. override func close() {
  362. if self.isActive {
  363. if browser != nil {
  364. var activeIndex = 0
  365. let dex = browser.index(of: self)
  366. if dex == browser.tabCount() - 1 {
  367. activeIndex = Int(browser.tabCount()-2)
  368. } else {
  369. activeIndex = Int(dex + 1)
  370. }
  371. let activeContents = browser.tabContents(at: Int32(activeIndex))
  372. activeContents?.addWindowController(browser.windowController)
  373. }
  374. }
  375. super.close()
  376. }
  377. // MARK: init
  378. override init() {
  379. super.init()
  380. // Add your subclass-specific initialization here.
  381. NotificationCenter.default.addObserver(self, selector: #selector(pdfChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "CPDFListViewAnnotationsAttributeHasChangeNotification"), object: nil)
  382. // NotificationCenter.default.addObserver(self, selector: #selector(pdfChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "CPDFViewDocumentChangedNotification"), object: nil)
  383. // NotificationCenter.default.addObserver(self, selector: #selector(pdfChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "CPDFViewPageChangedNotification"), object: nil)
  384. NotificationCenter.default.addObserver(self, selector: #selector(pdfChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "CPDFListViewDidAddAnnotationNotification"), object: nil)
  385. NotificationCenter.default.addObserver(self, selector: #selector(pdfChangedNotification(_:)), name: NSNotification.Name.CPDFViewPageChanged, object: nil)
  386. }
  387. override init?(baseTabContents baseContents: CTTabContents?) {
  388. super.init(baseTabContents: baseContents)
  389. if isHome {
  390. homeViewController = KMHomeViewController.init()
  391. homeViewController?.myDocument = self
  392. self.view = homeViewController?.view
  393. }
  394. }
  395. // MARK: Handling User Actions
  396. override var title: String? {
  397. get {
  398. if isHome {
  399. if (self.isNewTab) {
  400. return NSLocalizedString("New Tab", comment: "")
  401. } else {
  402. return NSLocalizedString("Home", comment: "")
  403. }
  404. } else {
  405. return fileURL?.lastPathComponent
  406. }
  407. }
  408. set {
  409. super.title = newValue
  410. }
  411. }
  412. func needSaveWatermark() -> Bool {
  413. if let need = self.mainViewController?.saveWatermarkFlag {
  414. return need
  415. }
  416. return false
  417. }
  418. // MARK: Private Methods
  419. func pdfChangedNotification(_ notification: Notification) -> Void {
  420. if !isHome {
  421. let mainViewController = mainViewController
  422. var document: CPDFDocument!
  423. let dic = notification.object as? NSDictionary
  424. if dic?["object"] is CPDFAnnotation {
  425. let annotation : CPDFAnnotation = dic?["object"] as? CPDFAnnotation ?? CPDFAnnotation()
  426. document = annotation.page.document
  427. } else if dic?["object"] is CPDFListView {
  428. let pdflistView = notification.object as? CPDFListView
  429. document = pdflistView?.document
  430. }
  431. if mainViewController != nil {
  432. if document == mainViewController!.document {
  433. updateChangeCount(.changeDone)
  434. }
  435. }
  436. }
  437. }
  438. override func updateChangeCount(_ change: NSDocument.ChangeType) {
  439. let mainWindow = NSApp.mainWindow
  440. var currentWindowController: KMBrowserWindowController?
  441. if mainWindow != nil {
  442. let windowController = mainWindow!.windowController
  443. if windowController is KMBrowserWindowController {
  444. currentWindowController = (windowController as! KMBrowserWindowController)
  445. } else {
  446. for window in NSApp.windows {
  447. let windowController = window.windowController
  448. if windowController is KMBrowserWindowController {
  449. currentWindowController = (windowController as! KMBrowserWindowController)
  450. break
  451. }
  452. }
  453. }
  454. } else {
  455. for window in NSApp.windows {
  456. let windowController = window.windowController
  457. if windowController is KMBrowserWindowController {
  458. currentWindowController = (windowController as! KMBrowserWindowController)
  459. break
  460. }
  461. }
  462. }
  463. if let currentBroser = currentWindowController?.browser {
  464. if self.isEqual(to: currentBroser.activeTabContents()) {
  465. super.updateChangeCount(change)
  466. return
  467. }
  468. }
  469. super.updateChangeCount(.changeCleared)
  470. }
  471. func uploadToCloud(_ callback: (@escaping(Bool, String)->())) {
  472. guard let handdler = self.cloudUploadHanddler else {
  473. return
  474. }
  475. handdler(callback)
  476. }
  477. func isPDFDocument() -> Bool {
  478. return true
  479. }
  480. func setDataFromTmpData() {
  481. guard let _document = self.mainViewController?.document else {
  482. return
  483. }
  484. // self.tryToUnlockDocument(document!)
  485. if (_document.permissionsStatus != .owner) {
  486. var password: NSString? = nil
  487. let fileId = self.fileId(for: _document)
  488. if (fileId.isEmpty) {
  489. return
  490. }
  491. self.getPassword(&password, fileId: fileId)
  492. if (password != nil) {
  493. self.isUnlockFromKeychain = true
  494. // document.unlock(withPassword: password! as String)
  495. self.mainViewController?.password = password as String?
  496. }
  497. }
  498. }
  499. func tryToUnlockDocument(_ document: CPDFDocument) {
  500. if (document.permissionsStatus != .owner) {
  501. var password: NSString? = nil
  502. let fileId = self.fileId(for: document)
  503. if (fileId.isEmpty) {
  504. return
  505. }
  506. self.getPassword(&password, fileId: fileId)
  507. if (password != nil) {
  508. self.isUnlockFromKeychain = true
  509. document.unlock(withPassword: password! as String)
  510. }
  511. }
  512. }
  513. func km_updateChangeCount(_ change: NSDocument.ChangeType) {
  514. super.updateChangeCount(change)
  515. }
  516. func trackEvents() {
  517. km_synchronized(self) {
  518. for i in self._trackEvents {
  519. if let type = KMSubscribeWaterMarkType(rawValue: i) {
  520. KMTools.trackEvent(type: type)
  521. }
  522. }
  523. }
  524. self.clearTrackEvents()
  525. }
  526. func recordTrackEvent(type: KMSubscribeWaterMarkType) {
  527. if (type == .none) {
  528. return
  529. }
  530. km_synchronized(self) {
  531. self._trackEvents.insert(type.rawValue)
  532. }
  533. }
  534. func clearTrackEvents() {
  535. km_synchronized(self) {
  536. self._trackEvents.removeAll()
  537. }
  538. }
  539. @IBAction func saveArchive(_ sender: Any?) {
  540. guard let item = sender as? NSMenuItem else {
  541. NSSound.beep()
  542. return
  543. }
  544. guard let fileURL = self.fileURL else {
  545. NSSound.beep()
  546. return
  547. }
  548. let check = try?fileURL.checkResourceIsReachable()
  549. if check == false || self.isDocumentEdited {
  550. let msg = KMLocalizedString("You must save this file first", "Alert text when trying to create archive for unsaved document")
  551. let inf = KMLocalizedString("The document has unsaved changes, or has not previously been saved to disk.", "Informative text in alert dialog")
  552. Task {
  553. _ = await KMAlertTool.runModel(message: msg, informative: inf)
  554. }
  555. return
  556. }
  557. // NSString *ext = ([sender tag] | SKArchiveDiskImageMask) ? @"dmg" : @"tgz";
  558. let idx = item.tag
  559. let ext = "dmg"
  560. let isEmail = true
  561. if isEmail {
  562. // if (([sender tag] | SKArchiveEmailMask)) {
  563. let tmpDirURL = FileManager.default.uniqueChewableItemsDirectoryURL()
  564. let tmpFileURL = tmpDirURL.appendingPathComponent(fileURL.lastPathComponentReplacingPathExtension(ext))
  565. self.newSaveArchive(to: tmpFileURL, email: true)
  566. } else {
  567. let sp = NSSavePanel()
  568. sp.allowedFileTypes = [ext]
  569. sp.canCreateDirectories = true
  570. // [sp setNameFieldStringValue:[fileURL lastPathComponentReplacingPathExtension:ext]];
  571. sp.beginSheetModal(for: self.windowForSheet!) { result in
  572. if result == .OK {
  573. self.newSaveArchive(to: sp.url!, email: false)
  574. }
  575. }
  576. }
  577. }
  578. // func saveArchiveToURL(to fileURL: URL, email: Bool) {
  579. // NSTask *task = [[[NSTask alloc] init] autorelease];
  580. // let task = Task()
  581. // if fileURL.pathExtension == "dmg" {
  582. // [task setLaunchPath:@""];
  583. // task.launchPath = "/usr/bin/hdiutil"
  584. // [task setArguments:[NSArray arrayWithObjects:@"create", @"-srcfolder", [[self fileURL] path], @"-format", @"UDZO", @"-volname", [[fileURL lastPathComponent] stringByDeletingPathExtension], [fileURL path], nil]];
  585. // } else {
  586. // [task setLaunchPath:@"/usr/bin/tar"];
  587. // [task setArguments:[NSArray arrayWithObjects:@"-czf", [fileURL path], [[self fileURL] lastPathComponent], nil]];
  588. // }
  589. // [task setCurrentDirectoryPath:[[[self fileURL] URLByDeletingLastPathComponent] path]];
  590. // [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
  591. // [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
  592. //
  593. // SKAttachmentEmailer *emailer = nil;
  594. // if (email)
  595. // emailer = [SKAttachmentEmailer attachmentEmailerWithFileURL:fileURL subject:[self displayName] waitingForTask:task];
  596. //
  597. // @try {
  598. // [task launch];
  599. // }
  600. // @catch (id exception) {
  601. // [emailer taskFailed];
  602. // }
  603. // }
  604. @IBAction func readNotes(_ sender: Any?) {
  605. KMPrint("readNotes")
  606. }
  607. @IBAction func convertNotes(_ sender: Any?) {
  608. KMPrint("convertNotes")
  609. }
  610. @IBAction func batchRemovePassWord(_ sender: Any?) {
  611. self.mainViewController?.clickChildTool(type: .secure, index: 2)
  612. }
  613. @IBAction func batchRemovPrivatySecurity(_ sender: Any?) {
  614. self.mainViewController?.removeOwnerPassword()
  615. }
  616. @IBAction func printPDFDocument(_ sender: Any?) {
  617. KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.mainViewController?.document, inputPageRange: KMPrintPageRange())
  618. }
  619. @IBAction func performFindPanelAction(_ sender: Any?) {
  620. self.mainViewController?.toolbarController.showFindBar()
  621. }
  622. @IBAction func addBookmark(_ sender: Any?) {
  623. guard let item = sender as? NSMenuItem else {
  624. return
  625. }
  626. // let bookmarkSheetController = SKBookmarkSheetController(windowNibName: "BookmarkSheet")
  627. // NSWindow.currentWindow().beginSheet(bookmarkSheetController.window!) { resoponse in
  628. //
  629. // }
  630. // bookmarkSheetController.textField.stringValue = self.displayName
  631. // bookmarkSheetController.beginSheetModal(for: self.windowForSheet) { [unowned self] result in
  632. // if (result == NSApplication.ModalResponse.OK.rawValue) {
  633. // let label = bookmarkSheetController.textField.stringValue;
  634. // let folder: SKBookmark = bookmarkSheetController.selectedFolder ?? SKBookmarkController.shared().bookmarkRoot
  635. // var bookmark = SKBookmark()
  636. // switch (item.tag) {
  637. // case 0:
  638. // let mainViewController = self.mainViewController
  639. // let page = mainViewController?.listView.currentPage()
  640. // bookmark = SKBookmark.bookmark(with: self.fileURL, pageIndex: (page?.pageIndex())!, label: label) as! SKBookmark
  641. // case 1:
  642. // let setup = self.currentDocumntSetup()
  643. // bookmark = SKBookmark.bookmark(withSetup: setup, label: label) as! SKBookmark
  644. //
  645. // case 2:
  646. // let setups = NSApp.orderedDocuments.map { $0.value(forKey: "currentDocumentSetup") }
  647. // bookmark = SKBookmark.bookmarkSession(withSetups: setups as [Any], label: label) as! SKBookmark
  648. //
  649. // default:
  650. // break;
  651. // }
  652. // folder.mutableArrayValue(forKey: "children").add(bookmark)
  653. // }
  654. // }
  655. if item.tag == 3 {
  656. KMPrint("Edit Bookmark")
  657. bookmarkController = KMBookmarkController.showBookmarkController()
  658. } else if item.tag == 2 {
  659. KMPrint("session Bookmark")
  660. bookmarkSheetController = KMBookmarkSheetController.showBookmarkSheetController(type: .session)
  661. } else if item.tag == 0 {
  662. KMPrint("add Bookmark")
  663. bookmarkSheetController = KMBookmarkSheetController.showBookmarkSheetController(type: .bookmark)
  664. }
  665. bookmarkSheetController?.stringValue = self.displayName
  666. bookmarkSheetController?.cancelAction = { [unowned self] controller, type in
  667. }
  668. //
  669. bookmarkSheetController?.doneAction = { [unowned self] controller, type, label in
  670. let folder = controller.selectedFolder
  671. var bookmark: KMBookmark?
  672. switch type {
  673. case .bookmark:
  674. let mainViewController = mainViewController
  675. if let page = mainViewController?.listView.currentPage() {
  676. let index: UInt = page.pageIndex()
  677. bookmark = KMBookmark.bookmark(url: self.fileURL!, pageIndex: index, label: label)
  678. }
  679. case .setup: break
  680. let setup = currentDocumentSetup
  681. bookmark = KMBookmark.bookmark(setup: setup, label: label)
  682. case .session:
  683. let setups = NSApp.orderedDocuments.compactMap { $0.value(forKey:"currentDocumentSetup") }
  684. bookmark = KMSessionBookmark.bookmarkSession(setups: setups as NSArray, label: label)
  685. default:
  686. break
  687. }
  688. if let bookmark = bookmark {
  689. folder?.children.append(bookmark)
  690. }
  691. KMBookmarkManager.manager.saveData()
  692. }
  693. }
  694. func currentDocumntSetup() -> [String: Any] {
  695. var setup: [String: Any] = [:]
  696. let data = SKAlias.init(url: fileURL).data
  697. if (data != nil) {
  698. setup.updateValue(data as Any, forKey: "_BDAlias")
  699. } else {
  700. setup.updateValue(fileURL?.path as Any, forKey: "fileName")
  701. }
  702. return setup;
  703. }
  704. @IBAction func showWindow(_ sender: Any?) {
  705. KMPrint("showWindow")
  706. }
  707. // MARK: - Private Methods
  708. private func _km_write(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws {
  709. var success = true
  710. if !self.isHome {
  711. if mainViewController != nil {
  712. if mainViewController?.document != nil {
  713. self.mainViewController?.commitEditingIfNeed()
  714. // if mainViewController!.document!.isEncrypted {
  715. // success = mainViewController!.document!.write(to: url)
  716. // } else {
  717. if (mainViewController!.needSave) {
  718. if let options = self.mainViewController?.secureOptions, !options.isEmpty {
  719. self.mainViewController!.document?.setDocumentAttributes(self.mainViewController?.documentAttribute)
  720. success = self.mainViewController!.document!.write(to: url, withOptions: options)
  721. } else if let flag = self.mainViewController?.removeSecureFlag, flag {
  722. success = self.mainViewController!.document!.writeDecrypt(to: url)
  723. } else {
  724. success = mainViewController!.document!.write(to: url)
  725. }
  726. } else {
  727. success = mainViewController!.document!.write(to: url)
  728. }
  729. // }
  730. self.mainViewController?.needSave = false
  731. self.mainViewController?.clearSecureOptions()
  732. self.mainViewController?.clearRemoveSecureFlag()
  733. }
  734. }
  735. } else {
  736. success = false
  737. }
  738. if (success && self._saveAsing) {
  739. if let tabView = self.browser?.windowController?.tabStripController?.activeTabView() as? CTTabView {
  740. tabView.controller()?.title = url.lastPathComponent
  741. }
  742. self._saveAsing = false
  743. }
  744. if success && isNewCreated && NSDocument.SaveOperationType.saveAsOperation == saveOperation {
  745. isNewCreated = false
  746. }
  747. }
  748. private func _km_saveForWatermark(openAccessoryView: Bool = true, subscribeDidClick: (()->Void)? = nil, callback:@escaping (_ needSave: Bool, _ param: Any...)->Void) {
  749. Task { @MainActor in
  750. if await (KMLightMemberManager.manager.canPayFunction() == false) {
  751. let _ = KMSubscribeWaterMarkWindowController.show(window: NSApp.mainWindow!, isContinue:false, type: .save) {
  752. if let _callback = subscribeDidClick {
  753. _callback()
  754. }
  755. } completion: { isSubscribeSuccess, isWaterMarkExport, isClose in
  756. if (isClose) {
  757. callback(false, KMResult.cancel, false)
  758. return
  759. }
  760. if (isSubscribeSuccess) {
  761. callback(true)
  762. return
  763. }
  764. if (isWaterMarkExport) {
  765. guard let _document = self.mainViewController?.document else {
  766. callback(false, KMResult.failure)
  767. return
  768. }
  769. // 提交文本编辑的内容
  770. self.mainViewController?.commitEditingIfNeed()
  771. DispatchQueue.main.async {
  772. NSPanel.savePanel(NSApp.mainWindow!, openAccessoryView, panel:{ panel in
  773. if (!self.isNewCreated) {
  774. panel.directoryURL = _document.documentURL.deletingLastPathComponent()
  775. }
  776. panel.nameFieldStringValue = _document.documentURL.lastPathComponent
  777. }) { response, url, isOpen in
  778. if (response == .cancel) {
  779. callback(false, KMResult.cancel, true)
  780. return
  781. }
  782. guard let _url = KMTools.saveWatermarkDocument(document: _document, to: url!, secureOptions: self.mainViewController?.secureOptions, documentAttribute: self.mainViewController?.documentAttribute,removePWD: self.mainViewController!.removeSecureFlag) else {
  783. callback(false, KMResult.failure)
  784. return
  785. }
  786. callback(false, KMResult.success)
  787. if (isOpen) {
  788. NSDocumentController.shared.km_safe_openDocument(withContentsOf: _url, display: true) { _, _, _ in
  789. }
  790. } else {
  791. NSWorkspace.shared.activateFileViewerSelecting([_url])
  792. }
  793. }
  794. }
  795. return
  796. }
  797. callback(false, KMResult.cancel, false)
  798. }
  799. return
  800. }
  801. callback(true)
  802. }
  803. }
  804. private func _km_save(_ sender: Any?) {
  805. super.save(sender)
  806. }
  807. private func _km_save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
  808. self._saveToURL = url
  809. super.save(to: url, ofType: typeName, for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  810. }
  811. private func _km_saveAs(_ sender: Any?) {
  812. super.saveAs(sender)
  813. self._saveAsing = true
  814. }
  815. private func _km_runModalSavePanel(for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
  816. super.runModalSavePanel(for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
  817. }
  818. }
  819. extension KMMainDocument {
  820. override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  821. if (menuItem.action == #selector(save(_ :))) {
  822. if (self.isHome) {
  823. return false
  824. }
  825. if (self.isDocumentEdited) {
  826. return self.isDocumentEdited
  827. }
  828. guard let mainVC = self.mainViewController else {
  829. return false
  830. }
  831. return mainVC.isPDFDocumentEdited || mainVC.needSave
  832. } else if (menuItem.action == #selector(saveAs(_ :))) {
  833. return !self.isHome
  834. } else if menuItem.action == #selector(batchRemovPrivatySecurity) {
  835. if self.isHome {
  836. return false
  837. }
  838. guard let doc = self.mainViewController?.listView?.document else {
  839. return false
  840. }
  841. let allowsPrinting = doc.allowsPrinting
  842. let allowsCopying = doc.allowsCopying
  843. if allowsCopying && allowsPrinting {
  844. return false
  845. }
  846. return true
  847. } else if menuItem.action == #selector(saveArchive) {
  848. return !self.isHome
  849. }
  850. return super.validateMenuItem(menuItem)
  851. }
  852. }
  853. extension NSDocument {
  854. @objc class func isDamage(url: URL) -> Bool {
  855. // 文件路径是否存在
  856. if (FileManager.default.fileExists(atPath: url.path) == false) {
  857. return true
  858. }
  859. /// PDF 格式文件
  860. if (url.pathExtension.lowercased() == "pdf") {
  861. let document = PDFDocument(url: url)
  862. if (document == nil) {
  863. return true
  864. }
  865. if (document!.isLocked) { // 加锁文件不在这里判断
  866. return false
  867. }
  868. if (document!.pageCount <= 0) {
  869. return true
  870. }
  871. return false
  872. }
  873. // 支持的图片格式
  874. let imageExts = ["jpg","cur","bmp","jpeg","gif","png","tiff","tif","ico","icns","tga","psd","eps","hdr","jp2","jpc","pict","sgi","heic"]
  875. let isImage = imageExts.contains(url.pathExtension.lowercased())
  876. if (isImage == false) { // 其他格式目前返回没损坏,后续再补充(如果有需求)
  877. return false
  878. }
  879. // 图片格式
  880. let image = NSImage(contentsOf: url)
  881. let data = image?.tiffRepresentation
  882. if (data == nil) {
  883. return true
  884. }
  885. let imageRep = NSBitmapImageRep(data: data!)
  886. imageRep!.size = image!.size
  887. var imageData: NSData?
  888. if (url.pathExtension.lowercased() == "png") {
  889. imageData = imageRep?.representation(using: .png, properties: [:]) as NSData?
  890. } else {
  891. imageData = imageRep?.representation(using: .jpeg, properties: [:]) as NSData?
  892. }
  893. if (imageData == nil) {
  894. return true
  895. }
  896. let path = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!)
  897. if (FileManager.default.fileExists(atPath: path!) == false) {
  898. try?FileManager.default.createDirectory(atPath: path!, withIntermediateDirectories: false)
  899. }
  900. var tagString: String = ""
  901. let dateFormatter = DateFormatter()
  902. dateFormatter.dateFormat = "yyMMddHHmmss"
  903. tagString.append(dateFormatter.string(from: Date()))
  904. tagString = tagString.appendingFormat("%04d", arc4random()%10000)
  905. let filePath = path?.appending("/\(tagString).png")
  906. if (imageData!.write(toFile: filePath!, atomically: true) == false) {
  907. return true
  908. }
  909. // 删除临时图片
  910. try?FileManager.default.removeItem(atPath: filePath!)
  911. return false
  912. }
  913. @objc class func isDamage(url: URL, needAlertIfDamage need: Bool) -> Bool {
  914. let result = self.isDamage(url: url)
  915. if (result == false) {
  916. return false
  917. }
  918. if (need == false) {
  919. return true
  920. }
  921. let alert = NSAlert()
  922. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  923. alert.runModal()
  924. return true
  925. }
  926. }
  927. // MARK: -
  928. // MARK: 保存密码
  929. extension NSDocument {
  930. func savePasswordInKeychain(_ password: String, _ document: CPDFDocument) {
  931. if (document.isLocked || password.isEmpty) {
  932. return
  933. }
  934. let fileId = self.fileId(for: document)
  935. if (fileId.isEmpty) {
  936. return
  937. }
  938. // let status: SKPasswordStatus =
  939. let label = "PDF Reader Pro: \(self.displayName!)"
  940. SKKeychain.setPassword(password, item: nil, forService: self.passwordServiceName(), account: fileId, label: label, comment: self.fileURL?.path)
  941. }
  942. func getPassword(_ password: AutoreleasingUnsafeMutablePointer<NSString?>, fileId: String) {
  943. let status = SKKeychain.getPassword(password, item: nil, forService: self.passwordServiceName(), account: fileId)
  944. // if (status == .found) {
  945. // }
  946. }
  947. fileprivate func fileId(for document: CPDFDocument) -> String {
  948. return "\(document.documentURL.path.hash)"
  949. }
  950. private func passwordServiceName() -> String {
  951. return "PDF Reader Pro password"
  952. }
  953. }
  954. extension KMMainDocument: SKPDFSynchronizerDelegate {
  955. func synchronizer(_ synchronizer: SKPDFSynchronizer!, foundLine line: Int, inFile file: String!) {
  956. if FileManager.default.fileExists(atPath: file) {
  957. let defaults = UserDefaults.standard
  958. var editorPreset = defaults.string(forKey: SKTeXEditorPresetKey) ?? ""
  959. var editorCmd: String?
  960. var editorArgs: String?
  961. var cmdString: String?
  962. if !KMSyncPreferences.getTeXEditorCommand(command: &editorCmd, arguments: &editorArgs, forPreset: editorPreset) {
  963. editorCmd = defaults.string(forKey: SKTeXEditorCommandKey)
  964. editorArgs = defaults.string(forKey: SKTeXEditorArgumentsKey)
  965. }
  966. if var cmdString = editorArgs {
  967. if !editorCmd!.hasPrefix("/") {
  968. var searchPaths = ["/usr/bin", "/usr/local/bin"]
  969. var toolPath: String?
  970. let fm = FileManager.default
  971. if !(editorPreset.isEmpty) {
  972. if let path = NSWorkspace.shared.fullPath(forApplication: editorPreset) {
  973. if let appBundle = Bundle(path: path) {
  974. if let contentsPath = appBundle.path(forResource: "Contents", ofType: nil) {
  975. searchPaths.insert(contentsPath, at: 0)
  976. }
  977. if editorPreset != "BBEdit", let execPath = appBundle.executablePath {
  978. searchPaths.insert(execPath, at: 0)
  979. }
  980. if let resourcePath = appBundle.resourcePath {
  981. searchPaths.insert(resourcePath, at: 0)
  982. }
  983. if let sharedSupportPath = appBundle.sharedSupportPath {
  984. searchPaths.insert(sharedSupportPath, at: 0)
  985. }
  986. }
  987. }
  988. } else {
  989. let appSupportDirs = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
  990. let appSupportPaths = appSupportDirs.map { $0.path }
  991. searchPaths.append(contentsOf: appSupportPaths)
  992. }
  993. for path in searchPaths {
  994. toolPath = (path as NSString).appendingPathComponent(editorCmd!)
  995. if fm.isExecutableFile(atPath: toolPath!) {
  996. editorCmd = toolPath
  997. break
  998. }
  999. toolPath = ((path as NSString).appendingPathComponent("bin") as NSString).appendingPathComponent(editorCmd!)
  1000. if fm.isExecutableFile(atPath: toolPath!) {
  1001. editorCmd = toolPath
  1002. break
  1003. }
  1004. }
  1005. }
  1006. cmdString = cmdString.replacingOccurrences(of: "%line", with: "\(line + 1)")
  1007. cmdString = cmdString.replacingOccurrences(of: "%file", with: file)
  1008. cmdString = cmdString.replacingOccurrences(of: "%output", with: fileURL?.path ?? "")
  1009. cmdString.insert(contentsOf: "\" ", at: cmdString.startIndex)
  1010. cmdString.insert(contentsOf: editorCmd!, at: cmdString.startIndex)
  1011. cmdString.insert("\"", at: cmdString.startIndex)
  1012. let ws = NSWorkspace.shared
  1013. if let theUTI = try? ws.type(ofFile: editorCmd!) {
  1014. if ws.type(theUTI, conformsToType: "com.apple.applescript.script") || ws.type(theUTI, conformsToType: "com.apple.applescript.text") {
  1015. cmdString.insert(contentsOf: "/usr/bin/osascript ", at: cmdString.startIndex)
  1016. }
  1017. }
  1018. let task = Process()
  1019. task.launchPath = "/bin/sh"
  1020. task.currentDirectoryPath = (file as NSString).deletingLastPathComponent
  1021. task.arguments = ["-c", cmdString]
  1022. task.standardOutput = FileHandle.nullDevice
  1023. task.standardError = FileHandle.nullDevice
  1024. do {
  1025. try task.run()
  1026. } catch let error {
  1027. Swift.print("command failed: \(cmdString ?? ""): \(error)")
  1028. }
  1029. }
  1030. }
  1031. }
  1032. func synchronizer(_ synchronizer: SKPDFSynchronizer!, foundLocation point: NSPoint, atPageIndex pageIndex: UInt, options: Int) {
  1033. guard let pdfDoc = self.mainViewController?.document else { return }
  1034. if pageIndex < pdfDoc.pageCount {
  1035. if let page = pdfDoc.page(at: pageIndex) {
  1036. var adjustedPoint = point
  1037. if options & SKPDFSynchronizerFlippedMask != 0 {
  1038. let mediaBox = page.bounds(for: .mediaBox)
  1039. adjustedPoint.y = NSMaxY(mediaBox) - adjustedPoint.y
  1040. }
  1041. self.mainViewController?.listView.displayLine(at: adjustedPoint, inPageAtIndex: Int(pageIndex), showReadingBar: options & SKPDFSynchronizerShowReadingBarMask != 0)
  1042. }
  1043. }
  1044. }
  1045. }
  1046. extension KMMainDocument {
  1047. }