KMHeaderFooterAdjectiveModel.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // KMHeaderFooterAdjectiveModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/27.
  6. //
  7. import Cocoa
  8. @objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding {
  9. var leftMargin: Int = 30
  10. var rightMargin: Int = 30
  11. var bottomMargin: Int = 30
  12. var topMargin: Int = 30
  13. var topLeftString: String = ""
  14. var topCenterString: String = ""
  15. var topRightString: String = ""
  16. var bottomLeftString: String = ""
  17. var bottomCenterString: String = ""
  18. var bottomRightString: String = ""
  19. var startString: String = "1"
  20. var name: String = ""
  21. var cellHeight: CGFloat {
  22. get {
  23. var height: CGFloat = 45.0
  24. if (self.topLeftString.count > 0) {
  25. height += 20.0
  26. }
  27. if (self.topCenterString.count > 0) {
  28. height += 20.0
  29. }
  30. if (self.topRightString.count > 0) {
  31. height += 20.0
  32. }
  33. if (self.bottomLeftString.count > 0) {
  34. height += 20.0
  35. }
  36. if (self.bottomCenterString.count > 0) {
  37. height += 20.0
  38. }
  39. if (self.bottomRightString.count > 0) {
  40. height += 20.0
  41. }
  42. return height
  43. }
  44. }
  45. var hasVaild: Bool {
  46. get {
  47. for string in [self.topLeftString, self.topCenterString, self.topRightString,
  48. self.bottomLeftString, self.bottomCenterString, self.bottomRightString] {
  49. if (!string.isEmpty) {
  50. return true
  51. }
  52. }
  53. return false
  54. }
  55. }
  56. override init() {
  57. super.init()
  58. self.textFont = .font(name: "Helvetica", size: 10)
  59. self.textColor = .color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
  60. }
  61. required init?(coder: NSCoder) {
  62. super.init()
  63. pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "type"))!
  64. leftMargin = coder.decodeInteger(forKey: "leftMargin")
  65. rightMargin = coder.decodeInteger(forKey: "rightMargin")
  66. bottomMargin = coder.decodeInteger(forKey: "bottomMargin")
  67. topMargin = coder.decodeInteger(forKey: "topMargin")
  68. topLeftString = coder.decodeObject(forKey: "topLeftString") as? String ?? ""
  69. topCenterString = coder.decodeObject(forKey: "topCenterString") as? String ?? ""
  70. topRightString = coder.decodeObject(forKey: "topRightString") as? String ?? ""
  71. bottomLeftString = coder.decodeObject(forKey: "bottomLeftString") as? String ?? ""
  72. bottomCenterString = coder.decodeObject(forKey: "bottomCenterString") as? String ?? ""
  73. bottomRightString = coder.decodeObject(forKey: "bottomRightString") as? String ?? ""
  74. startString = coder.decodeObject(forKey: "startString") as? String ?? ""
  75. fontSize = coder.decodeFloat(forKey: "fontSize")
  76. tempTextColor = coder.decodeObject(forKey: "textColor") as? NSColor ?? NSColor.black
  77. id = coder.decodeObject(forKey: "headerFooterID") as? String ?? ""
  78. pageCount = coder.decodeInteger(forKey: "pageChoice")
  79. pageRangeString = coder.decodeObject(forKey: "pagesString") as? String ?? ""
  80. // hasHeader = coder.decodeBool(forKey: "hasHeader")
  81. // hasFooter = coder.decodeBool(forKey: "hasFooter")
  82. // cellHeight = coder.decodeFloat(forKey: "cellHeight")
  83. // dateFormatString = coder.decodeObject(forKey: "dateFormatString") as? String ?? "m/d"
  84. // pageFormatString = coder.decodeObject(forKey: "pageFormatString") as? String ?? "1"
  85. // isBates = coder.decodeBool(forKey: "isBates")
  86. // batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as? String ?? ""
  87. // batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as? String ?? ""
  88. // batesDigits = coder.decodeInteger(forKey: "batesDigits")
  89. }
  90. func encode(with coder: NSCoder) {
  91. coder.encode(pageRangeType.rawValue, forKey: "type")
  92. coder.encode(leftMargin, forKey: "leftMargin")
  93. coder.encode(rightMargin, forKey: "rightMargin")
  94. coder.encode(bottomMargin, forKey: "bottomMargin")
  95. coder.encode(topMargin, forKey: "topMargin")
  96. coder.encode(topLeftString, forKey: "topLeftString")
  97. coder.encode(topCenterString, forKey: "topCenterString")
  98. coder.encode(topRightString, forKey: "topRightString")
  99. coder.encode(bottomLeftString, forKey: "bottomLeftString")
  100. coder.encode(bottomCenterString, forKey: "bottomCenterString")
  101. coder.encode(bottomRightString, forKey: "bottomRightString")
  102. coder.encode(startString, forKey: "startString")
  103. coder.encode(fontSize, forKey: "fontSize")
  104. coder.encode(tempTextColor, forKey: "textColor")
  105. // coder.encode(hasHeader, forKey: "hasHeader")
  106. // coder.encode(hasFooter, forKey: "hasFooter")
  107. // coder.encode(cellHeight, forKey: "cellHeight")
  108. coder.encode(id, forKey: "headerFooterID")
  109. coder.encode(pageCount, forKey: "pageChoice")
  110. coder.encode(pageRangeString, forKey: "pagesString")
  111. // coder.encode(dateFormatString, forKey: "dateFormatString")
  112. // coder.encode(pageFormatString, forKey: "pageFormatString")
  113. // coder.encode(isBates, forKey: "isBates")
  114. // coder.encode(batesPrefixString, forKey: "batesPrefixString")
  115. // coder.encode(batesSuffixString, forKey: "batesSuffixString")
  116. // coder.encode(batesDigits, forKey: "batesDigits")
  117. }
  118. // func copy(with zone: NSZone? = nil) -> Any {
  119. // let obj = KMHeaderFooterObject()
  120. // obj.pageRangeType = pageRangeType
  121. // obj.leftMargin = leftMargin
  122. // obj.rightMargin = rightMargin
  123. // obj.bottomMargin = bottomMargin
  124. // obj.topMargin = topMargin
  125. // obj.topLeftString = topLeftString
  126. // obj.topCenterString = topCenterString
  127. // obj.topRightString = topRightString
  128. // obj.bottomLeftString = bottomLeftString
  129. // obj.bottomCenterString = bottomCenterString
  130. // obj.bottomRightString = bottomRightString
  131. // obj.startString = startString
  132. // obj.fontSize = fontSize
  133. // obj.textColor = textColor
  134. //// obj.hasHeader = hasHeader
  135. //// obj.hasFooter = hasFooter
  136. //// obj.cellHeight = cellHeight
  137. // obj.id = id
  138. // obj.pageCount = pageCount
  139. // obj.pageRangeString = pageRangeString
  140. //
  141. // obj.dateFormatString = dateFormatString
  142. // obj.pageFormatString = pageFormatString
  143. // obj.isBates = isBates
  144. // obj.batesPrefixString = batesPrefixString
  145. // obj.batesSuffixString = batesSuffixString
  146. // obj.batesDigits = batesDigits
  147. // return obj
  148. // }
  149. }