KMThumbnail.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // KMThumbnail.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/11/16.
  6. //
  7. import Cocoa
  8. let thumbnailMethodKey = "KMThumbnailMethodKey"
  9. let outlineMethodKey = "KMOutlineMethoddKey"
  10. let bookMarkMethodKey = "KMBookMarkMethodKey"
  11. let anntationMethodKey = "KMAnntationMethodKey"
  12. let searchMethodKey = "KMSearchMethodKey"
  13. let formMethodKey = "KMFormMethodKey"
  14. let signatureMethodKey = "KMSignatureMethodKey"
  15. let snapshotMethodKey = "KMSnapshotMethodKey"
  16. @objc protocol KMThumbnailDelegate: NSObjectProtocol {
  17. @objc optional func generateImage(for thumbnail: KMThumbnail) -> Bool
  18. }
  19. class KMThumbnail: NSObject {
  20. weak var delegate: KMThumbnailDelegate?
  21. var dirty = false
  22. private var _image: NSImage?
  23. var image: NSImage? {
  24. get {
  25. if let data = self.delegate?.generateImage?(for: self), data && self.dirty {
  26. self.dirty = false
  27. }
  28. return self._image
  29. }
  30. set {
  31. self._image = newValue
  32. }
  33. }
  34. private var _label: String = ""
  35. var label: String {
  36. get {
  37. return self._label
  38. }
  39. }
  40. private var _pageIndex: Int = 0
  41. var pageIndex: Int {
  42. get {
  43. return self._pageIndex
  44. }
  45. }
  46. var size: NSSize {
  47. get {
  48. return self.image?.size ?? .zero
  49. }
  50. }
  51. var thumiii: NSImageView?
  52. convenience init(image: NSImage?, label: String, pageIndex: Int) {
  53. self.init()
  54. self.image = image
  55. self._label = label
  56. self._pageIndex = pageIndex
  57. self.dirty = false
  58. }
  59. }