// // KMRedactPropertyContentView.swift // PDF Reader Pro // // Created by tangchao on 2023/1/17. // import Cocoa class KMRedactPropertyContentView: KMRedactContentBaseView { @IBOutlet weak var outsideBox: NSBox! @IBOutlet weak var outsideLabel: NSTextField! @IBOutlet weak var outsideColorView: KMRedactColorView! @IBOutlet weak var fillLabel: NSTextField! @IBOutlet weak var fillColorView: KMRedactColorView! @IBOutlet weak var overTextCheck: NSButton! @IBOutlet var overTextView: NSTextView! @IBOutlet weak var textLabel: NSTextField! @IBOutlet weak var fontStyleComboBox: NSComboBox! @IBOutlet weak var fontSizeComboBox: NSComboBox! @IBOutlet weak var fontTypeComboBox: NSComboBox! @IBOutlet weak var textColorView: KMRedactColorView! @IBOutlet weak var textAligementView: KMRedactAligementView! let fontSizes: Array = [8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72] var annotation : CPDFRedactAnnotation? { get { return nil } set { if (newValue == nil) { return } if ((newValue?.overlayText().isEmpty)!) { self.isOverText(false) } else { self.isOverText(true) } } } override func awakeFromNib() { super.awakeFromNib() self.outsideLabel.stringValue = NSLocalizedString("Redaction Mark Outline Color:", comment: "") self.fillLabel.stringValue = NSLocalizedString("Redact Area Fill Color:", comment: "") self.overTextCheck.title = NSLocalizedString("Use Overlay Text", comment: "") self.overTextCheck.target = self self.overTextCheck.action = #selector(overTextCheckAction) self.overTextView.textContainerInset = NSMakeSize(6, 8) self.overTextView.enclosingScrollView?.borderType = .noBorder self.overTextView.enclosingScrollView?.contentView.wantsLayer = true self.overTextView.enclosingScrollView?.contentView.layer?.borderWidth = 1 self.overTextView.enclosingScrollView?.contentView.layer?.borderColor = NSColor.black.cgColor self.overTextView.string = NSLocalizedString("Redact", comment: "") self.overTextView.delegate = self self.textLabel.stringValue = NSLocalizedString("Font", comment: "") var fontNames: Array = [] for font in CPDFAnnotationModel.supportFonts() { let fontDict: NSDictionary = font as! NSDictionary let fontName: String = fontDict.allKeys.first as! String fontNames.append(fontName) } self.fontStyleComboBox.delegate = self self.fontStyleComboBox.removeAllItems() self.fontStyleComboBox.addItems(withObjectValues: fontNames) self.updateFontName(fontNames[1]) self.fontTypeComboBox.delegate = self self.fontSizeComboBox.delegate = self self.fontSizeComboBox.removeAllItems() self.fontSizeComboBox.addItems(withObjectValues: self.fontSizes) self.fontSizeComboBox.stringValue = NSLocalizedString("Auto", comment: "") /* self.interiorColor = annotationModel.interiorColor; self.borderColor = annotationModel.color; if (annotationModel.isOverlayText) { self.overlayText = annotationModel.overlayText?:@""; self.fontColor = annotationModel.fontColor; self.alignment = annotationModel.alignment; self.font = [NSFont fontWithName:@"Helvetica" size:annotationModel.fontSize]; } */ } // MARK: Private Methods @objc private func overTextCheckAction(sender: NSButton) { if (sender.state == .on) { self.isOverText(true) } else { self.isOverText(false) } guard let callback = self.itemClick else { return } callback(3, sender.state == .on) } private func isOverText(_ isOver: Bool) { if (isOver) { self.overTextCheck.state = .on self.overTextView.isEditable = true self.fontStyleComboBox.isEnabled = true self.fontSizeComboBox.isEnabled = true self.fontTypeComboBox.isEnabled = true } else { self.overTextCheck.state = .off self.overTextView.isEditable = false self.fontStyleComboBox.isEnabled = false self.fontSizeComboBox.isEnabled = false self.fontTypeComboBox.isEnabled = false } } private func updateFontName(_ fontName: String) { var styleNames: Array? for font in CPDFAnnotationModel.supportFonts() { let fontDict = font as! NSDictionary let name: String = fontDict.allKeys.first as! String if (name == fontName) { let datas: Array = fontDict.allValues.first as! Array styleNames = datas self.fontStyleComboBox.stringValue = fontName break } } if (styleNames != nil) { self.fontTypeComboBox.removeAllItems() self.fontTypeComboBox.addItems(withObjectValues: styleNames!) self.fontTypeComboBox.selectItem(at: 0) } } } extension KMRedactPropertyContentView: NSTextViewDelegate { func textDidChange(_ notification: Notification) { if (self.overTextView.isEqual(to: notification.object)) { guard let callback = self.itemClick else { return } callback(4, self.overTextView.string) } } } extension KMRedactPropertyContentView: NSComboBoxDelegate { func comboBoxSelectionDidChange(_ notification: Notification) { if (self.fontStyleComboBox.isEqual(to: notification.object)) { var index: Int = self.fontStyleComboBox.indexOfSelectedItem if (index < 0) { index = 0 } guard let callback = self.itemClick else { return } callback(5, self.fontStyleComboBox.itemObjectValue(at: index)) } else if (self.fontSizeComboBox.isEqual(to: notification.object)) { var index: Int = self.fontSizeComboBox.indexOfSelectedItem if (index < 0) { index = 0 } guard let callback = self.itemClick else { return } callback(6, self.fontSizeComboBox.itemObjectValue(at: index)) } else if (self.fontTypeComboBox.isEqual(to: notification.object)) { var index: Int = self.fontTypeComboBox.indexOfSelectedItem if (index < 0) { index = 0 } guard let callback = self.itemClick else { return } callback(7, self.fontTypeComboBox.itemObjectValue(at: index)) } } }