|
@@ -86,7 +86,11 @@ let KMColorPickerViewHeight: CGFloat = 64
|
|
|
var subType: KMSelfSignAnnotationFreeTextSubType = .none
|
|
|
var _activeAnnotationType: KMActiveAnnotationType = .highlight
|
|
|
var pdfView: CPDFListView?
|
|
|
- var annotationModel: CPDFAnnotationModel?
|
|
|
+ var annotationModel: CPDFAnnotationModel? {
|
|
|
+ didSet {
|
|
|
+ self.initAnnotationMode()
|
|
|
+ }
|
|
|
+ }
|
|
|
// var annotationCallback: ((CPDFAnnotation) -> Void)?
|
|
|
|
|
|
@IBOutlet private weak var imageBox: NSBox!
|
|
@@ -595,6 +599,9 @@ let KMColorPickerViewHeight: CGFloat = 64
|
|
|
// MARK: Set & Get
|
|
|
|
|
|
var annotations: [CPDFAnnotation] {
|
|
|
+ set {
|
|
|
+ print(annotations)
|
|
|
+ }
|
|
|
get {
|
|
|
return annotationModel?.annotations as? [CPDFAnnotation] ?? []
|
|
|
}
|
|
@@ -612,6 +619,34 @@ let KMColorPickerViewHeight: CGFloat = 64
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ func initAnnotationMode() {
|
|
|
+ if annotationModel?.annotationType == .freeText {
|
|
|
+ let sud = UserDefaults.standard
|
|
|
+ let bounds = NSMakeRect(0, 0, 50, 50)
|
|
|
+ let annotation = CPDFFreeTextAnnotation()
|
|
|
+// defaults.safe_setColor(annotation.color, forKey: CFreeTextNoteColorKey)
|
|
|
+// defaults.safe_setColor((annotation as! CPDFFreeTextAnnotation).fontColor, forKey: CFreeTextNoteFontColorKey)
|
|
|
+// defaults.set((annotation as! CPDFFreeTextAnnotation).alignment.rawValue, forKey: CFreeTextNoteAlignmentKey)
|
|
|
+// defaults.set((annotation as! CPDFFreeTextAnnotation).fontName(), forKey: CFreeTextNoteFontNameKey)
|
|
|
+// defaults.set((annotation as! CPDFFreeTextAnnotation).fontSize(), forKey: CFreeTextNoteFontSizeKey)
|
|
|
+// defaults.set(annotation.lineWidth(), forKey: CFreeTextNoteLineWidthKey)
|
|
|
+// defaults.set(annotation.borderStyle().rawValue, forKey: CFreeTextNoteLineStyleKey)
|
|
|
+// defaults.set(annotation.dashPattern(), forKey: CFreeTextNoteDashPatternKey)
|
|
|
+ annotation.bounds = bounds;
|
|
|
+ annotation.color = sud.color(forKey: CFreeTextNoteColorKey)
|
|
|
+ annotation.fontColor = sud.color(forKey: CFreeTextNoteFontColorKey)
|
|
|
+ annotation.alignment = NSTextAlignment(rawValue: sud.integer(forKey: CFreeTextNoteAlignmentKey))!
|
|
|
+ let font = sud.font(forNameKey: CFreeTextNoteFontNameKey, sizeKey: CFreeTextNoteFontSizeKey)
|
|
|
+ if (font != nil) {
|
|
|
+ annotation.font = font
|
|
|
+ }
|
|
|
+ annotation.setLineWidth(CGFloat(sud.float(forKey: CFreeTextNoteLineWidthKey)))
|
|
|
+ annotation.setDashPattern(sud.array(forKey: CFreeTextNoteDashPatternKey) ?? [])
|
|
|
+ annotation.setBorderStyle(CPDFBorderStyle(rawValue: sud.integer(forKey: CFreeTextNoteLineStyleKey))!)
|
|
|
+// annotationModel?.annotations = [annotation]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func updateannotationMode() {
|
|
|
let defaults = UserDefaults.standard
|
|
|
if annotationType == .freeText {
|
|
@@ -879,13 +914,13 @@ let KMColorPickerViewHeight: CGFloat = 64
|
|
|
}
|
|
|
|
|
|
func openFreeTextStylesViewController() {
|
|
|
- if annotations.count == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
let vc = KMFreeTextStylesViewController()
|
|
|
vc.annotations = annotations
|
|
|
+ vc.annotationModel = self.annotationModel
|
|
|
vc.view.frame = CGRect(x: 0, y: 0, width: 280, height: CGRectGetHeight(self.view.window?.frame ?? CGRect.zero) - 300)
|
|
|
+ vc.didSelect = { [unowned self] data in
|
|
|
+ self.updateAnnotation()
|
|
|
+ }
|
|
|
|
|
|
let createFilePopover = NSPopover()
|
|
|
createFilePopover.contentViewController = vc
|