|
@@ -11,7 +11,7 @@ import Cocoa
|
|
|
private var _annotations: [CPDFTextWidgetAnnotation] = []
|
|
|
private var _formMode: CAnnotationType = .radioButton
|
|
|
var pdfView: CPDFListView?
|
|
|
- var annotationModel: CPDFAnnotationModel?
|
|
|
+ var _annotationModel: CPDFAnnotationModel?
|
|
|
|
|
|
@IBOutlet private var textFilledAlignmentLabel: NSTextField! // 对齐方式
|
|
|
@IBOutlet private var textFilledAlignmentPopUpBtn: KMPopUpButton!
|
|
@@ -83,8 +83,9 @@ import Cocoa
|
|
|
}
|
|
|
|
|
|
private func updateAnnotation() {
|
|
|
- if annotationModel?.annotation != nil {
|
|
|
+ if annotationModel.annotation != nil {
|
|
|
for tAnnotation in annotations {
|
|
|
+ tAnnotation.updateAppearanceStream()
|
|
|
pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
|
|
|
}
|
|
|
}
|
|
@@ -100,23 +101,6 @@ import Cocoa
|
|
|
_formMode = newValue
|
|
|
|
|
|
isFromMode = true
|
|
|
- let defaults = UserDefaults.standard
|
|
|
- var annotation: CPDFTextWidgetAnnotation? = nil
|
|
|
- let bounds = NSMakeRect(0, 0, 60, 25)
|
|
|
-
|
|
|
- if formMode == .textField {
|
|
|
- annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: pdfView!.document!)
|
|
|
- annotation?.alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
|
|
|
- annotation?.stringValue = defaults.string(forKey: SKAnnotationTextStringValueKey) ?? ""
|
|
|
-
|
|
|
- annotation?.isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
|
|
|
- }
|
|
|
-
|
|
|
- if let annotation = annotation {
|
|
|
- annotations = [annotation]
|
|
|
- }
|
|
|
-
|
|
|
- self.annotation = annotation
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -129,6 +113,21 @@ import Cocoa
|
|
|
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! [CPDFTextWidgetAnnotation]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
func updateAnnotationMode() {
|
|
|
let sud = UserDefaults.standard
|
|
@@ -158,18 +157,18 @@ import Cocoa
|
|
|
|
|
|
@IBAction func textFilledAlignmentAction(_ sender: NSPopUpButton) {
|
|
|
for tAnnotation in annotations {
|
|
|
- var annotationString = ""
|
|
|
- if tAnnotation.stringValue.isEmpty {
|
|
|
- annotationString = " "
|
|
|
- } else {
|
|
|
- let lastString = String(tAnnotation.stringValue.suffix(1))
|
|
|
-
|
|
|
- if lastString == " " {
|
|
|
- annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
|
|
|
- } else {
|
|
|
- annotationString = "\(tAnnotation.stringValue) "
|
|
|
- }
|
|
|
- }
|
|
|
+// var annotationString = ""
|
|
|
+// if tAnnotation.stringValue.isEmpty {
|
|
|
+// annotationString = " "
|
|
|
+// } else {
|
|
|
+// let lastString = String(tAnnotation.stringValue.suffix(1))
|
|
|
+//
|
|
|
+// if lastString == " " {
|
|
|
+// annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
|
|
|
+// } else {
|
|
|
+// annotationString = "\(tAnnotation.stringValue) "
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
switch sender.indexOfSelectedItem {
|
|
|
case 0:
|
|
@@ -182,7 +181,7 @@ import Cocoa
|
|
|
break
|
|
|
}
|
|
|
|
|
|
- tAnnotation.stringValue = annotationString
|
|
|
+// tAnnotation.stringValue = annotationString
|
|
|
}
|
|
|
|
|
|
updateAnnotation()
|
|
@@ -190,24 +189,24 @@ import Cocoa
|
|
|
|
|
|
@IBAction func textFilledAllowNewLineAction(_ sender: NSButton) {
|
|
|
for tAnnotation in annotations {
|
|
|
- var annotationString = ""
|
|
|
-
|
|
|
- if tAnnotation.stringValue.isEmpty {
|
|
|
- annotationString = " "
|
|
|
- } else {
|
|
|
- let lastString = String(tAnnotation.stringValue.suffix(1))
|
|
|
- if lastString == " " {
|
|
|
- annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
|
|
|
- } else {
|
|
|
- annotationString = "\(tAnnotation.stringValue) "
|
|
|
- }
|
|
|
- }
|
|
|
+// var annotationString = ""
|
|
|
+//
|
|
|
+// if tAnnotation.stringValue.isEmpty {
|
|
|
+// annotationString = " "
|
|
|
+// } else {
|
|
|
+// let lastString = String(tAnnotation.stringValue.suffix(1))
|
|
|
+// if lastString == " " {
|
|
|
+// annotationString = String(tAnnotation.stringValue.prefix(tAnnotation.stringValue.count - 1))
|
|
|
+// } else {
|
|
|
+// annotationString = "\(tAnnotation.stringValue) "
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
if let textWidgetAnnotation = tAnnotation as? CPDFTextWidgetAnnotation {
|
|
|
textWidgetAnnotation.isMultiline = (sender.state == .on)
|
|
|
}
|
|
|
|
|
|
- tAnnotation.stringValue = annotationString
|
|
|
+// tAnnotation.stringValue = annotationString
|
|
|
}
|
|
|
|
|
|
updateAnnotation()
|