KMHeaderFooterAdjectiveModel.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // KMHeaderFooterAdjectiveModel.swift
  3. // Cisdem PDFMaster
  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. // hasHeader = coder.decodeBool(forKey: "hasHeader")
  90. // hasFooter = coder.decodeBool(forKey: "hasFooter")
  91. // cellHeight = coder.decodeFloat(forKey: "cellHeight")
  92. // dateFormatString = coder.decodeObject(forKey: "dateFormatString") as? String ?? "m/d"
  93. // pageFormatString = coder.decodeObject(forKey: "pageFormatString") as? String ?? "1"
  94. // isBates = coder.decodeBool(forKey: "isBates")
  95. // batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as? String ?? ""
  96. // batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as? String ?? ""
  97. // batesDigits = coder.decodeInteger(forKey: "batesDigits")
  98. }
  99. func encode(with coder: NSCoder) {
  100. coder.encode(type.rawValue, forKey: "type")
  101. coder.encode(pageRangeType.rawValue, forKey: "pageChoice")
  102. coder.encode(leftMargin, forKey: "leftMargin")
  103. coder.encode(rightMargin, forKey: "rightMargin")
  104. coder.encode(bottomMargin, forKey: "bottomMargin")
  105. coder.encode(topMargin, forKey: "topMargin")
  106. coder.encode(topLeftString, forKey: "topLeftString")
  107. coder.encode(topCenterString, forKey: "topCenterString")
  108. coder.encode(topRightString, forKey: "topRightString")
  109. coder.encode(bottomLeftString, forKey: "bottomLeftString")
  110. coder.encode(bottomCenterString, forKey: "bottomCenterString")
  111. coder.encode(bottomRightString, forKey: "bottomRightString")
  112. coder.encode(startString, forKey: "startString")
  113. coder.encode(fontSize, forKey: "fontSize")
  114. coder.encode(self.getTextColor(), forKey: "textColor")
  115. // coder.encode(hasHeader, forKey: "hasHeader")
  116. // coder.encode(hasFooter, forKey: "hasFooter")
  117. // coder.encode(cellHeight, forKey: "cellHeight")
  118. coder.encode(id, forKey: "headerFooterID")
  119. coder.encode(pageRangeString, forKey: "pagesString")
  120. // coder.encode(dateFormatString, forKey: "dateFormatString")
  121. // coder.encode(pageFormatString, forKey: "pageFormatString")
  122. // coder.encode(isBates, forKey: "isBates")
  123. // coder.encode(batesPrefixString, forKey: "batesPrefixString")
  124. // coder.encode(batesSuffixString, forKey: "batesSuffixString")
  125. // coder.encode(batesDigits, forKey: "batesDigits")
  126. }
  127. // func copy(with zone: NSZone? = nil) -> Any {
  128. // let obj = KMHeaderFooterObject()
  129. // obj.pageRangeType = pageRangeType
  130. // obj.leftMargin = leftMargin
  131. // obj.rightMargin = rightMargin
  132. // obj.bottomMargin = bottomMargin
  133. // obj.topMargin = topMargin
  134. // obj.topLeftString = topLeftString
  135. // obj.topCenterString = topCenterString
  136. // obj.topRightString = topRightString
  137. // obj.bottomLeftString = bottomLeftString
  138. // obj.bottomCenterString = bottomCenterString
  139. // obj.bottomRightString = bottomRightString
  140. // obj.startString = startString
  141. // obj.fontSize = fontSize
  142. // obj.textColor = textColor
  143. //// obj.hasHeader = hasHeader
  144. //// obj.hasFooter = hasFooter
  145. //// obj.cellHeight = cellHeight
  146. // obj.id = id
  147. // obj.pageCount = pageCount
  148. // obj.pageRangeString = pageRangeString
  149. //
  150. // obj.dateFormatString = dateFormatString
  151. // obj.pageFormatString = pageFormatString
  152. // obj.isBates = isBates
  153. // obj.batesPrefixString = batesPrefixString
  154. // obj.batesSuffixString = batesSuffixString
  155. // obj.batesDigits = batesDigits
  156. // return obj
  157. // }
  158. }