|
@@ -12,7 +12,7 @@ import Cocoa
|
|
|
private var _annotations: [CPDFWidgetAnnotation] = []
|
|
|
private var _formMode: CAnnotationType = .radioButton
|
|
|
var pdfView: CPDFListView?
|
|
|
- var annotationModel: CPDFAnnotationModel?
|
|
|
+ var _annotationModel: CPDFAnnotationModel?
|
|
|
|
|
|
@IBOutlet private var colorLabel: NSTextField!
|
|
|
@IBOutlet private var colorPickerView: KMColorPickerView!
|
|
@@ -108,49 +108,63 @@ import Cocoa
|
|
|
_formMode = newValue
|
|
|
isFromMode = true
|
|
|
|
|
|
- let defaults = UserDefaults.standard
|
|
|
- var annotation: CPDFWidgetAnnotation?
|
|
|
- var backgroundColor: NSColor?
|
|
|
- var fontColor: NSColor?
|
|
|
-
|
|
|
- if formMode == .textField {
|
|
|
- annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!)
|
|
|
- backgroundColor = defaults.color(forKey: SKAnnotationTextWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
- annotation?.backgroundColor = backgroundColor
|
|
|
- fontColor = defaults.color(forKey: SKAnnotationTextWidgetFontColorKey)
|
|
|
- annotation?.fontColor = fontColor
|
|
|
- (annotation as! CPDFTextWidgetAnnotation).alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
|
|
|
- if let font = defaults.font(forNameKey: CAnnotationTextWidgetFontNameKey, sizeKey: CAnnotationTextWidgetFontSizeKey) {
|
|
|
- annotation?.font = font
|
|
|
- }
|
|
|
- if let tAnnotation = annotation as? CPDFTextWidgetAnnotation {
|
|
|
- (annotation as! CPDFTextWidgetAnnotation).isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
|
|
|
- }
|
|
|
- } else if formMode == .listMenu {
|
|
|
- annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: true)
|
|
|
- backgroundColor = defaults.color(forKey: SKAnnotationChoiceListWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
- annotation?.backgroundColor = backgroundColor
|
|
|
- fontColor = defaults.color(forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
- annotation?.fontColor = fontColor
|
|
|
- if let font = defaults.font(forNameKey: SKAnnotationChoiceListWidgetFontNameKey, sizeKey: SKAnnotationChoiceListWidgetFontSizeKey) {
|
|
|
- annotation?.font = font
|
|
|
- }
|
|
|
- } else if formMode == .comboBox {
|
|
|
- annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: false)
|
|
|
- backgroundColor = defaults.color(forKey: SKAnnotationChoiceWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
- annotation?.backgroundColor = backgroundColor
|
|
|
- fontColor = defaults.color(forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
- annotation?.fontColor = fontColor
|
|
|
- if let font = defaults.font(forNameKey: SKAnnotationChoiceWidgetFontNameKey, sizeKey: SKAnnotationChoiceWidgetFontSizeKey) {
|
|
|
- annotation?.font = font
|
|
|
+// let defaults = UserDefaults.standard
|
|
|
+// var annotation: CPDFWidgetAnnotation?
|
|
|
+// var backgroundColor: NSColor?
|
|
|
+// var fontColor: NSColor?
|
|
|
+//
|
|
|
+// if formMode == .textField {
|
|
|
+// annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!)
|
|
|
+// backgroundColor = defaults.color(forKey: SKAnnotationTextWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
+// annotation?.backgroundColor = backgroundColor
|
|
|
+// fontColor = defaults.color(forKey: SKAnnotationTextWidgetFontColorKey)
|
|
|
+// annotation?.fontColor = fontColor
|
|
|
+// (annotation as! CPDFTextWidgetAnnotation).alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
|
|
|
+// if let font = defaults.font(forNameKey: SKAnnotationTextWidgetFontNameKey, sizeKey: SKAnnotationTextWidgetFontSizeKey) {
|
|
|
+// annotation?.font = font
|
|
|
+// }
|
|
|
+// if let tAnnotation = annotation as? CPDFTextWidgetAnnotation {
|
|
|
+// (annotation as! CPDFTextWidgetAnnotation).isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
|
|
|
+// }
|
|
|
+// } else if formMode == .listMenu {
|
|
|
+// annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: true)
|
|
|
+// backgroundColor = defaults.color(forKey: SKAnnotationChoiceListWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
+// annotation?.backgroundColor = backgroundColor
|
|
|
+// fontColor = defaults.color(forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
+// annotation?.fontColor = fontColor
|
|
|
+// if let font = defaults.font(forNameKey: SKAnnotationChoiceListWidgetFontNameKey, sizeKey: SKAnnotationChoiceListWidgetFontSizeKey) {
|
|
|
+// annotation?.font = font
|
|
|
+// }
|
|
|
+// } else if formMode == .comboBox {
|
|
|
+// annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: false)
|
|
|
+// backgroundColor = defaults.color(forKey: SKAnnotationChoiceWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
+// annotation?.backgroundColor = backgroundColor
|
|
|
+// fontColor = defaults.color(forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
+// annotation?.fontColor = fontColor
|
|
|
+// if let font = defaults.font(forNameKey: SKAnnotationChoiceWidgetFontNameKey, sizeKey: SKAnnotationChoiceWidgetFontSizeKey) {
|
|
|
+// annotation?.font = font
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// annotation = CPDFWidgetAnnotation(document: (pdfView?.document)!)
|
|
|
+// }
|
|
|
+//
|
|
|
+// self.annotations = [annotation].compactMap { $0 }
|
|
|
+// self.annotation = annotations.first
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var annotationModel: CPDFAnnotationModel {
|
|
|
+ get {
|
|
|
+ return _annotationModel!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _annotationModel = newValue
|
|
|
+ formMode = _annotationModel?.annotationType ?? .textField
|
|
|
+ if _annotationModel?.annotations != nil {
|
|
|
+ if annotationModel.annotations.count > 0 {
|
|
|
+ annotations = _annotationModel?.annotations as! [CPDFWidgetAnnotation]
|
|
|
}
|
|
|
- } else {
|
|
|
- annotation = CPDFWidgetAnnotation(document: (pdfView?.document)!)
|
|
|
}
|
|
|
-
|
|
|
- self.annotations = [annotation].compactMap { $0 }
|
|
|
- self.annotation = annotations.first
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -206,23 +220,23 @@ import Cocoa
|
|
|
annotationFont = (annotation as! CPDFTextWidgetAnnotation).font
|
|
|
}
|
|
|
} else {
|
|
|
- if let presetValue = annotationModel?.stringValue() {
|
|
|
- annotationModel?.setStringValue(presetValue)
|
|
|
+ if let presetValue = annotationModel.stringValue() {
|
|
|
+ annotationModel.setStringValue(presetValue)
|
|
|
}
|
|
|
var opacity: CGFloat = 1
|
|
|
- let color = annotationModel?.backgroundColor()
|
|
|
+ let color = annotationModel.backgroundColor()
|
|
|
if color != nil {
|
|
|
color!.usingColorSpaceName(.calibratedRGB)?.getRed(nil, green:nil, blue: nil, alpha: &opacity)
|
|
|
}
|
|
|
|
|
|
- let fontColor = annotationModel?.fontColor()
|
|
|
+ let fontColor = annotationModel.fontColor()
|
|
|
fillColorPickerView!.color = color
|
|
|
colorPickerView.color = fontColor
|
|
|
- fontSizeComboBox.stringValue = "\(annotationModel?.fontSize() ?? 12.0) pt"
|
|
|
+ fontSizeComboBox.stringValue = "\(annotationModel.fontSize() ?? 12.0) pt"
|
|
|
|
|
|
- var annotationFont = NSFont.systemFont(ofSize: (annotationModel?.fontSize())!)
|
|
|
- if annotationModel?.fontName() != nil {
|
|
|
- annotationFont = NSFont(name: (annotationModel?.fontName())!, size: (annotationModel?.fontSize())!)!
|
|
|
+ var annotationFont = NSFont.systemFont(ofSize: annotationModel.fontSize())
|
|
|
+ if annotationModel.fontName() != nil {
|
|
|
+ annotationFont = NSFont(name: (annotationModel.fontName())!, size: (annotationModel.fontSize()))!
|
|
|
}
|
|
|
DispatchQueue.global(qos: .default).async { [self] in
|
|
|
let fonts = NSFontManager.shared.availableFontFamilies
|
|
@@ -231,15 +245,15 @@ import Cocoa
|
|
|
let style = annotationFont.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String
|
|
|
let menu = NSMenu()
|
|
|
for (index, fontName) in fonts.enumerated() {
|
|
|
- if let font = NSFont(name: fontName, size: (annotationModel?.fontSize())!) {
|
|
|
+ if let font = NSFont(name: fontName, size: annotationModel.fontSize()) {
|
|
|
let attributes: [NSAttributedString.Key: Any] = [.font: font]
|
|
|
let attributedString = NSAttributedString(string: fontName, attributes: attributes)
|
|
|
let item = NSMenuItem()
|
|
|
item.attributedTitle = attributedString
|
|
|
menu.addItem(item)
|
|
|
|
|
|
- if annotationModel?.fontName() != nil {
|
|
|
- if annotationModel?.fontName() == font.fontName {
|
|
|
+ if annotationModel.fontName() != nil {
|
|
|
+ if annotationModel.fontName() == font.fontName {
|
|
|
selectedIndex = index
|
|
|
}
|
|
|
}
|
|
@@ -263,25 +277,23 @@ import Cocoa
|
|
|
|
|
|
func updateAnnotationMode() {
|
|
|
let userDefaults = UserDefaults.standard
|
|
|
- guard let annotation = self.annotation else { return }
|
|
|
-
|
|
|
if formMode == .textField {
|
|
|
- userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationTextWidgetBackgroundColorKey)
|
|
|
- userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationTextWidgetFontColorKey)
|
|
|
- userDefaults.set((annotation as! CPDFTextWidgetAnnotation).alignment.rawValue, forKey: SKAnnotationTextWidgetAlignmenKey)
|
|
|
- userDefaults.set(annotation.font.fontName, forKey: CAnnotationTextWidgetFontNameKey)
|
|
|
- userDefaults.set(annotation.font.pointSize, forKey: CAnnotationTextWidgetFontSizeKey)
|
|
|
- userDefaults.set((annotation as! CPDFTextWidgetAnnotation).isMultiline, forKey: SKAnnotationTextMultilineKey)
|
|
|
- } else if formMode == .comboBox {
|
|
|
- userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
|
|
|
- userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
- userDefaults.set(annotation.font.fontName, forKey: SKAnnotationChoiceWidgetFontNameKey)
|
|
|
- userDefaults.set(annotation.font.pointSize, forKey: SKAnnotationChoiceWidgetFontSizeKey)
|
|
|
+ userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationTextWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationTextWidgetFontColorKey)
|
|
|
+ userDefaults.set(annotationModel.alignment().rawValue, forKey: SKAnnotationTextWidgetAlignmenKey)
|
|
|
+ userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationTextWidgetFontNameKey)
|
|
|
+ userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationTextWidgetFontSizeKey)
|
|
|
+ userDefaults.set(annotationModel.isMultiline(), forKey: SKAnnotationTextMultilineKey)
|
|
|
} else if formMode == .comboBox {
|
|
|
- userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
|
|
|
- userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
- userDefaults.set(annotation.font.fontName, forKey: SKAnnotationChoiceListWidgetFontNameKey)
|
|
|
- userDefaults.set(annotation.font.pointSize, forKey: SKAnnotationChoiceListWidgetFontSizeKey)
|
|
|
+ userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationChoiceWidgetFontColorKey)
|
|
|
+ userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationChoiceWidgetFontNameKey)
|
|
|
+ userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationChoiceWidgetFontSizeKey)
|
|
|
+ } else if formMode == .listMenu {
|
|
|
+ userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
|
|
|
+ userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationChoiceListWidgetFontColorKey)
|
|
|
+ userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationChoiceListWidgetFontNameKey)
|
|
|
+ userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationChoiceListWidgetFontSizeKey)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -291,9 +303,10 @@ import Cocoa
|
|
|
}
|
|
|
|
|
|
private func updateAnnotation() {
|
|
|
- if annotationModel?.annotation != nil {
|
|
|
+ if annotationModel.annotation != nil {
|
|
|
for tAnnotation in annotations {
|
|
|
pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
|
|
|
+ tAnnotation.updateAppearanceStream()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -379,13 +392,20 @@ import Cocoa
|
|
|
tAnnotation.fontColor = colorPickerView.color
|
|
|
tAnnotation.setButtonWidgetStateString(annotationString)
|
|
|
}
|
|
|
+ updateAnnotationMode()
|
|
|
updateAnnotation()
|
|
|
}
|
|
|
|
|
|
@IBAction func fillColorPickerViewAction(_ sender: Any) {
|
|
|
- for tAnnotation in annotations {
|
|
|
-// tAnnotation.removeAllAppearanceStreams()
|
|
|
- tAnnotation.backgroundColor = fillColorPickerView.color
|
|
|
+ if annotations.count > 0 {
|
|
|
+ for tAnnotation in annotations {
|
|
|
+ // tAnnotation.removeAllAppearanceStreams()
|
|
|
+ tAnnotation.backgroundColor = fillColorPickerView.color
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ annotationModel.setBackgroundColor(fillColorPickerView.color)
|
|
|
+ updateAnnotationMode()
|
|
|
}
|
|
|
updateAnnotation()
|
|
|
}
|