KMHeaderFooterAdjectiveModel.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // KMHeaderFooterAdjectiveModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/27.
  6. //
  7. import Cocoa
  8. enum KMHeaderFooterObjectType: Int {
  9. case headerFooter = 0
  10. case bates
  11. }
  12. @objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding {
  13. var type: KMHeaderFooterObjectType = .headerFooter
  14. // 是否数据迁移(原App数据迁移)
  15. var isMigrate = false
  16. // 是否已被更新
  17. var isUpdated = false
  18. var leftMargin: Int = 30
  19. var rightMargin: Int = 30
  20. var bottomMargin: Int = 30
  21. var topMargin: Int = 30
  22. var topLeftString: String = ""
  23. var topCenterString: String = ""
  24. var topRightString: String = ""
  25. var bottomLeftString: String = ""
  26. var bottomCenterString: String = ""
  27. var bottomRightString: String = ""
  28. var startString: String = "1"
  29. var name: String = ""
  30. var cellHeight: CGFloat {
  31. get {
  32. var height: CGFloat = 45.0
  33. if (self.topLeftString.count > 0) {
  34. height += 20.0
  35. }
  36. if (self.topCenterString.count > 0) {
  37. height += 20.0
  38. }
  39. if (self.topRightString.count > 0) {
  40. height += 20.0
  41. }
  42. if (self.bottomLeftString.count > 0) {
  43. height += 20.0
  44. }
  45. if (self.bottomCenterString.count > 0) {
  46. height += 20.0
  47. }
  48. if (self.bottomRightString.count > 0) {
  49. height += 20.0
  50. }
  51. return height
  52. }
  53. }
  54. var hasVaild: Bool {
  55. get {
  56. for string in [self.topLeftString, self.topCenterString, self.topRightString,
  57. self.bottomLeftString, self.bottomCenterString, self.bottomRightString] {
  58. if (!string.isEmpty) {
  59. return true
  60. }
  61. }
  62. return false
  63. }
  64. }
  65. override init() {
  66. super.init()
  67. self.textFont = .font(name: "Helvetica", size: 10)
  68. self.textColor = .color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
  69. }
  70. required init?(coder: NSCoder) {
  71. super.init()
  72. type = KMHeaderFooterObjectType.init(rawValue: coder.decodeInteger(forKey: "type"))!
  73. pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "pageChoice"))!
  74. leftMargin = coder.decodeInteger(forKey: "leftMargin")
  75. rightMargin = coder.decodeInteger(forKey: "rightMargin")
  76. bottomMargin = coder.decodeInteger(forKey: "bottomMargin")
  77. topMargin = coder.decodeInteger(forKey: "topMargin")
  78. topLeftString = coder.decodeObject(forKey: "topLeftString") as? String ?? ""
  79. topCenterString = coder.decodeObject(forKey: "topCenterString") as? String ?? ""
  80. topRightString = coder.decodeObject(forKey: "topRightString") as? String ?? ""
  81. bottomLeftString = coder.decodeObject(forKey: "bottomLeftString") as? String ?? ""
  82. bottomCenterString = coder.decodeObject(forKey: "bottomCenterString") as? String ?? ""
  83. bottomRightString = coder.decodeObject(forKey: "bottomRightString") as? String ?? ""
  84. startString = coder.decodeObject(forKey: "startString") as? String ?? ""
  85. fontSize = coder.decodeFloat(forKey: "fontSize")
  86. tempTextColor = coder.decodeObject(forKey: "textColor") as? NSColor ?? NSColor.black
  87. id = coder.decodeObject(forKey: "headerFooterID") as? String ?? ""
  88. pageRangeString = coder.decodeObject(forKey: "pagesString") as? String ?? ""
  89. }
  90. func encode(with coder: NSCoder) {
  91. coder.encode(type.rawValue, forKey: "type")
  92. coder.encode(pageRangeType.rawValue, forKey: "pageChoice")
  93. coder.encode(leftMargin, forKey: "leftMargin")
  94. coder.encode(rightMargin, forKey: "rightMargin")
  95. coder.encode(bottomMargin, forKey: "bottomMargin")
  96. coder.encode(topMargin, forKey: "topMargin")
  97. coder.encode(topLeftString, forKey: "topLeftString")
  98. coder.encode(topCenterString, forKey: "topCenterString")
  99. coder.encode(topRightString, forKey: "topRightString")
  100. coder.encode(bottomLeftString, forKey: "bottomLeftString")
  101. coder.encode(bottomCenterString, forKey: "bottomCenterString")
  102. coder.encode(bottomRightString, forKey: "bottomRightString")
  103. coder.encode(startString, forKey: "startString")
  104. coder.encode(fontSize, forKey: "fontSize")
  105. coder.encode(self.getTextColor(), forKey: "textColor")
  106. coder.encode(id, forKey: "headerFooterID")
  107. coder.encode(pageRangeString, forKey: "pagesString")
  108. }
  109. }