|
@@ -7,15 +7,31 @@
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
-@objcMembers class KMAnnotationFontWindowController: NSWindowController {
|
|
|
+@objcMembers
|
|
|
+class KMFontModel: NSObject {
|
|
|
+ var fontName: String = ""
|
|
|
+ var fontWeight: String = ""
|
|
|
+ var fontSize: CGFloat = 12.0
|
|
|
+ var fontColor: NSColor = .black
|
|
|
+ var fontAlignment: KMFreeTextAnnotationAlignmentType = .left
|
|
|
+ var annotationType: CAnnotationType
|
|
|
|
|
|
- static let sharedAnnotationFont: KMAnnotationFontWindowController = KMAnnotationFontWindowController()
|
|
|
-
|
|
|
- var _annotations: [CPDFAnnotation]?
|
|
|
+ init(fontName: String, fontWeight: String, fontSize: CGFloat, fontColor: NSColor, fontAlignment: KMFreeTextAnnotationAlignmentType, annotationType: CAnnotationType) {
|
|
|
+ self.fontName = fontName
|
|
|
+ self.fontWeight = fontWeight
|
|
|
+ self.fontSize = fontSize
|
|
|
+ self.fontColor = fontColor
|
|
|
+ self.fontAlignment = fontAlignment
|
|
|
+ self.annotationType = annotationType
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- var annotationAlignCallback: ((Int) -> Void)?
|
|
|
- var annotationCallback: ((CPDFAnnotation) -> Void)?
|
|
|
+@objcMembers class KMAnnotationFontWindowController: NSWindowController {
|
|
|
+
|
|
|
+ static var sharedAnnotationFont: KMAnnotationFontWindowController!
|
|
|
|
|
|
+ var annotationFontModel: KMFontModel?
|
|
|
+ var callback: ((KMFontModel) -> Void)?
|
|
|
@IBOutlet weak var fontLabel: NSTextField!
|
|
|
@IBOutlet weak var fontComboBox: NSComboBox!
|
|
|
@IBOutlet weak var fontWeightLabel: NSTextField!
|
|
@@ -40,35 +56,24 @@ import Cocoa
|
|
|
|
|
|
@IBOutlet var fontAdjacencyLayoutConstraint: NSLayoutConstraint!
|
|
|
@IBOutlet var rowHeightLayoutConstraint: NSLayoutConstraint!
|
|
|
-
|
|
|
- var _annotation: CPDFAnnotation?
|
|
|
|
|
|
// MARK: Init Methods
|
|
|
|
|
|
deinit {
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
-
|
|
|
- if let textAnnotation = self.annotation as? CPDFTextAnnotation {
|
|
|
- let keys: [String] = ["string", "color"]
|
|
|
- for key in keys {
|
|
|
- textAnnotation.removeObserver(self, forKeyPath: key)
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ static func initWindowController(_ fontModel: KMFontModel) -> KMAnnotationFontWindowController {
|
|
|
+ if sharedAnnotationFont != nil {
|
|
|
+ sharedAnnotationFont.annotationFontModel = fontModel
|
|
|
+ return sharedAnnotationFont
|
|
|
} else {
|
|
|
- let keys: [String] = ["string", "color", "interiorColor", "border", "font", "fontColor", "alignment"]
|
|
|
- for key in keys {
|
|
|
- self.annotation.removeObserver(self, forKeyPath: key)
|
|
|
- }
|
|
|
+ let configWC: KMAnnotationFontWindowController = KMAnnotationFontWindowController.init(windowNibName: "KMAnnotationFontWindowController")
|
|
|
+ sharedAnnotationFont = configWC;
|
|
|
+ sharedAnnotationFont.annotationFontModel = fontModel
|
|
|
+ return sharedAnnotationFont
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// convenience init() {
|
|
|
-// let windowNibName = NSNib.Name("KMAnnotationFontWindowController")
|
|
|
-// self.init(windowNibName: "KMAnnotationFontWindowController")
|
|
|
-// }
|
|
|
-//
|
|
|
-// required init?(coder: NSCoder) {
|
|
|
-// super.init(coder: coder)
|
|
|
-// }
|
|
|
|
|
|
override func windowDidLoad() {
|
|
|
super.windowDidLoad()
|
|
@@ -92,77 +97,26 @@ import Cocoa
|
|
|
self.fontAdjacencyStepper.isHidden = true
|
|
|
self.rowHeightStepper.isHidden = true
|
|
|
|
|
|
+ annotationFontReload()
|
|
|
+ reloadData()
|
|
|
+
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(alignmentTypeNotification(_:)), name: NSNotification.Name("KMAnnotationAlignmentTypeNotification"), object: nil)
|
|
|
}
|
|
|
|
|
|
- // MARK: Get、Set
|
|
|
-
|
|
|
- var annotations: [CPDFAnnotation] {
|
|
|
- set {
|
|
|
- _annotations = newValue
|
|
|
-
|
|
|
- annotation = newValue.first!
|
|
|
- self.reloadData()
|
|
|
- }
|
|
|
- get {
|
|
|
- return _annotations!
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var annotation: CPDFAnnotation {
|
|
|
- set {
|
|
|
-// let equal: Bool = ((_annotation?.isEqual(newValue)) != nil)
|
|
|
- let equal = self._annotation?.isEqual(to: newValue) ?? false
|
|
|
- if equal {
|
|
|
- if _annotation is CPDFTextAnnotation {
|
|
|
- let keys = ["string", "color"]
|
|
|
- for key in keys {
|
|
|
- _annotation?.removeObserver(self, forKeyPath: key)
|
|
|
- }
|
|
|
- _annotation = newValue
|
|
|
- for key in keys {
|
|
|
- _annotation?.addObserver(self, forKeyPath: key, options: [.new, .old], context: nil)
|
|
|
- }
|
|
|
- } else {
|
|
|
- let keys = ["string", "color", "interiorColor", "border", "font", "fontColor", "alignment"]
|
|
|
- for key in keys {
|
|
|
- _annotation?.removeObserver(self, forKeyPath: key)
|
|
|
- }
|
|
|
- _annotation = newValue
|
|
|
- for key in keys {
|
|
|
- _annotation?.addObserver(self, forKeyPath: key, options: [.new, .old], context: nil)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- get {
|
|
|
- return _annotation!
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// MARK: private Method
|
|
|
|
|
|
func reloadData() {
|
|
|
if fontWeightPopUpButton != nil {
|
|
|
fontWeightPopUpButton.removeAllItems()
|
|
|
}
|
|
|
- if annotation is CPDFFreeTextAnnotation {
|
|
|
- fontSizePopUpButton.title = "\((annotation as! CPDFFreeTextAnnotation).font.pointSize) pt"
|
|
|
- } else if annotation is CPDFWidgetAnnotation {
|
|
|
- fontSizePopUpButton.title = "\((annotation as! CPDFWidgetAnnotation).font.pointSize) pt"
|
|
|
- }
|
|
|
+ fontSizePopUpButton.title = "\(annotationFontModel?.fontSize ?? 12) pt"
|
|
|
|
|
|
DispatchQueue.global(qos: .default).async {
|
|
|
let fonts = NSFontManager.shared.availableFontFamilies
|
|
|
var fontArr = [NSAttributedString]()
|
|
|
var selectedIndex = 0
|
|
|
- let family = ""
|
|
|
- let style = ""
|
|
|
- if self.annotation is CPDFFreeTextAnnotation {
|
|
|
- (self.annotation as! CPDFFreeTextAnnotation).font.fontDescriptor.object(forKey: .family)
|
|
|
- } else if self.annotation is CPDFWidgetAnnotation {
|
|
|
- (self.annotation as! CPDFWidgetAnnotation).font.fontDescriptor.object(forKey: .face)
|
|
|
- }
|
|
|
+ let family = self.annotationFontModel?.fontName
|
|
|
+ let style = self.annotationFontModel?.fontWeight
|
|
|
|
|
|
for (index, fontName) in fonts.enumerated() {
|
|
|
if let font = NSFont(name: fontName, size: 12.0) {
|
|
@@ -170,14 +124,8 @@ import Cocoa
|
|
|
let string = NSAttributedString(string: fontName, attributes: attributes)
|
|
|
fontArr.append(string)
|
|
|
|
|
|
- if self.annotation is CPDFFreeTextAnnotation {
|
|
|
- if (self.annotation as! CPDFFreeTextAnnotation).font.fontName == font.fontName {
|
|
|
- selectedIndex = index
|
|
|
- }
|
|
|
- } else if self.annotation is CPDFWidgetAnnotation {
|
|
|
- if (self.annotation as! CPDFWidgetAnnotation).font.fontName == font.fontName {
|
|
|
- selectedIndex = index
|
|
|
- }
|
|
|
+ if self.annotationFontModel?.fontName == font.fontName {
|
|
|
+ selectedIndex = index
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -185,39 +133,19 @@ import Cocoa
|
|
|
DispatchQueue.main.async {
|
|
|
self.fontComboBox.addItems(withObjectValues: fontArr)
|
|
|
self.fontComboBox.selectItem(at: selectedIndex)
|
|
|
- let selectedStyleIndex = self.setFontStyle(fontName: family, currentStyle: style)
|
|
|
- self.fontWeightPopUpButton.selectItem(at: selectedStyleIndex)
|
|
|
+ let selectedStyleIndex = self.setFontStyle(fontName: family!, currentStyle: style)
|
|
|
+ self.fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if annotation is CPDFFreeTextAnnotation {
|
|
|
- fontColorWell.color = (annotation as! CPDFFreeTextAnnotation).fontColor ?? UserDefaults.standard.color(forKey: CFreeTextNoteFontColorKey) ?? NSColor.black
|
|
|
- } else if annotation is CPDFWidgetAnnotation {
|
|
|
- fontColorWell.color = (annotation as! CPDFWidgetAnnotation).fontColor ?? UserDefaults.standard.color(forKey: CFreeTextNoteFontColorKey) ?? NSColor.black
|
|
|
- }
|
|
|
-
|
|
|
- if self.annotation is CPDFFreeTextAnnotation {
|
|
|
- switch (self.annotation as! CPDFFreeTextAnnotation).alignment {
|
|
|
- case NSTextAlignment.left:
|
|
|
- alignmentSegmentedControl.selectedSegment = 0
|
|
|
- case NSTextAlignment.center:
|
|
|
- alignmentSegmentedControl.selectedSegment = 1
|
|
|
- case NSTextAlignment.right:
|
|
|
- alignmentSegmentedControl.selectedSegment = 2
|
|
|
- default:
|
|
|
- break
|
|
|
- }
|
|
|
- } else if self.annotation is CPDFTextWidgetAnnotation {
|
|
|
- switch (self.annotation as! CPDFTextWidgetAnnotation).alignment {
|
|
|
- case NSTextAlignment.left:
|
|
|
- alignmentSegmentedControl.selectedSegment = 0
|
|
|
- case NSTextAlignment.center:
|
|
|
- alignmentSegmentedControl.selectedSegment = 1
|
|
|
- case NSTextAlignment.right:
|
|
|
- alignmentSegmentedControl.selectedSegment = 2
|
|
|
- default:
|
|
|
- break
|
|
|
- }
|
|
|
+ fontColorWell.color = annotationFontModel!.fontColor
|
|
|
+ switch annotationFontModel!.fontAlignment {
|
|
|
+ case .left:
|
|
|
+ alignmentSegmentedControl.selectedSegment = 0
|
|
|
+ case .center:
|
|
|
+ alignmentSegmentedControl.selectedSegment = 1
|
|
|
+ case .right:
|
|
|
+ alignmentSegmentedControl.selectedSegment = 2
|
|
|
}
|
|
|
|
|
|
fontAdjacencyLayoutConstraint.constant = fontAdjacencyStepper.isHidden ? -fontAdjacencyStepper.frame.size.height : 16.0
|
|
@@ -228,41 +156,65 @@ import Cocoa
|
|
|
rowHeightLabel.isHidden = rowHeightStepper.isHidden
|
|
|
}
|
|
|
|
|
|
- func setFontStyle(fontName: String, currentStyle style: String?) -> Int {
|
|
|
- var selectIndex = 0
|
|
|
+ func setFontStyle(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 = index
|
|
|
- }
|
|
|
-
|
|
|
- let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [
|
|
|
- NSFontDescriptor.AttributeName.family: fontName,
|
|
|
- NSFontDescriptor.AttributeName.face: styleName
|
|
|
- ])
|
|
|
-
|
|
|
- if let font = NSFont(descriptor: attributeFontDescriptor, size: 12.0) {
|
|
|
- let attributedString = NSAttributedString(string: styleName, attributes: [NSAttributedString.Key.font: font])
|
|
|
+ for i in 0..<fontFamily.count {
|
|
|
+ let array = fontFamily[i]
|
|
|
+ if let styleName = array[1] as? String {
|
|
|
+ if style == styleName {
|
|
|
+ selectIndex = UInt(i)
|
|
|
+ }
|
|
|
+ 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 = attributedString
|
|
|
+ item.attributedTitle = string
|
|
|
+
|
|
|
menu.addItem(item)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if style == nil {
|
|
|
selectIndex = 0
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
fontWeightPopUpButton.menu = menu
|
|
|
-
|
|
|
+
|
|
|
return selectIndex
|
|
|
}
|
|
|
|
|
|
+ func annotationFontReload() {
|
|
|
+ DispatchQueue.global(qos: .default).async { [self] in
|
|
|
+ let fonts = NSFontManager.shared.availableFontFamilies
|
|
|
+ let menu = NSMenu()
|
|
|
+ var selectedIndex = 0
|
|
|
+
|
|
|
+ for (index, fontName) in fonts.enumerated() {
|
|
|
+ if let font = NSFont(name: fontName, size: 12.0) {
|
|
|
+ let attributedString = NSAttributedString(string: fontName, attributes: [NSAttributedString.Key.font: font])
|
|
|
+ let item = NSMenuItem()
|
|
|
+ item.attributedTitle = attributedString
|
|
|
+ menu.addItem(item)
|
|
|
+
|
|
|
+ if annotationFontModel?.fontName == font.fontName {
|
|
|
+ selectedIndex = index
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
+ fontComboBox.menu = menu
|
|
|
+ fontComboBox.selectItem(at: selectedIndex)
|
|
|
+
|
|
|
+ let selectedStyleIndex = setFontStyle(fontName: annotationFontModel!.fontName, currentStyle: annotationFontModel!.fontWeight)
|
|
|
+ fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: Action
|
|
|
|
|
|
@IBAction func fontComboBoxAction(_ sender: NSComboBox) {
|
|
@@ -271,138 +223,76 @@ import Cocoa
|
|
|
let familyString = resultAtt.string
|
|
|
let selectIndex = setFontStyle(fontName: familyString, currentStyle: nil)
|
|
|
let styleString = self.fontWeightPopUpButton.selectedItem?.title
|
|
|
- self.fontWeightPopUpButton.selectItem(at: selectIndex)
|
|
|
+ self.fontWeightPopUpButton.selectItem(at: Int(selectIndex))
|
|
|
|
|
|
- for tAnnotation in self.annotations {
|
|
|
- if tAnnotation is CPDFFreeTextAnnotation {
|
|
|
- if let font = (tAnnotation as! CPDFFreeTextAnnotation).font {
|
|
|
- if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? String {
|
|
|
- let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
|
|
|
- if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat((fontSize as NSString).floatValue)) {
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).font = newFont
|
|
|
- if let annotationCallback = self.annotationCallback {
|
|
|
- annotationCallback(tAnnotation)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else if tAnnotation is CPDFWidgetAnnotation {
|
|
|
- if let font = (tAnnotation as! CPDFWidgetAnnotation).font {
|
|
|
- if let fontSize = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.size) as? String {
|
|
|
- let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
|
|
|
- if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat((fontSize as NSString).floatValue)) {
|
|
|
- (tAnnotation as! CPDFWidgetAnnotation).font = newFont
|
|
|
- if let annotationCallback = self.annotationCallback {
|
|
|
- annotationCallback(tAnnotation)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ let font = NSFont(name: familyString, size: fontSizePopUpButton.stringValue.stringToCGFloat()) ?? NSFont.systemFont(ofSize: 16)
|
|
|
+ if let family = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
|
|
|
+ let style = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let selectedStyleIndex = self.setFontStyle(fontName: family, currentStyle: style)
|
|
|
+ self.fontWeightPopUpButton.selectItem(at: Int(selectedStyleIndex))
|
|
|
}
|
|
|
}
|
|
|
+ annotationFontModel!.fontName = familyString
|
|
|
+ annotationFontModel!.fontWeight = fontWeightPopUpButton.selectedItem!.title
|
|
|
+ if let callback = self.callback {
|
|
|
+ callback(annotationFontModel!)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@IBAction func fontSizeComboBoxAction(_ sender: NSPopUpButton) {
|
|
|
- for tAnnotation in annotations {
|
|
|
- if tAnnotation is CPDFFreeTextAnnotation {
|
|
|
- if var font = (tAnnotation as! CPDFFreeTextAnnotation).font {
|
|
|
- let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
|
|
|
- if let fontSize = Float(fontSizeString) {
|
|
|
- font = NSFont(name: font.fontName, size: CGFloat(fontSize))!
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).font = font
|
|
|
- }
|
|
|
- }
|
|
|
- } else if tAnnotation is CPDFWidgetAnnotation {
|
|
|
- if var font = (tAnnotation as! CPDFWidgetAnnotation).font {
|
|
|
- let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
|
|
|
- if let fontSize = Float(fontSizeString) {
|
|
|
- font = NSFont(name: font.fontName, size: CGFloat(fontSize))!
|
|
|
- (tAnnotation as! CPDFWidgetAnnotation).font = font
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if let annotationCallback = annotationCallback {
|
|
|
- annotationCallback(tAnnotation)
|
|
|
- }
|
|
|
+ let selectItem = self.fontComboBox.indexOfSelectedItem
|
|
|
+ let resultAtt = NSMutableAttributedString(attributedString: self.fontComboBox.itemObjectValue(at: selectItem) as! NSAttributedString)
|
|
|
+ let familyString = resultAtt.string
|
|
|
+ let styleString = self.fontWeightPopUpButton.selectedItem?.title
|
|
|
+ let fontSizeString = fontSizePopUpButton.title.replacingOccurrences(of: " pt", with: "")
|
|
|
+
|
|
|
+ annotationFontModel?.fontSize = fontSizeString.stringToCGFloat()
|
|
|
+ if let callback = self.callback {
|
|
|
+ callback(annotationFontModel!)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @IBAction func fontColorWellAction(_ sender: NSColorWell) {
|
|
|
- for tAnnotation in annotations {
|
|
|
- if tAnnotation is CPDFFreeTextAnnotation {
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).fontColor = sender.color
|
|
|
- } else if tAnnotation is CPDFWidgetAnnotation {
|
|
|
- (tAnnotation as! CPDFWidgetAnnotation).fontColor = sender.color
|
|
|
- }
|
|
|
-
|
|
|
- if let annotationCallback = annotationCallback {
|
|
|
- annotationCallback(tAnnotation)
|
|
|
- }
|
|
|
+ @IBAction func fontStylePopUpButtonAction(_ sender: NSPopUpButton) {
|
|
|
+ guard let styleString = fontWeightPopUpButton.selectedItem?.title else {
|
|
|
+ return
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- @IBAction func alignButtonAction(_ sender: NSSegmentedControl) {
|
|
|
- var alignCount = 0
|
|
|
+ let selectItem = self.fontComboBox.indexOfSelectedItem
|
|
|
+ let resultAtt = NSMutableAttributedString(attributedString: self.fontComboBox.itemObjectValue(at: selectItem) as! NSAttributedString)
|
|
|
+ let familyString = resultAtt.string
|
|
|
|
|
|
- for tAnnotation in self.annotations {
|
|
|
- if tAnnotation is CPDFFreeTextAnnotation {
|
|
|
- switch sender.selectedSegment {
|
|
|
- case 0:
|
|
|
- alignCount = 0
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).alignment = .left
|
|
|
- case 1:
|
|
|
- alignCount = 2
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).alignment = .center
|
|
|
- case 2:
|
|
|
- alignCount = 1
|
|
|
- (tAnnotation as! CPDFFreeTextAnnotation).alignment = .right
|
|
|
- default:
|
|
|
- break
|
|
|
- }
|
|
|
- } else if tAnnotation is CPDFTextWidgetAnnotation {
|
|
|
- switch sender.selectedSegment {
|
|
|
- case 0:
|
|
|
- alignCount = 0
|
|
|
- (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
|
|
|
- case 1:
|
|
|
- alignCount = 2
|
|
|
- (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
|
|
|
- case 2:
|
|
|
- alignCount = 1
|
|
|
- (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
|
|
|
- default:
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
+ annotationFontModel?.fontName = familyString
|
|
|
+ annotationFontModel?.fontWeight = styleString
|
|
|
+ if let callback = self.callback {
|
|
|
+ callback(annotationFontModel!)
|
|
|
}
|
|
|
-
|
|
|
- self.annotationAlignCallback!(alignCount)
|
|
|
}
|
|
|
|
|
|
- // MARK: Notification
|
|
|
-
|
|
|
- // 监听属性变化
|
|
|
- override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
|
|
|
- guard let observedObject = object as AnyObject?, observedObject !== self.annotation else {
|
|
|
- return
|
|
|
+ @IBAction func fontColorWellAction(_ sender: NSColorWell) {
|
|
|
+ annotationFontModel?.fontColor = sender.color
|
|
|
+ if let callback = self.callback {
|
|
|
+ callback(annotationFontModel!)
|
|
|
}
|
|
|
|
|
|
- let newValue = change?[.newKey] ?? NSNull()
|
|
|
- let oldValue = change?[.oldKey] ?? NSNull()
|
|
|
-
|
|
|
- if (newValue as AnyObject).isEqual(oldValue) {
|
|
|
- return
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func alignButtonAction(_ sender: NSSegmentedControl) {
|
|
|
+ switch sender.selectedSegment {
|
|
|
+ case 0:
|
|
|
+ annotationFontModel?.fontAlignment = .left
|
|
|
+ case 1:
|
|
|
+ annotationFontModel?.fontAlignment = .center
|
|
|
+ case 2:
|
|
|
+ annotationFontModel?.fontAlignment = .right
|
|
|
+ default:
|
|
|
+ break
|
|
|
}
|
|
|
-
|
|
|
- if keyPath == "string" {
|
|
|
- if let newValue = newValue as? NSNull {
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- reloadData()
|
|
|
+ if let callback = self.callback {
|
|
|
+ callback(annotationFontModel!)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // MARK: Notification
|
|
|
|
|
|
|
|
|
// 处理对齐类型通知
|