|
@@ -572,55 +572,93 @@ import Cocoa
|
|
|
}
|
|
|
|
|
|
@IBAction func buttonClicked_ChangeFont(_ sender: Any) {
|
|
|
- let fontWindowController = KMAnnotationFontWindowController.sharedAnnotationFont
|
|
|
- let window = fontWindowController!.window
|
|
|
- if fontWindowController != nil && window != nil {
|
|
|
-// fontWindowController!.annotations = annotations
|
|
|
-
|
|
|
-// fontWindowController!.annotationAlignCallback = { [weak self] selectedCount in
|
|
|
-// guard let self = self else { return }
|
|
|
-//
|
|
|
-// for tAnnotation in self.annotations {
|
|
|
-// var annotationString = ""
|
|
|
-//
|
|
|
-//
|
|
|
-// if tAnnotation.buttonWidgetStateString().isEmpty {
|
|
|
-// annotationString = " "
|
|
|
-// } else {
|
|
|
-// let lastString = String(tAnnotation.buttonWidgetStateString().suffix(1))
|
|
|
-//
|
|
|
-// if lastString == " " {
|
|
|
-// annotationString = String(tAnnotation.buttonWidgetStateString().prefix(tAnnotation.buttonWidgetStateString().count - 1))
|
|
|
-// } else {
|
|
|
-// annotationString = "\(tAnnotation.buttonWidgetStateString()) "
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// switch selectedCount {
|
|
|
-// case 0:
|
|
|
-// (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
|
|
|
-// case 2:
|
|
|
-// (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
|
|
|
-// case 1:
|
|
|
-// (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
|
|
|
-// case 3:
|
|
|
-// (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .justified
|
|
|
-// default:
|
|
|
-// break
|
|
|
-// }
|
|
|
-//
|
|
|
-// tAnnotation.setButtonWidgetStateString(annotationString)
|
|
|
-// }
|
|
|
-//
|
|
|
-// self.updateAnnotation()
|
|
|
-// }
|
|
|
+ let selectItem = self.fontPopUpButton.selectedItem
|
|
|
+ guard let selectItem = selectItem else { return }
|
|
|
+
|
|
|
+ let resultAtt = NSMutableAttributedString(attributedString: selectItem.attributedTitle!)
|
|
|
+ let familyString = resultAtt.string
|
|
|
+ let styleString = self.fontStylePopUpButton.selectedItem?.title
|
|
|
+ let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
|
|
|
+ let fontSizeString = fontSizeComboBox.stringValue.replacingOccurrences(of: " pt", with: "")
|
|
|
+ let newFont = NSFont(descriptor: attributeFontDescriptor, size: fontSizeString.stringToCGFloat())
|
|
|
+ var fontAlignment: KMFreeTextAnnotationAlignmentType = .left
|
|
|
+ if annotationModel.alignment() == .left {
|
|
|
+ fontAlignment = .left
|
|
|
+ } else if annotationModel.alignment() == .center {
|
|
|
+ fontAlignment = .center
|
|
|
+ } else if annotationModel.alignment() == .right {
|
|
|
+ fontAlignment = .right
|
|
|
+ }
|
|
|
+ let fontModel = KMFontModel(fontName: familyString, fontWeight: styleString!, fontSize: fontSizeString.stringToCGFloat(), fontColor: colorPickerView.color ?? .black, fontAlignment: fontAlignment, annotationType: annotationModel.annotationType)
|
|
|
+
|
|
|
+ let fontWindowController = KMAnnotationFontWindowController.initWindowController(fontModel)
|
|
|
+ let window = fontWindowController.window
|
|
|
+ fontWindowController.callback = { [weak self] model in
|
|
|
+ self!.colorPickerView.color = model.fontColor
|
|
|
|
|
|
-// fontWindowController.annotationCallback = {
|
|
|
-//
|
|
|
-// }
|
|
|
+ DispatchQueue.global(qos: .default).async { [self]
|
|
|
+ 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: [.font: font])
|
|
|
+ let item = NSMenuItem()
|
|
|
+ item.attributedTitle = attributedString
|
|
|
+ menu.addItem(item)
|
|
|
+
|
|
|
+ if let family = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
|
|
|
+ let style = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
|
|
|
+ if model.fontName == family {
|
|
|
+ selectedIndex = index
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ if self != nil {
|
|
|
+ self!.fontPopUpButton.menu = menu
|
|
|
+ self!.fontPopUpButton.selectItem(at: selectedIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let selectedStyleIndex = self!.setFontStyle(withFontName: model.fontName, currentStyle: model.fontWeight)
|
|
|
+ self!.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
|
|
|
+ self!.fontSizeComboBox.stringValue = String(format: "%.f pt", model.fontSize)
|
|
|
|
|
|
- window!.orderFront(sender)
|
|
|
+ if self!.annotationModel.annotations != nil {
|
|
|
+ let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: model.fontName, .face: model.fontWeight])
|
|
|
+ let annotationFont = NSFont(descriptor: attributeFontDescriptor, size: model.fontSize)
|
|
|
+
|
|
|
+ for tAnnotation in self!.annotations {
|
|
|
+ if tAnnotation is CPDFTextWidgetAnnotation {
|
|
|
+ (tAnnotation as! CPDFTextWidgetAnnotation).font = annotationFont
|
|
|
+ (tAnnotation as! CPDFTextWidgetAnnotation).fontColor = model.fontColor
|
|
|
+ if model.fontAlignment == .left {
|
|
|
+ (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
|
|
|
+ } else if model.fontAlignment == .center {
|
|
|
+ (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
|
|
|
+ } else if model.fontAlignment == .right {
|
|
|
+ (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self!.updateAnnotation()
|
|
|
+ } else {
|
|
|
+ self!.annotationModel.setFontName(model.fontName)
|
|
|
+ self!.annotationModel.setFontSize(model.fontSize)
|
|
|
+ self!.annotationModel.setFontColor(model.fontColor)
|
|
|
+ if model.fontAlignment == .left {
|
|
|
+ self!.annotationModel.setAlignment(.left)
|
|
|
+ } else if model.fontAlignment == .center {
|
|
|
+ self!.annotationModel.setAlignment(.center)
|
|
|
+ } else if model.fontAlignment == .right {
|
|
|
+ self!.annotationModel.setAlignment(.right)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ window?.orderFront(sender)
|
|
|
}
|
|
|
|
|
|
// MARK: NSNotification Action
|