// // 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 { // return NSSet(objects: AUTOROTATE_KEY, PRINTSCALINGMODE_KEY) as! Set // } // // func keyPathsForValuesAffectingAutoRotate() -> Set { // return NSSet(objects: REPRESENTEDOBJECT_KEY) as! Set // } // // func keyPathsForValuesAffectingPrintScalingMode() -> Set { // return NSSet(objects: REPRESENTEDOBJECT_KEY) as! Set // } // // func keyPathsForValuesAffectingPreview() -> Set { // return NSSet(objects: AUTOROTATE_KEY, PRINTSCALINGMODE_KEY) as! Set // } // // override func viewDidLoad() { // super.viewDidLoad() // // Do view setup here. // } // func keyPathsForValuesAffectingPreview() -> Set { return NSSet(objects: "printScalingMode") as! Set //scalingMode scaleMode } // func keyPathsForValuesAffectingPreview() -> Set { // return NSSet(objects: "printScalingMode") as! Set //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]; // } }