KMHeaderFooterAdjectiveModel.swift 6.9 KB

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