KMMainDocument.swift 50 KB

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