123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // KMPrintAccessoryController.swift
- // PDF Master
- //
- // Created by lizhe on 2023/2/21.
- //
- import Cocoa
- class KMPrintAccessoryController: NSViewController, NSPrintPanelAccessorizing {
- let AUTOROTATE_KEY = "autoRotate"
- let AUTOROTATE_KEYPATH = "representedObject.dictionary.PDFPrintAutoRotate"
- let PRINTSCALINGMODE_KEY = "printScalingMode"
- let PRINTSCALINGMODE_KEYPATH = "representedObject.dictionary.PDFPrintScalingMode"
- let REPRESENTEDOBJECT_KEY = "representedObject"
-
- var printOperation: NSPrintOperation?
- @objc var printScalingMode: PDFPrintScalingMode
- {
- @objc set {
- let printInfo = self.representedObject as! NSPrintInfo
- printInfo.dictionary().setObject(newValue.rawValue, forKey: "PDFPrintScalingMode" as NSCopying)
- // self.setValue(NSNumber.init(value: newValue.rawValue), forKeyPath: PRINTSCALINGMODE_KEYPATH)
- }
- @objc get {
- return PDFPrintScalingMode(rawValue: (self.value(forKeyPath: PRINTSCALINGMODE_KEYPATH)) as! Int) ?? .pageScaleNone
- }
- }
- // didSet {
- // let printInfo = self.representedObject as! NSPrintInfo
- // printInfo.dictionary().setObject(self.printScalingMode.rawValue, forKey: "PDFPrintScalingMode" as NSCopying)
- // self.printOperation?.view?.updateLayer()
- // self.printOperation?.printInfo.updateFromPMPageFormat()
- // self.printOperation?.printInfo.updateFromPMPrintSettings()
- // self.printOperation!.runModal(for: NSApplication.shared.mainWindow!, delegate: nil, didRun: nil, contextInfo: nil)
- // self.printOperation?.view?.updateLayer()
- // print(printInfo)
- // printInfo.dictionary.PDFPrintScalingMode
- // 不改变
- // [[printInfo dictionary] setObject:[NSNumber numberWithBool:[[[printInfo dictionary] objectForKey:NSPrintHeaderAndFooter] boolValue]] forKey:NSPrintHeaderAndFooter];
- // }
- // }
- var autoRotate: Bool = false
- // {
- // set {
- // self.setValue(NSNumber.init(booleanLiteral: newValue), forKeyPath: AUTOROTATE_KEYPATH)
- // }
- // get {
- // return (self.value(forKeyPath: AUTOROTATE_KEYPATH)) as! Bool
- // }
- // }
-
- @IBOutlet weak var actualSizeButton: NSButton!
- @IBOutlet weak var scaleFachPageButton: NSButton!
- @IBOutlet weak var onlyScaleDownLargeButton: NSButton!
-
-
- // func keyPathsForValuesAffectingLocalizedSummaryItems() -> Set<String> {
- // return NSSet(objects: AUTOROTATE_KEY, PRINTSCALINGMODE_KEY) as! Set<String>
- // }
- //
- // func keyPathsForValuesAffectingAutoRotate() -> Set<String> {
- // return NSSet(objects: REPRESENTEDOBJECT_KEY) as! Set<String>
- // }
- //
- // func keyPathsForValuesAffectingPrintScalingMode() -> Set<String> {
- // return NSSet(objects: REPRESENTEDOBJECT_KEY) as! Set<String>
- // }
- //
- // func keyPathsForValuesAffectingPreview() -> Set<String> {
- // return NSSet(objects: AUTOROTATE_KEY, PRINTSCALINGMODE_KEY) as! Set<String>
- // }
- //
- // override func viewDidLoad() {
- // super.viewDidLoad()
- // // Do view setup here.
- // }
- //
-
- func keyPathsForValuesAffectingPreview() -> Set<String> {
- return NSSet(objects: "printScalingMode") as! Set<String> //scalingMode scaleMode
- }
-
-
- // func keyPathsForValuesAffectingPreview() -> Set<String> {
- // return NSSet(objects: "printScalingMode") as! Set<String> //scalingMode scaleMode
- // }
-
- //缩小后显示的内容
- func localizedSummaryItems() -> [[NSPrintPanel.AccessorySummaryKey : String]] {
- let autoRotation = self.autoRotate ? NSLocalizedString("On", comment: "") : NSLocalizedString("Off", comment: "")
- var autoScaling = ""
- // switch (printScalingMode) {
- // case .pageScaleNone:
- // autoScaling = NSLocalizedString("None", comment: "")
- // case .pageScaleToFit:
- // autoScaling = NSLocalizedString("Scale Each Page", comment: "")
- // case .pageScaleDownToFit:
- // autoScaling = NSLocalizedString("Only Scale Down Large Pages", comment: "")
- // @unknown default:
- // print("未找到")
- // }
- return [[NSPrintPanel.AccessorySummaryKey.itemName: NSLocalizedString("Page Auto Rotation", comment: ""),
- NSPrintPanel.AccessorySummaryKey.itemDescription : autoRotation],
- [NSPrintPanel.AccessorySummaryKey.itemName: NSLocalizedString("Page Auto Scaling", comment: ""),
- NSPrintPanel.AccessorySummaryKey.itemDescription : autoScaling]]
- }
-
- @IBAction func actualSizeButtonAction(_ sender: Any) {
- self.printScalingMode = .pageScaleNone
- }
- @IBAction func scaleFachPageButtonAction(_ sender: Any) {
- self.printScalingMode = .pageScaleToFit
- }
- @IBAction func onlyScaleDownLargeButtonAction(_ sender: Any) {
- self.printScalingMode = .pageScaleDownToFit
- }
-
-
- // - (void)setWxmailPreview:(BOOL)flag {
- // NSPrintInfo *printInfo = [self representedObject];
- // // 不改变
- // [[printInfo dictionary] setObject:[NSNumber numberWithBool:[[[printInfo dictionary] objectForKey:NSPrintHeaderAndFooter] boolValue]] forKey:NSPrintHeaderAndFooter];
- // }
- //
- // - (void) refreshPreview {
- // qInfo() << "refreshPreview";
- // // NOTE: 刷新
- // [self setWxmailPreview:NO];
- // }
- }
|