123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- //
- // KMRedactPropertiesWindowController.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/12/19.
- //
- import Cocoa
- class KMRedactPropertiesWindowController: NSWindowController {
-
- var readactAnnotation: CPDFRedactAnnotation?
-
- @IBOutlet weak var outlineColorLabel: NSTextField!
- @IBOutlet weak var outlineColorWell: NSColorWell!
- @IBOutlet weak var fillColorLabel: NSTextField!
- @IBOutlet weak var fillColorWell: NSColorWell!
-
- @IBOutlet weak var overlayTextButton: NSButton!
- @IBOutlet weak var overlayTextLabel: NSTextField!
- @IBOutlet weak var overlayTextField: NSTextField!
- @IBOutlet weak var fontSizeLabel: NSTextField!
-
- @IBOutlet weak var fontSizeComboBox: NSComboBox!
- @IBOutlet weak var alignementLabel: NSTextField!
- @IBOutlet weak var segmentedControl: NSSegmentedControl!
- @IBOutlet weak var fontColorLabel: NSTextField!
-
- @IBOutlet weak var fontColorWell: NSColorWell!
- @IBOutlet weak var makePropertiesButton: NSButton!
- @IBOutlet weak var cancelButton: NSButton!
- @IBOutlet weak var okButton: NSButton!
- /*
- @property (nonatomic,assign) NSModalSession modalSession;
- */
-
- var callback: ((_ anno: CPDFRedactAnnotation?)->Void)?
- convenience init() {
- self.init(windowNibName: "KMRedactPropertiesWindowController")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.outlineColorLabel.stringValue = KMLocalizedString("Redaction Mark Outline Color:", nil)
- self.fillColorLabel.stringValue = KMLocalizedString("Redact Area Fill Color:", nil)
- self.overlayTextButton.title = KMLocalizedString("Use Overlay Text", nil)
- self.overlayTextLabel.stringValue = KMLocalizedString("Overlay Text:", nil)
- // self.repeatTextButton.title = NSLocalizedString(@"Repeat Text", nil);
- // self.autoSizeTextButton.title = NSLocalizedString(@"Auto-Size text to fit redaction region", nil);
- self.alignementLabel.stringValue = KMLocalizedString("Text Alignment", nil)
- self.fontSizeLabel.stringValue = KMLocalizedString("Font Size", nil)
- self.fontColorLabel.stringValue = String(format: "%@:", KMLocalizedString("Font Color", nil))
- self.makePropertiesButton.title = KMLocalizedString("Make Properties Default", nil)
- self.cancelButton.title = KMLocalizedString("Cancel", nil)
- self.okButton.title = KMLocalizedString("OK", nil)
-
- if let anno = self.readactAnnotation {
- self.outlineColorWell.color = anno.borderColor()
- self.fillColorWell.color = anno.interiorColor()
- self.fontColorWell.color = anno.fontColor()
-
- self.fontSizeComboBox.stringValue = String(format: "%.lf pt", anno.font().pointSize)
- var segment = 0
- if(anno.alignment().rawValue == 1) {
- segment = 2
- } else if (anno.alignment().rawValue == 2) {
- segment = 1
- }
- self.segmentedControl.setSelected(true, forSegment: segment)
- self.overlayTextField.stringValue = anno.overlayText() ?? ""
- if(anno.overlayText().isEmpty == false) {
- self.overlayTextButton.state = .on
- } else {
- self.overlayTextButton.state = .off
- }
- self.makePropertiesButton.isHidden = false
- } else {
- self.outlineColorWell.color = KMPDFAnnotationRedactConfig.shared.redactOutlineColor!
- self.fillColorWell.color = KMPDFAnnotationRedactConfig.shared.redactFillColor!
- self.fontColorWell.color = KMPDFAnnotationRedactConfig.shared.redactFontColor!
- self.overlayTextButton.state = KMPDFAnnotationRedactConfig.shared.overlayText ? .on : .off
- // self.repeatTextButton.state = [KMPDFAnnotationRedactConfig sharedInstance].repeatText ? NSControlStateValueOn : NSControlStateValueOff;
- // self.autoSizeTextButton.state = [KMPDFAnnotationRedactConfig sharedInstance].autoSizeText ? NSControlStateValueOn : NSControlStateValueOff;
- self.overlayTextField.stringValue = KMPDFAnnotationRedactConfig.shared.overlayTextString
- self.fontSizeComboBox.stringValue = String(format: "%ld pt", KMPDFAnnotationRedactConfig.shared.fontSize)
- var segment = 0
- if(KMPDFAnnotationRedactConfig.shared.textAlignment == 1) {
- segment = 2
- } else if (KMPDFAnnotationRedactConfig.shared.textAlignment == 2) {
- segment = 1
- }
- self.segmentedControl.setSelected(true, forSegment: segment)
- self.makePropertiesButton.isHidden = true
- }
-
- self.updateUIState()
- }
-
- @IBAction func cancel_button(_ sender: AnyObject?) {
- if self.callback != nil {
- self.callback!(self.readactAnnotation)
- }
- self.km_quick_endSheet()
- }
-
- @IBAction func sure_button(_ sender: AnyObject?) {
- let s = (self.fontSizeComboBox.stringValue as? NSString)?.trimmingCharacters(in: CharacterSet(charactersIn: " pt")) ?? ""
- let fontsize = Int(s) ?? 12
- var alignment: NSTextAlignment = .left
- if(self.segmentedControl.indexOfSelectedItem == 1) {
- alignment = .center
- } else if (self.segmentedControl.indexOfSelectedItem == 2) {
- alignment = .right
- }
-
- if(self.readactAnnotation == nil || self.makePropertiesButton.state == .on) {
- KMPDFAnnotationRedactConfig.shared.redactOutlineColor = self.outlineColorWell.color
- KMPDFAnnotationRedactConfig.shared.redactFillColor = self.fillColorWell.color
- KMPDFAnnotationRedactConfig.shared.redactFontColor = self.fontColorWell.color
- KMPDFAnnotationRedactConfig.shared.overlayText = self.overlayTextButton.state == .on
- KMPDFAnnotationRedactConfig.shared.fontSize = fontsize
- KMPDFAnnotationRedactConfig.shared.textAlignment = alignment.rawValue
- if(self.overlayTextButton.state == .on) {
- KMPDFAnnotationRedactConfig.shared.overlayTextString = self.overlayTextField.stringValue
- } else {
- KMPDFAnnotationRedactConfig.shared.overlayTextString = ""
- }
- }
-
- if let anno = self.readactAnnotation {
- anno.setBorderColor(self.outlineColorWell.color)
- anno.setInteriorColor(self.fillColorWell.color)
- anno.setFontColor(self.fontColorWell.color)
- if(self.overlayTextButton.state == .on) {
- anno.setFont(.init(name: "Helvetica", size: fontsize.cgFloat))
- anno.setAlignment(alignment)
- anno.setOverlayText(self.overlayTextField.stringValue)
- } else {
- anno.setOverlayText("")
- }
- }
- if self.callback != nil {
- self.callback!(self.readactAnnotation)
- }
- self.km_quick_endSheet()
- }
-
- @IBAction func useOverlayText_button(_ sender: AnyObject?) {
- self.updateUIState()
- }
-
- @IBAction func autoSzieText_button(_ sender: AnyObject?) {
- self.updateUIState()
- }
-
- @IBAction func fontSize_Combox(_ sender: AnyObject?) {
-
- }
- func updateUIState() {
- let state = self.overlayTextButton.state
- let enabled = state == .on
- self.overlayTextLabel.isEnabled = enabled
- self.overlayTextField.isEnabled = enabled
- // self.autoSizeTextButton.enabled = state;
- self.fontSizeLabel.isEnabled = enabled
- self.fontSizeComboBox.isEnabled = enabled
- self.alignementLabel.isEnabled = enabled
- self.segmentedControl.isEnabled = enabled
- // self.repeatTextButton.enabled = state;
- self.fontColorLabel.isEnabled = enabled
- self.fontColorWell.isEnabled = enabled
- if(enabled) {
- self.overlayTextLabel.textColor = .labelColor
- self.fontSizeLabel.textColor = .labelColor
- self.alignementLabel.textColor = .labelColor
- self.fontColorLabel.textColor = .labelColor
- } else {
- self.overlayTextLabel.textColor = .tertiaryLabelColor
- self.fontSizeLabel.textColor = .tertiaryLabelColor
- self.fontColorLabel.textColor = .tertiaryLabelColor
- self.alignementLabel.textColor = .tertiaryLabelColor
- }
- }
- }
|