KMPDFAnnotationRedactConfig.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // KMPDFAnnotationRedactConfig.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/12/18.
  6. //
  7. import Cocoa
  8. class KMPDFAnnotationRedactConfig: NSObject {
  9. private let KMPDFAnnotationRedactOutlineColor = "KMPDFAnnotationRedactOutlineColor"
  10. private let KMPDFAnnotationRedactFillColor = "KMPDFAnnotationRedactFillColor"
  11. private let KMPDFAnnotationRedactFontColor = "KMPDFAnnotationRedactFontColor"
  12. private let KMPDFAnnotationRedactUseOverlayText = "KMPDFAnnotationRedactUseOverlayText"
  13. private let KMPDFAnnotationRedactOverlayTextString = "KMPDFAnnotationRedactOverlayTextString"
  14. private let KMPDFAnnotationRedactRepeatText = "KMPDFAnnotationRedactRepeatText"
  15. private let KMPDFAnnotationRedactAutoSizeText = "KMPDFAnnotationRedactAutoSizeText"
  16. private let KMPDFAnnotationRedactFontSize = "KMPDFAnnotationRedactFontSize"
  17. private let KMPDFAnnotationRedactTextAlignment = "KMPDFAnnotationRedactTextAlignment"
  18. static let shared = KMPDFAnnotationRedactConfig()
  19. var redactOutlineColor: NSColor? {
  20. get {
  21. let outlineColor = UserDefaults.standard.color(forKey: KMPDFAnnotationRedactOutlineColor)
  22. if outlineColor == nil {
  23. return NSColor.red
  24. }
  25. return outlineColor
  26. }
  27. set {
  28. if let data = newValue {
  29. UserDefaults.standard.setColor(data, forKey: KMPDFAnnotationRedactOutlineColor)
  30. UserDefaults.standard.synchronize()
  31. }
  32. }
  33. }
  34. var redactFillColor: NSColor? {
  35. get {
  36. let outlineColor = UserDefaults.standard.color(forKey: KMPDFAnnotationRedactFillColor)
  37. if outlineColor == nil {
  38. return NSColor.black
  39. }
  40. return outlineColor
  41. }
  42. set {
  43. if let data = newValue {
  44. UserDefaults.standard.setColor(data, forKey: KMPDFAnnotationRedactFillColor)
  45. UserDefaults.standard.synchronize()
  46. }
  47. }
  48. }
  49. var redactFontColor: NSColor? {
  50. get {
  51. let fontColor = UserDefaults.standard.color(forKey: KMPDFAnnotationRedactFontColor)
  52. if fontColor == nil {
  53. return NSColor.red
  54. }
  55. return fontColor
  56. }
  57. set {
  58. if let data = newValue {
  59. UserDefaults.standard.setColor(data, forKey: KMPDFAnnotationRedactFontColor)
  60. UserDefaults.standard.synchronize()
  61. }
  62. }
  63. }
  64. var overlayText: Bool {
  65. get {
  66. return UserDefaults.standard.bool(forKey: KMPDFAnnotationRedactUseOverlayText)
  67. }
  68. set {
  69. KMDataManager.ud_set(newValue, forKey: KMPDFAnnotationRedactUseOverlayText)
  70. }
  71. }
  72. var overlayTextString: String {
  73. get {
  74. return UserDefaults.standard.string(forKey: KMPDFAnnotationRedactOverlayTextString) ?? ""
  75. }
  76. set {
  77. UserDefaults.standard.set(newValue, forKey: KMPDFAnnotationRedactOverlayTextString)
  78. UserDefaults.standard.synchronize()
  79. }
  80. }
  81. var repeatText: Bool {
  82. get {
  83. return UserDefaults.standard.bool(forKey: KMPDFAnnotationRedactRepeatText)
  84. }
  85. set {
  86. KMDataManager.ud_set(newValue, forKey: KMPDFAnnotationRedactRepeatText)
  87. }
  88. }
  89. var autoSizeText: Bool {
  90. get {
  91. return UserDefaults.standard.bool(forKey: KMPDFAnnotationRedactAutoSizeText)
  92. }
  93. set {
  94. KMDataManager.ud_set(newValue, forKey: KMPDFAnnotationRedactAutoSizeText)
  95. }
  96. }
  97. var fontSize: Int {
  98. get {
  99. let fontSize = UserDefaults.standard.integer(forKey: KMPDFAnnotationRedactFontSize)
  100. if fontSize == 0 {
  101. return 12
  102. }
  103. return fontSize
  104. }
  105. set {
  106. KMDataManager.ud_set(newValue, forKey: KMPDFAnnotationRedactFontSize)
  107. }
  108. }
  109. var textAlignment: Int {
  110. get {
  111. return UserDefaults.standard.integer(forKey: KMPDFAnnotationRedactTextAlignment)
  112. }
  113. set {
  114. KMDataManager.ud_set(newValue, forKey: KMPDFAnnotationRedactTextAlignment)
  115. }
  116. }
  117. }