|
@@ -0,0 +1,509 @@
|
|
|
+//
|
|
|
+// KMAnnotationChoiceWidgetAppearanceViewController.swift
|
|
|
+// PDF Reader Pro
|
|
|
+//
|
|
|
+// Created by wanjun on 2024/1/16.
|
|
|
+//
|
|
|
+
|
|
|
+import Cocoa
|
|
|
+
|
|
|
+private enum KMPDFAnnotationFontWeightType: Int {
|
|
|
+ case ultraLight = 0
|
|
|
+ case thin
|
|
|
+ case light
|
|
|
+ case regular
|
|
|
+ case medium
|
|
|
+ case semibold
|
|
|
+ case bold
|
|
|
+ case heavy
|
|
|
+ case black
|
|
|
+}
|
|
|
+
|
|
|
+class KMAnnotationChoiceWidgetAppearanceViewController: NSViewController {
|
|
|
+
|
|
|
+ private var _annotations: [CPDFChoiceWidgetAnnotation] = []
|
|
|
+ private var _formMode: CAnnotationType = .radioButton
|
|
|
+ var pdfView: CPDFListView?
|
|
|
+ var annotationModel: CPDFAnnotationModel?
|
|
|
+
|
|
|
+ // Outlets
|
|
|
+ @IBOutlet private var fillColorLabel: NSTextField!
|
|
|
+ @IBOutlet private var fillColorPickerView: KMColorPickerView!
|
|
|
+ @IBOutlet private var fontViewBottom: NSLayoutConstraint!
|
|
|
+ @IBOutlet private var fontLabel: NSTextField!
|
|
|
+ @IBOutlet private var fontPopUpButton: KMPopUpButton!
|
|
|
+ @IBOutlet private var fontStylePopUpButton: KMPopUpButton!
|
|
|
+ @IBOutlet private var fontSizeComboBox: KMComboBox!
|
|
|
+ @IBOutlet private var fontButton: NSButton!
|
|
|
+ @IBOutlet private var colorPickerView: KMColorPickerView!
|
|
|
+
|
|
|
+ // Properties
|
|
|
+ private var annotation: CPDFChoiceWidgetAnnotation?
|
|
|
+ private var isFromMode: Bool = false
|
|
|
+ private var annotationFont: NSFont?
|
|
|
+ private var fontWeightType: KMPDFAnnotationFontWeightType = .ultraLight
|
|
|
+
|
|
|
+ deinit {
|
|
|
+ fillColorPickerView.target = nil
|
|
|
+ fillColorPickerView.action = nil
|
|
|
+ colorPickerView.target = nil
|
|
|
+ colorPickerView.action = nil
|
|
|
+ NSColorPanel.shared.setTarget(nil)
|
|
|
+ NSColorPanel.shared.setAction(nil)
|
|
|
+ NSFontManager.shared.target = nil
|
|
|
+
|
|
|
+ NotificationCenter.default.removeObserver(self)
|
|
|
+ DistributedNotificationCenter.default().removeObserver(self)
|
|
|
+ annotation = nil
|
|
|
+ annotationFont = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: Init
|
|
|
+
|
|
|
+ override func loadView() {
|
|
|
+ super.loadView()
|
|
|
+
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(formButtonLabelTextField), name: Notification.Name("KMFormActionButtonLabelTextField"), object: nil)
|
|
|
+
|
|
|
+ fillColorLabel.stringValue = NSLocalizedString("Colors", comment: "")
|
|
|
+ fillColorLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ fontLabel.stringValue = NSLocalizedString("Fonts", comment: "")
|
|
|
+ fontLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ fillColorPickerView.noContentString = true
|
|
|
+ fillColorPickerView.annotationTypeString = NSLocalizedString("Background Color", comment: "")
|
|
|
+ fillColorPickerView.annotationType = .fromFillColors
|
|
|
+ fillColorPickerView.isFillColor = true
|
|
|
+ fillColorPickerView.isCallColorPanelAction = true
|
|
|
+
|
|
|
+ colorPickerView.noContentString = true
|
|
|
+ colorPickerView.annotationTypeString = NSLocalizedString("Text Color", comment: "")
|
|
|
+ colorPickerView.annotationType = .fromColors
|
|
|
+ colorPickerView.isCallColorPanelAction = true
|
|
|
+
|
|
|
+ fontStylePopUpButton.type = .arrowDown
|
|
|
+ fontSizeComboBox.type = .none
|
|
|
+ fontSizeComboBox.comboxRect = fontSizeComboBox.bounds
|
|
|
+ fontPopUpButton.type = .arrowUpDown
|
|
|
+
|
|
|
+ fontPopUpButton.wantsLayer = true
|
|
|
+ fontStylePopUpButton.wantsLayer = true
|
|
|
+ fontSizeComboBox.wantsLayer = true
|
|
|
+
|
|
|
+ fontPopUpButton.layer!.borderWidth = 1.0
|
|
|
+ fontStylePopUpButton.layer!.borderWidth = 1.0
|
|
|
+ fontSizeComboBox.layer!.borderWidth = 1.0
|
|
|
+
|
|
|
+ fontPopUpButton.layer!.cornerRadius = 1.0
|
|
|
+ fontStylePopUpButton.layer!.cornerRadius = 1.0
|
|
|
+ fontSizeComboBox.layer!.cornerRadius = 1.0
|
|
|
+
|
|
|
+ updateViewColor()
|
|
|
+
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewDidAppear() {
|
|
|
+ super.viewDidAppear()
|
|
|
+
|
|
|
+ let showConvertDetails = KMPropertiesViewPopController.showChangeColorDetails()
|
|
|
+ if showConvertDetails, let document = self.view.window?.windowController?.document as? NSDocument,
|
|
|
+ document.fileURL != nil {
|
|
|
+ KMPropertiesViewPopController.defaultManager().showChangeColorDetailsView(colorPickerView.firstButton)
|
|
|
+ }
|
|
|
+
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)),
|
|
|
+ name: Notification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: Private Method
|
|
|
+
|
|
|
+ func reloadData() {
|
|
|
+ var opacity: CGFloat = 1
|
|
|
+ if let color = annotation!.backgroundColor {
|
|
|
+ color.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(nil, green: nil, blue: nil, alpha: &opacity)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let fontColor = annotation?.fontColor,
|
|
|
+ annotation != nil /*|| annotation?.type == .widgetPushButtonControl*/ {
|
|
|
+ fillColorPickerView.color = annotation?.backgroundColor
|
|
|
+ colorPickerView.color = fontColor
|
|
|
+ }
|
|
|
+
|
|
|
+ fontSizeComboBox.stringValue = "\(annotation?.font.pointSize) pt"
|
|
|
+
|
|
|
+ DispatchQueue.global(qos: .default).async { [self] in
|
|
|
+ let fonts = NSFontManager.shared.availableFontFamilies
|
|
|
+ var selectedIndex = 0
|
|
|
+ let family = annotation?.font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String ?? ""
|
|
|
+ let style = annotation?.font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String ?? ""
|
|
|
+
|
|
|
+ let menu = NSMenu()
|
|
|
+
|
|
|
+ for (index, fontName) in fonts.enumerated() {
|
|
|
+ if let font = NSFont(name: fontName, size: 12.0) {
|
|
|
+ let attributes = [NSAttributedString.Key.font: font]
|
|
|
+ let attributedString = NSAttributedString(string: fontName, attributes: attributes)
|
|
|
+ let item = NSMenuItem()
|
|
|
+ item.attributedTitle = attributedString
|
|
|
+ menu.addItem(item)
|
|
|
+ if annotation?.font.fontName == font.fontName {
|
|
|
+ selectedIndex = index
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
+ fontPopUpButton.menu = menu
|
|
|
+ fontPopUpButton.selectItem(at: selectedIndex)
|
|
|
+ let selectedStyleIndex = setFontStyleWithFontName(family, currentStyle: style)
|
|
|
+ fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ annotationFont = annotation?.font
|
|
|
+
|
|
|
+ let fontManager = NSFontManager.shared
|
|
|
+ fontManager.target = self
|
|
|
+ fontManager.action = #selector(changeFont(_:))
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateAnnotationMode() {
|
|
|
+ let userDefaults = UserDefaults.standard
|
|
|
+ let note = annotation!
|
|
|
+ let annotationMode = self.formMode
|
|
|
+
|
|
|
+ switch annotationMode {
|
|
|
+ case .actionButton:
|
|
|
+ userDefaults.setColor(note.backgroundColor, forKey: SKAnnotationActionButtonWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(note.fontColor, forKey: SKAnnotationActionButtonWidgetFontColorKey)
|
|
|
+ userDefaults.set(note.font.fontName, forKey: SKAnnotationActionButtonWidgetFontNameKey)
|
|
|
+ userDefaults.set(note.font.pointSize, forKey: SKAnnotationActionButtonWidgetFontSizeKey)
|
|
|
+ case .comboBox:
|
|
|
+ userDefaults.setColor(note.backgroundColor, forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(note.fontColor, forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
+ userDefaults.set(note.font.fontName, forKey: SKAnnotationChoiceWidgetFontNameKey)
|
|
|
+ userDefaults.set(note.font.pointSize, forKey: SKAnnotationChoiceWidgetFontSizeKey)
|
|
|
+ case .listMenu:
|
|
|
+ userDefaults.setColor(note.backgroundColor, forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(note.fontColor, forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
+ userDefaults.set(note.font.fontName, forKey: SKAnnotationChoiceListWidgetFontNameKey)
|
|
|
+ userDefaults.set(note.font.pointSize, forKey: SKAnnotationChoiceListWidgetFontSizeKey)
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func colorWithCGColor(_ cgColor: CGColor?) -> NSColor? {
|
|
|
+ guard let cgColor = cgColor else { return nil }
|
|
|
+ return NSColor(cgColor: cgColor)
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateViewColor() {
|
|
|
+ if KMAppearance.isDarkMode() {
|
|
|
+ let darkBorderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ let darkBackgroundColor = NSColor(red: 57/255.0, green: 60/255.0, blue: 62/255.0, alpha: 1.0).cgColor
|
|
|
+
|
|
|
+ fontPopUpButton.layer?.borderColor = darkBorderColor
|
|
|
+ fontStylePopUpButton.layer?.borderColor = darkBorderColor
|
|
|
+ fontSizeComboBox.layer?.borderColor = darkBorderColor
|
|
|
+
|
|
|
+ fontPopUpButton.layer?.backgroundColor = darkBackgroundColor
|
|
|
+ fontStylePopUpButton.layer?.backgroundColor = darkBackgroundColor
|
|
|
+ fontSizeComboBox.layer?.backgroundColor = darkBackgroundColor
|
|
|
+ } else {
|
|
|
+ let lightBorderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ let lightBackgroundColor = NSColor.white.cgColor
|
|
|
+
|
|
|
+ fontPopUpButton.layer?.borderColor = lightBorderColor
|
|
|
+ fontStylePopUpButton.layer?.borderColor = lightBorderColor
|
|
|
+ fontSizeComboBox.layer?.borderColor = lightBorderColor
|
|
|
+
|
|
|
+ fontPopUpButton.layer?.backgroundColor = lightBackgroundColor
|
|
|
+ fontStylePopUpButton.layer?.backgroundColor = lightBackgroundColor
|
|
|
+ fontSizeComboBox.layer?.backgroundColor = lightBackgroundColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func changeStoredFontInfo(_ sender: Any) {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+// if let font = (sender as AnyObject).convertFont(tAnnotation.font) {
|
|
|
+// tAnnotation.font = font
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func setFontStyleWithFontName(_ fontName: String, currentStyle style: String?) -> UInt {
|
|
|
+ var selectIndex: UInt = 0
|
|
|
+ let menu = NSMenu()
|
|
|
+ if let fontFamily = NSFontManager.shared.availableMembers(ofFontFamily: fontName) {
|
|
|
+ for (index, array) in fontFamily.enumerated() {
|
|
|
+ let styleName = array[1] as? String ?? ""
|
|
|
+ if style == styleName {
|
|
|
+ selectIndex = UInt(index)
|
|
|
+ }
|
|
|
+ let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: fontName, NSFontDescriptor.AttributeName.face: styleName])
|
|
|
+ let font = NSFont(descriptor: attributeFontDescriptor, size: 12.0)
|
|
|
+ let attrited = [NSAttributedString.Key.font: font]
|
|
|
+ let string = NSAttributedString(string: styleName, attributes: attrited)
|
|
|
+ let item = NSMenuItem()
|
|
|
+ item.attributedTitle = string
|
|
|
+ menu.addItem(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if style == nil {
|
|
|
+ selectIndex = 0
|
|
|
+ }
|
|
|
+ fontStylePopUpButton.menu = menu
|
|
|
+ return selectIndex
|
|
|
+ }
|
|
|
+
|
|
|
+ private func updateAnnotation() {
|
|
|
+ if annotationModel?.annotation != nil {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+ pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: Set & Get
|
|
|
+
|
|
|
+ var formMode: CAnnotationType {
|
|
|
+ get {
|
|
|
+ return _formMode
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _formMode = newValue
|
|
|
+ isFromMode = true
|
|
|
+
|
|
|
+ let sud = UserDefaults.standard
|
|
|
+ var note: CPDFChoiceWidgetAnnotation?
|
|
|
+ var bounds = NSRect(x: 0, y: 0, width: 60, height: 25)
|
|
|
+ var backgroundColor: NSColor?
|
|
|
+ var fontColor: NSColor?
|
|
|
+
|
|
|
+ if formMode == .listMenu {
|
|
|
+ bounds = NSRect(x: 0, y: 0, width: 100, height: 80)
|
|
|
+ note = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: pdfView!.document, listChoice: true)
|
|
|
+
|
|
|
+ backgroundColor = sud.color(forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
|
|
|
+ note?.backgroundColor = backgroundColor ?? NSColor.clear
|
|
|
+
|
|
|
+ fontColor = sud.color(forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
+ note?.fontColor = fontColor
|
|
|
+
|
|
|
+ if let font = sud.font(forNameKey: SKAnnotationChoiceListWidgetFontNameKey,
|
|
|
+ sizeKey: SKAnnotationChoiceListWidgetFontSizeKey) {
|
|
|
+ note?.font = font
|
|
|
+ }
|
|
|
+ } else if formMode == .comboBox {
|
|
|
+ bounds = NSRect(x: 0, y: 0, width: 100, height: 25)
|
|
|
+ note = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: pdfView!.document, listChoice: false)
|
|
|
+
|
|
|
+ backgroundColor = sud.color(forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
|
|
|
+ note?.backgroundColor = backgroundColor ?? NSColor.clear
|
|
|
+
|
|
|
+ fontColor = sud.color(forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
+ note?.fontColor = fontColor
|
|
|
+
|
|
|
+ if let font = sud.font(forNameKey: SKAnnotationChoiceWidgetFontNameKey,
|
|
|
+ sizeKey: SKAnnotationChoiceWidgetFontSizeKey) {
|
|
|
+ note?.font = font
|
|
|
+ }
|
|
|
+ } else if formMode == .actionButton {
|
|
|
+ bounds = NSRect(x: 0, y: 0, width: 100, height: 80)
|
|
|
+// note = KMPDFAnnotationChoiceWidgetSub(bounds: bounds)
|
|
|
+
|
|
|
+ backgroundColor = sud.color(forKey: SKAnnotationActionButtonWidgetBackgroundColorKey)
|
|
|
+ note?.backgroundColor = backgroundColor ?? NSColor.clear
|
|
|
+
|
|
|
+ fontColor = sud.color(forKey: SKAnnotationActionButtonWidgetFontColorKey)
|
|
|
+ note?.fontColor = fontColor
|
|
|
+
|
|
|
+ if let font = sud.font(forNameKey: SKAnnotationActionButtonWidgetFontNameKey,
|
|
|
+ sizeKey: SKAnnotationActionButtonWidgetFontSizeKey) {
|
|
|
+ note?.font = font
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ note = CPDFChoiceWidgetAnnotation(document: pdfView?.document)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let note1 = note {
|
|
|
+ self.annotations = [note1]
|
|
|
+ self.annotation = note1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var annotations: [CPDFChoiceWidgetAnnotation] {
|
|
|
+ get {
|
|
|
+ return _annotations
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _annotations = newValue
|
|
|
+ annotation = _annotations.first
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: Button Action
|
|
|
+
|
|
|
+ @IBAction func colorPickerViewAction(_ sender: Any) {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ tAnnotation.fontColor = colorPickerView.color
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func fillColorPickerViewAction(_ sender: Any) {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ tAnnotation.backgroundColor = fillColorPickerView.color
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func buttonClickedChangeFont(_ sender: Any) {
|
|
|
+// guard let weakSelf = self else { return }
|
|
|
+
|
|
|
+// let fontWindowController = KMAnnotationFontWindowController.sharedAnnotationFont()
|
|
|
+// guard let window = fontWindowController.window else { return }
|
|
|
+//
|
|
|
+// fontWindowController.annotations = weakSelf.annotations
|
|
|
+//
|
|
|
+// fontWindowController.annotationAlignCallback = { selectedCount in
|
|
|
+// for tAnnotation in weakSelf.annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+//
|
|
|
+// switch selectedCount {
|
|
|
+// case 0:
|
|
|
+// tAnnotation.alignment = .left
|
|
|
+// case 2:
|
|
|
+// tAnnotation.alignment = .center
|
|
|
+// case 1:
|
|
|
+// tAnnotation.alignment = .right
|
|
|
+// case 3:
|
|
|
+// tAnnotation.alignment = .justified
|
|
|
+// default:
|
|
|
+// break
|
|
|
+// }
|
|
|
+// }
|
|
|
+// weakSelf.pdfview.setNeedsDisplay(true)
|
|
|
+// }
|
|
|
+//
|
|
|
+// fontWindowController.annotationCallback = { annotation in
|
|
|
+// // Handle annotation callback if needed
|
|
|
+// }
|
|
|
+//
|
|
|
+// window.orderFront(sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func fontColorButtonAction(_ sender: NSButton) {
|
|
|
+ NSColorPanel.shared.setTarget(self)
|
|
|
+ NSColorPanel.shared.setAction(#selector(colorPanelAction(_:)))
|
|
|
+ NSColorPanel.shared.orderFront(nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func colorPanelAction(_ sender: Any) {
|
|
|
+ let color = NSColorPanel.shared.color
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ tAnnotation.fontColor = color
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func currentFontColorButtonAction(_ sender: NSButton) {
|
|
|
+ if let cgColor = sender.layer?.backgroundColor,
|
|
|
+ let color = colorWithCGColor(cgColor) {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ tAnnotation.fontColor = color
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func fontPopUpButtonAction(_ sender: NSPopUpButton) {
|
|
|
+ if let selectedItem = fontPopUpButton.selectedItem {
|
|
|
+ let familyString = selectedItem.attributedTitle?.string ?? ""
|
|
|
+ let selectIndex = setFontStyleWithFontName(familyString, currentStyle: nil)
|
|
|
+ if let styleString = fontStylePopUpButton.selectedItem?.title {
|
|
|
+ fontStylePopUpButton.selectItem(at: Int(selectIndex))
|
|
|
+
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ if let font = annotation!.font {
|
|
|
+ if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? NSNumber {
|
|
|
+ let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: familyString, NSFontDescriptor.AttributeName.face: styleString])
|
|
|
+ let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat(fontSize.floatValue))
|
|
|
+
|
|
|
+ if let newFont = newFont {
|
|
|
+ tAnnotation.font = newFont
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func fontSizeComboBoxAction(_ sender: NSComboBox) {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+ if let font = tAnnotation.font {
|
|
|
+ if let newFont = NSFont(name: font.fontName, size: CGFloat(fontSizeComboBox.floatValue)) {
|
|
|
+ tAnnotation.font = newFont
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func fontStylePopUpButtonAction(_ sender: NSPopUpButton) {
|
|
|
+ guard let styleString = fontStylePopUpButton.selectedItem?.title else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for tAnnotation in annotations {
|
|
|
+ if let font = tAnnotation.font {
|
|
|
+ if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? String,
|
|
|
+ let familyString = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String {
|
|
|
+
|
|
|
+ let floatValue = Float(fontSize)
|
|
|
+ let cgFloatValue = CGFloat(floatValue!)
|
|
|
+
|
|
|
+ let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: familyString, NSFontDescriptor.AttributeName.face: styleString])
|
|
|
+ let newFont = NSFont(descriptor: attributeFontDescriptor, size: cgFloatValue)
|
|
|
+ if newFont != nil {
|
|
|
+ tAnnotation.font = newFont
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: NSNotification Action
|
|
|
+
|
|
|
+ @objc func formButtonLabelTextField() {
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func changeFont(_ sender: Any) {
|
|
|
+// annotationFont = sender.convertFont(annotationFont)
|
|
|
+
|
|
|
+ for tAnnotation in annotations {
|
|
|
+// tAnnotation.removeAllAppearanceStreams()
|
|
|
+// tAnnotation.setFont(annotationFont)
|
|
|
+ }
|
|
|
+ updateAnnotation()
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func themeChanged(_ notification: Notification) {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
|
|
|
+ self?.updateViewColor()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|