123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- //
- // KMCompareFilesConfig.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/11/16.
- //
- import Cocoa
- let PDFCompareISCompareTextFilesKey = "PDFCompareISCompareTextFiles1"
- let PDFCompareISCompareImageFilesKey = "PDFCompareISCompareImageFiles1"
- let PDFCompareInsertColorFilesKey = "PDFCompareInsertColorFiles"
- let PDFCompareInsertOpacityFilesKey = "PDFCompareInsertOpacityFiles"
- let PDFCompareDeleteColorFilesKey = "PDFCompareDeleteColorFiles"
- let PDFCompareDeleteOpacityFilesKey = "PDFCompareDeleteOpacityFiles"
- let PDFCompareReplaceColorFilesKey = "PDFCompareReplaceColorFiles"
- let PDFCompareReplaceOpacityFilesKey = "PDFCompareReplaceOpacityFiles"
- let PDFCompareOldStrokeColorFilesKey = "PDFCompareOldStrokeColorFiles"
- let PDFCompareNewStrokeColorFilesKey = "PDFCompareNewStrokeColorFiles"
- let PDFCompareNewStrokeOpacityFilesKey = "PDFCompareNewStrokeOpacityFiles"
- let PDFCompareOldStrokeOpacityFilesKey = "PDFCompareOldStrokeOpacityFiles"
- let PDFCompareNewFillOpacityFilesKey = "PDFCompareNewFillOpacityFiles"
- let PDFCompareOldFillOpacityFilesKey = "PDFCompareOldFillOpacityFiles"
- let PDFCompareIsNOFillFilesKey = "PDFCompareIsNOFillFiles"
- let PDFComparePDFBlendModeFilesKey = "PDFComparePDFBlendModeFiles"
- class KMCompareFilesConfig {
- static let defaultConfig: KMCompareFilesConfig = KMCompareFilesConfig()
- var fileNewAttribute: KMFileAttribute = KMFileAttribute()
- var fileOldAttribute: KMFileAttribute = KMFileAttribute()
-
- func setColor(_ color: NSColor?, forKey key: String) {
- let data = color != nil ? NSArchiver.archivedData(withRootObject: color!) : NSArchiver.archivedData(withRootObject: NSColor.red)
- UserDefaults.standard.set(data, forKey: key)
- }
- func colorForKey(_ key: String) -> NSColor? {
- var color: NSColor?
- if let data = UserDefaults.standard.data(forKey: key) {
- color = NSUnarchiver.unarchiveObject(with: data) as? NSColor
- } else if let array = UserDefaults.standard.array(forKey: key), array.count > 0 {
- var red, green, blue, alpha: CGFloat
- red = CGFloat(array[0] as! Double)
- green = CGFloat(array[0] as! Double)
- blue = CGFloat(array[0] as! Double)
-
- if array.count > 2 {
- green = CGFloat(array[1] as! Double)
- blue = CGFloat(array[2] as! Double)
- }
- if array.count == 2 {
- alpha = CGFloat(array[1] as! Double)
- } else if array.count > 3 {
- alpha = CGFloat(array[3] as! Double)
- } else {
- alpha = 1.0
- }
- color = NSColor(calibratedRed: red, green: green, blue: blue, alpha: alpha)
- }
- return color
- }
- func setIsCompareText(_ isCompareText: Bool) {
- UserDefaults.standard.set(isCompareText, forKey: PDFCompareISCompareTextFilesKey)
- }
- func isCompareText() -> Bool {
- if UserDefaults.standard.object(forKey: PDFCompareISCompareTextFilesKey) != nil {
- return UserDefaults.standard.bool(forKey: PDFCompareISCompareTextFilesKey)
- } else {
- return true
- }
-
-
- }
- func setIsCompareImage(_ isCompareImage: Bool) {
- UserDefaults.standard.set(isCompareImage, forKey: PDFCompareISCompareImageFilesKey)
- }
- func isCompareImage() -> Bool {
- if UserDefaults.standard.object(forKey: PDFCompareISCompareImageFilesKey) != nil {
- return UserDefaults.standard.bool(forKey: PDFCompareISCompareImageFilesKey)
- } else {
- return true
- }
- }
- func setInsertColor(_ insertColor: NSColor?) {
- setColor(insertColor, forKey: PDFCompareInsertColorFilesKey)
- }
- func insertColor() -> NSColor {
- guard let color = colorForKey(PDFCompareInsertColorFilesKey) else {
- return NSColor.green
- }
- return color
- }
- func setInsertOpacity(_ insertOpacity: CGFloat) {
- UserDefaults.standard.set(insertOpacity, forKey: PDFCompareInsertOpacityFilesKey)
- }
- func insertOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareInsertOpacityFilesKey) as? CGFloat {
- return value
- }
- return 0.2
- }
- func setDeleteColor(_ deleteColor: NSColor?) {
- setColor(deleteColor, forKey: PDFCompareDeleteColorFilesKey)
- }
- func deleteColor() -> NSColor {
- guard let color = colorForKey(PDFCompareDeleteColorFilesKey) else {
- return NSColor.red
- }
- return color
- }
- func setDeleteOpacity(_ deleteOpacity: CGFloat) {
- UserDefaults.standard.set(deleteOpacity, forKey: PDFCompareDeleteOpacityFilesKey)
- }
- func deleteOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareDeleteOpacityFilesKey) as? CGFloat {
- return value
- }
- return 0.2
- }
- func setReplaceColor(_ replaceColor: NSColor?) {
- setColor(replaceColor, forKey: PDFCompareReplaceColorFilesKey)
- }
- func replaceColor() -> NSColor {
- guard let color = colorForKey(PDFCompareReplaceColorFilesKey) else {
- return NSColor.blue
- }
- return color
- }
- func setReplaceOpacity(_ replaceOpacity: CGFloat) {
- UserDefaults.standard.set(replaceOpacity, forKey: PDFCompareReplaceOpacityFilesKey)
- }
- func replaceOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareReplaceOpacityFilesKey) as? CGFloat {
- return value
- }
- return 0.2
- }
- func setOldStrokeColor(_ oldStrokeColor: NSColor?) {
- setColor(oldStrokeColor, forKey: PDFCompareOldStrokeColorFilesKey)
- }
- func oldStrokeColor() -> NSColor {
- guard let color = colorForKey(PDFCompareOldStrokeColorFilesKey) else {
- return NSColor(calibratedRed: 245.0/255.0, green: 40.0/255.0, blue: 27.0/255.0, alpha: 1.0)
- }
- return color
- }
- func setNewStrokeColor(_ newStrokeColor: NSColor?) {
- setColor(newStrokeColor, forKey: PDFCompareNewStrokeColorFilesKey)
- }
- func newStrokeColor() -> NSColor {
- guard let color = colorForKey(PDFCompareNewStrokeColorFilesKey) else {
- return NSColor(calibratedRed: 49.0/255.0, green: 193.0/255.0, blue: 255.0/255.0, alpha: 1.0)
- }
- return color
- }
- func setNewStrokeOpacity(_ newStrokeOpacity: CGFloat) {
- UserDefaults.standard.set(newStrokeOpacity, forKey: PDFCompareNewStrokeOpacityFilesKey)
- }
- func newStrokeOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareNewStrokeOpacityFilesKey) as? CGFloat {
- return value
- }
- return 1.0
- }
- func setOldStrokeOpacity(_ oldStrokeOpacity: CGFloat) {
- UserDefaults.standard.set(oldStrokeOpacity, forKey: PDFCompareOldStrokeOpacityFilesKey)
- }
- func oldStrokeOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareOldStrokeOpacityFilesKey) as? CGFloat {
- return value
- }
- return 1.0
- }
- func setNewFillOpacity(_ newFillOpacity: CGFloat) {
- UserDefaults.standard.set(newFillOpacity, forKey: PDFCompareNewFillOpacityFilesKey)
- }
- func newFillOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareNewFillOpacityFilesKey) as? CGFloat {
- return value
- }
- return 1.0
- }
- func setOldFillOpacity(_ oldFillOpacity: CGFloat) {
- UserDefaults.standard.set(oldFillOpacity, forKey: PDFCompareOldFillOpacityFilesKey)
- }
- func oldFillOpacity() -> CGFloat {
- if let value = UserDefaults.standard.value(forKey: PDFCompareOldFillOpacityFilesKey) as? CGFloat {
- return value
- }
- return 1.0
- }
- func setIsNOFill(_ isNOFill: Bool) {
- UserDefaults.standard.set(isNOFill, forKey: PDFCompareIsNOFillFilesKey)
- }
- func isNOFill() -> Bool {
- return UserDefaults.standard.bool(forKey: PDFCompareIsNOFillFilesKey)
- }
- func setBlendMod(_ blendMod: CPDFBlendMode) {
- UserDefaults.standard.set(blendMod.rawValue, forKey: PDFComparePDFBlendModeFilesKey)
- }
- func blendMod() -> CPDFBlendMode {
- if let value = UserDefaults.standard.value(forKey: PDFComparePDFBlendModeFilesKey) as? Int,
- let blendMode = CPDFBlendMode(rawValue: value) {
- return blendMode
- }
- return CPDFBlendMode.darken
- }
- }
|