123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // KMWatermarkAdjectiveBaseModel.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/27.
- //
- import Cocoa
- enum KMWatermarkeModelPageRangeType: Int {
- case all = 0
- case odd
- case even
- case other
- }
- /// 关联指
- enum KMWatermarkAdjectiveText {
- case font(name: String, size: CGFloat)
- case color(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
- }
- @objcMembers class KMWatermarkAdjectiveBaseModel: NSObject {
- var textFont: KMWatermarkAdjectiveText!
- var fontSize: Float = 12.0 {
- didSet {
- textFont = KMWatermarkAdjectiveText.font(name: "Helvetica", size: CGFloat(fontSize))
- }
- }
- var textColor: KMWatermarkAdjectiveText!
- var tempTextColor: NSColor = NSColor.black {
- didSet {
- // var red: CGFloat = 0.0
- // var greed: CGFloat = 0.0
- // var blue: CGFloat = 0.0
- // NSColor * oldStrokeColor = [config.oldStrokeColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
- // [oldStrokeColor getRed:&red green:&green blue:&blue alpha:NULL];
- // oldStrokeColor = [NSColor colorWithRed:red green:green blue:blue alpha:config.oldStrokeOpacity];
-
- var red: CGFloat = 0
- var green: CGFloat = 0
- var blue: CGFloat = 0
- var alpha: CGFloat = 0
- let oldStrokeColor = tempTextColor.usingColorSpace(NSColorSpace.deviceRGB)
- oldStrokeColor?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
- // let newStrokeColor = NSColor(red: red, green: green, blue: blue, alpha: alpha)
-
- textColor = KMWatermarkAdjectiveText.color(red: red, green: green, blue: blue, alpha: alpha)
- }
- }
-
- var id: String = ""
-
- var pageRangeType: KMWatermarkeModelPageRangeType = .all
- var pageRangeString: String = ""
- var pageCount: Int = 0
-
- public func getTextColor() -> NSColor {
- var color: NSColor!
- switch self.textColor {
- case .color(red: let red, green: let green, blue: let blue, alpha: let alpha):
- color = NSColor(red: red, green: green, blue: blue, alpha: alpha)
- default:
- break
- }
-
- if (color == nil) {
- color = NSColor.red
- }
-
- return color
- }
-
- public func getTextFont() -> NSFont {
- var fontSize = 0.0
- var fontName: String = ""
- switch self.textFont {
- case .font(name: let name, size: let size):
- fontName = name
- fontSize = size
- break
- default:
- break
- }
-
- return NSFont(name: fontName, size: fontSize) ?? NSFont(name: "Helvetica", size: 48)!
- }
-
- public func getTextFontName() -> String {
- var fontName: String = ""
- switch self.textFont {
- case .font(name: let name, size: _):
- fontName = name
- break
- default:
- break
- }
-
- return fontName
- }
-
- public func getTextFontSize() -> CGFloat {
- var fontSize = 48.0
- switch self.textFont {
- case .font(name: _, size: let size):
- fontSize = size
- break
- default:
- break
- }
-
- return fontSize
- }
- }
|