KMWatermarkAdjectiveBaseModel.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // KMWatermarkAdjectiveBaseModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/27.
  6. //
  7. import Cocoa
  8. enum KMWatermarkeModelPageRangeType: Int {
  9. case all = 0
  10. case odd
  11. case even
  12. case other
  13. }
  14. /// 关联指
  15. enum KMWatermarkAdjectiveText {
  16. case font(name: String, size: CGFloat)
  17. case color(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
  18. }
  19. @objcMembers class KMWatermarkAdjectiveBaseModel: NSObject {
  20. var textFont: KMWatermarkAdjectiveText!
  21. var fontSize: Float = 12.0 {
  22. didSet {
  23. textFont = KMWatermarkAdjectiveText.font(name: "Helvetica", size: CGFloat(fontSize))
  24. }
  25. }
  26. var textColor: KMWatermarkAdjectiveText!
  27. var tempTextColor: NSColor = NSColor.black {
  28. didSet {
  29. // var red: CGFloat = 0.0
  30. // var greed: CGFloat = 0.0
  31. // var blue: CGFloat = 0.0
  32. // NSColor * oldStrokeColor = [config.oldStrokeColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
  33. // [oldStrokeColor getRed:&red green:&green blue:&blue alpha:NULL];
  34. // oldStrokeColor = [NSColor colorWithRed:red green:green blue:blue alpha:config.oldStrokeOpacity];
  35. var red: CGFloat = 0
  36. var green: CGFloat = 0
  37. var blue: CGFloat = 0
  38. var alpha: CGFloat = 0
  39. let oldStrokeColor = tempTextColor.usingColorSpace(NSColorSpace.deviceRGB)
  40. oldStrokeColor?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  41. // let newStrokeColor = NSColor(red: red, green: green, blue: blue, alpha: alpha)
  42. textColor = KMWatermarkAdjectiveText.color(red: red, green: green, blue: blue, alpha: alpha)
  43. }
  44. }
  45. var id: String = ""
  46. var pageRangeType: KMWatermarkeModelPageRangeType = .all
  47. var pageRangeString: String = ""
  48. var pageCount: Int = 0
  49. public func getTextColor() -> NSColor {
  50. var color: NSColor!
  51. switch self.textColor {
  52. case .color(red: let red, green: let green, blue: let blue, alpha: let alpha):
  53. color = NSColor(red: red, green: green, blue: blue, alpha: alpha)
  54. default:
  55. break
  56. }
  57. if (color == nil) {
  58. color = NSColor.red
  59. }
  60. return color
  61. }
  62. public func getTextFont() -> NSFont {
  63. var fontSize = 0.0
  64. var fontName: String = ""
  65. switch self.textFont {
  66. case .font(name: let name, size: let size):
  67. fontName = name
  68. fontSize = size
  69. break
  70. default:
  71. break
  72. }
  73. return NSFont(name: fontName, size: fontSize) ?? NSFont(name: "Helvetica", size: 48)!
  74. }
  75. public func getTextFontName() -> String {
  76. var fontName: String = ""
  77. switch self.textFont {
  78. case .font(name: let name, size: _):
  79. fontName = name
  80. break
  81. default:
  82. break
  83. }
  84. return fontName
  85. }
  86. public func getTextFontSize() -> CGFloat {
  87. var fontSize = 48.0
  88. switch self.textFont {
  89. case .font(name: _, size: let size):
  90. fontSize = size
  91. break
  92. default:
  93. break
  94. }
  95. return fontSize
  96. }
  97. }