// // KMHeaderFooterAdjectiveModel.swift // PDF Reader Pro // // Created by tangchao on 2022/12/27. // import Cocoa enum KMHeaderFooterObjectType: Int { case headerFooter = 0 case bates } @objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding { var type: KMHeaderFooterObjectType = .headerFooter // 是否数据迁移(原App数据迁移) var isMigrate = false // 是否已被更新 var isUpdated = false var leftMargin: Int = 30 var rightMargin: Int = 30 var bottomMargin: Int = 30 var topMargin: Int = 30 var topLeftString: String = "" var topCenterString: String = "" var topRightString: String = "" var bottomLeftString: String = "" var bottomCenterString: String = "" var bottomRightString: String = "" var startString: String = "1" var name: String = "" var cellHeight: CGFloat { get { var height: CGFloat = 45.0 if (self.topLeftString.count > 0) { height += 20.0 } if (self.topCenterString.count > 0) { height += 20.0 } if (self.topRightString.count > 0) { height += 20.0 } if (self.bottomLeftString.count > 0) { height += 20.0 } if (self.bottomCenterString.count > 0) { height += 20.0 } if (self.bottomRightString.count > 0) { height += 20.0 } return height } } var hasVaild: Bool { get { for string in [self.topLeftString, self.topCenterString, self.topRightString, self.bottomLeftString, self.bottomCenterString, self.bottomRightString] { if (!string.isEmpty) { return true } } return false } } override init() { super.init() self.textFont = .font(name: "Helvetica", size: 10) self.textColor = .color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) } required init?(coder: NSCoder) { super.init() type = KMHeaderFooterObjectType.init(rawValue: coder.decodeInteger(forKey: "type"))! pageRangeType = KMWatermarkeModelPageRangeType.init(rawValue: coder.decodeInteger(forKey: "pageChoice"))! leftMargin = coder.decodeInteger(forKey: "leftMargin") rightMargin = coder.decodeInteger(forKey: "rightMargin") bottomMargin = coder.decodeInteger(forKey: "bottomMargin") topMargin = coder.decodeInteger(forKey: "topMargin") topLeftString = coder.decodeObject(forKey: "topLeftString") as? String ?? "" topCenterString = coder.decodeObject(forKey: "topCenterString") as? String ?? "" topRightString = coder.decodeObject(forKey: "topRightString") as? String ?? "" bottomLeftString = coder.decodeObject(forKey: "bottomLeftString") as? String ?? "" bottomCenterString = coder.decodeObject(forKey: "bottomCenterString") as? String ?? "" bottomRightString = coder.decodeObject(forKey: "bottomRightString") as? String ?? "" startString = coder.decodeObject(forKey: "startString") as? String ?? "" fontSize = coder.decodeFloat(forKey: "fontSize") tempTextColor = coder.decodeObject(forKey: "textColor") as? NSColor ?? NSColor.black id = coder.decodeObject(forKey: "headerFooterID") as? String ?? "" pageRangeString = coder.decodeObject(forKey: "pagesString") as? String ?? "" } func encode(with coder: NSCoder) { coder.encode(type.rawValue, forKey: "type") coder.encode(pageRangeType.rawValue, forKey: "pageChoice") coder.encode(leftMargin, forKey: "leftMargin") coder.encode(rightMargin, forKey: "rightMargin") coder.encode(bottomMargin, forKey: "bottomMargin") coder.encode(topMargin, forKey: "topMargin") coder.encode(topLeftString, forKey: "topLeftString") coder.encode(topCenterString, forKey: "topCenterString") coder.encode(topRightString, forKey: "topRightString") coder.encode(bottomLeftString, forKey: "bottomLeftString") coder.encode(bottomCenterString, forKey: "bottomCenterString") coder.encode(bottomRightString, forKey: "bottomRightString") coder.encode(startString, forKey: "startString") coder.encode(fontSize, forKey: "fontSize") coder.encode(self.getTextColor(), forKey: "textColor") coder.encode(id, forKey: "headerFooterID") coder.encode(pageRangeString, forKey: "pagesString") } }