|
@@ -360,13 +360,13 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: -10, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
|
|
|
|
|
|
// vc.customBoxWidthLayoutConstraint.constant = self.popWidth ?? sender.frame.width
|
|
|
- vc.downCallback = { [weak self](downEntered: Bool, count: String) -> Void in
|
|
|
+ vc.downCallback = { [unowned self](downEntered: Bool, count: String) -> Void in
|
|
|
if downEntered {
|
|
|
-// if self != nil {
|
|
|
-// if self!.mouseDownAction != nil {
|
|
|
-// self!.mouseDownAction!(sender, count)
|
|
|
-// }
|
|
|
-// }
|
|
|
+ if count == "Reset" {
|
|
|
+ self.resetTextPresuppositionData()
|
|
|
+ } else if count == "Redefine" {
|
|
|
+ self.reDefineTextPresuppositionData()
|
|
|
+ }
|
|
|
createFilePopover.close()
|
|
|
}
|
|
|
}
|
|
@@ -376,7 +376,7 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
extension KMEditPDFTextPropertyViewController: KMSelectPopButtonDelegate {
|
|
|
func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
|
|
|
if obj == textPresuppositionVC {
|
|
|
- let model: NSDictionary = CPDFAnnotationModel.defaultFreeTextPropert().object(at: obj.indexOfSelectedItem) as! NSDictionary
|
|
|
+ let model: NSDictionary = self.fetchFreeTextPropert()//CPDFAnnotationModel.defaultFreeTextPropert().object(at: obj.indexOfSelectedItem) as! NSDictionary
|
|
|
let fontName: String = model["fontName"] as! String
|
|
|
let size: CGFloat = CGFloat(Float(model["fontSize"] as! String)!)
|
|
|
self.updateTextPresupposition(fontName: fontName, size: size)
|
|
@@ -604,64 +604,7 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func updatePreviewImage() {
|
|
|
- let alignment = self.alignment
|
|
|
- let fontSize = Float((self.fontSizeVC?.stringValue.replacingOccurrences(of: "pt", with: ""))!)
|
|
|
- let fontName = self.fontNameVC?.stringValue
|
|
|
- let fontStyle = self.fontStyleVC?.stringValue
|
|
|
- let fontCurrentColor = self.currentColor
|
|
|
-
|
|
|
- let editringareas = self.listView.editingAreas()
|
|
|
- let count = self.listView.editingAreas()?.count
|
|
|
- let editingSelectionString = self.listView.editingSelectionString()
|
|
|
- let editingSelectionAlignment = self.listView.editingSelectionAlignment()
|
|
|
-
|
|
|
-
|
|
|
- var string = NSLocalizedString("example", comment: "")
|
|
|
- let style = NSMutableParagraphStyle()
|
|
|
- style.alignment = alignment
|
|
|
- if count == 1 {
|
|
|
- let areas = editringareas?.first
|
|
|
- if areas is CPDFEditTextArea {
|
|
|
- string = editingSelectionString ?? NSLocalizedString("example", comment: "")
|
|
|
- style.alignment = editingSelectionAlignment
|
|
|
- }
|
|
|
- }
|
|
|
- var attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : fontName,NSFontDescriptor.AttributeName.face: fontStyle])
|
|
|
- var font = NSFont.init(descriptor: attributeFontDescriptor, size: CGFloat(fontSize!))
|
|
|
- var red : CGFloat = 0.0
|
|
|
- var green : CGFloat = 0.0
|
|
|
- var blue : CGFloat = 0.0
|
|
|
- var alpha : CGFloat = 0.0
|
|
|
- var color : NSColor = NSColor.white
|
|
|
-
|
|
|
- fontCurrentColor.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
- color = NSColor(red: red, green: green, blue: blue, alpha: alpha)
|
|
|
-
|
|
|
- if font == nil {
|
|
|
- self.fontName = ""
|
|
|
- self.fontStyle = ""
|
|
|
- attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : self.fontNameVC?.items[0] ?? "Helvetica",NSFontDescriptor.AttributeName.face : self.fontStyleVC?.items[0] ?? "Bold"])
|
|
|
- font = NSFont.init(descriptor: attributeFontDescriptor, size: CGFloat(Float(self.fontSizeVC!.stringValue)!))
|
|
|
- }
|
|
|
-
|
|
|
- let attributes = [NSAttributedString.Key.font:font,NSAttributedString.Key.foregroundColor:color,NSAttributedString.Key.paragraphStyle:style]
|
|
|
-
|
|
|
- let size = string.size(withAttributes:attributes as [NSAttributedString.Key : Any])
|
|
|
- let image = NSImage(size: NSSize(width: self.preImageView.frame.size.width, height: size.height))
|
|
|
- image.lockFocus()
|
|
|
- NSGraphicsContext.current?.imageInterpolation = .high
|
|
|
- NSString(string: string).draw(in: NSRect(x: 0, y: 0, width: self.preImageView.frame.size.width, height: image.size.height), withAttributes: attributes as [NSAttributedString.Key : Any])
|
|
|
- NSGraphicsContext.current?.imageInterpolation = .default
|
|
|
- image.unlockFocus()
|
|
|
-
|
|
|
- self.preImageView.image = image
|
|
|
- }
|
|
|
-
|
|
|
- func supportFontSize() -> [String] {
|
|
|
- return ["8pt", "9pt", "10pt", "11pt", "12pt", "14pt", "16pt", "18pt", "20pt", "22pt", "24pt", "26pt", "28pt", "36pt", "48pt", "72pt"]
|
|
|
- }
|
|
|
-
|
|
|
+ //MARK: 基本属性调整
|
|
|
func updateTextPresupposition(fontName: String, size: CGFloat, needChangeListView: Bool = true) {
|
|
|
let fontNameArray = fontName.components(separatedBy: "-")
|
|
|
var name = ""
|
|
@@ -681,6 +624,115 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
self.updatePreviewImage()
|
|
|
}
|
|
|
|
|
|
+ func resetTextPresuppositionData() {
|
|
|
+ let model: NSDictionary = self.fetchDefaultFreeTextPropert()[textPresuppositionVC!.indexOfSelectedItem]
|
|
|
+ let fontName: String = model["fontName"] as! String
|
|
|
+ let size: CGFloat = CGFloat(Float(model["fontSize"] as! String)!)
|
|
|
+ self.updateTextPresupposition(fontName: fontName, size: size)
|
|
|
+
|
|
|
+ //重置数据 需要把现有值设置到缓存内
|
|
|
+ self.reDefineTextPresuppositionData()
|
|
|
+ }
|
|
|
+
|
|
|
+ func reDefineTextPresuppositionData() {
|
|
|
+ let fontName = self.fontName
|
|
|
+ let fontStyle = self.fontStyle
|
|
|
+ let fontSize = self.fontSize
|
|
|
+ let index = self.textPresuppositionVC?.indexOfSelectedItem
|
|
|
+
|
|
|
+ var fontDic: [String: String] = [:]
|
|
|
+ if fontStyle == "Regular" || fontStyle == "Roman" {
|
|
|
+ fontDic = ["fontName": fontName, "fontSize": fontSize.description]
|
|
|
+ } else {
|
|
|
+ fontDic = ["fontName": "\(fontName)-\(fontStyle)", "fontSize": fontSize.description]
|
|
|
+ }
|
|
|
+
|
|
|
+ let userDefaults = UserDefaults.standard
|
|
|
+ switch index {
|
|
|
+ case 1:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_H1")
|
|
|
+ case 2:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_H2")
|
|
|
+ case 3:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_H3")
|
|
|
+ case 4:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_B1")
|
|
|
+ case 5:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_B2")
|
|
|
+ case 6:
|
|
|
+ userDefaults.set(fontDic, forKey: "CPDFFreeTextDefaultFontObjects_B3")
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ userDefaults.synchronize()
|
|
|
+ }
|
|
|
+
|
|
|
+ func fetchFreeTextPropert() -> NSDictionary {
|
|
|
+ let index = self.textPresuppositionVC?.indexOfSelectedItem ?? 0
|
|
|
+ let model: NSDictionary = self.fetchDefaultFreeTextPropert()[index]
|
|
|
+ var resultModel: NSDictionary = [:]
|
|
|
+ let userDefaults = UserDefaults.standard
|
|
|
+ switch index {
|
|
|
+ case 1:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_H1") ?? [String: Any]()) as! NSDictionary
|
|
|
+ case 2:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_H2") ?? [String: Any]()) as! NSDictionary
|
|
|
+ case 3:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_H3") ?? [String: Any]()) as! NSDictionary
|
|
|
+ case 4:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_B1") ?? [String: Any]()) as! NSDictionary
|
|
|
+ case 5:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_B2") ?? [String: Any]()) as! NSDictionary
|
|
|
+ case 6:
|
|
|
+ resultModel = (userDefaults.object(forKey: "CPDFFreeTextDefaultFontObjects_B3") ?? [String: Any]()) as! NSDictionary
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if resultModel.count == 0 {
|
|
|
+ resultModel = model
|
|
|
+ }
|
|
|
+ return resultModel
|
|
|
+ }
|
|
|
+
|
|
|
+ func fetchDefaultFreeTextPropert() -> [NSDictionary] {
|
|
|
+ return [["fontName": "Helvetica", "fontSize": "12"],
|
|
|
+ ["fontName": "Helvetica-Bold", "fontSize": "36"],
|
|
|
+ ["fontName": "Helvetica-Bold", "fontSize": "24"],
|
|
|
+ ["fontName": "Helvetica-Bold", "fontSize": "18"],
|
|
|
+ ["fontName": "Helvetica", "fontSize": "14"],
|
|
|
+ ["fontName": "Helvetica", "fontSize": "12"],
|
|
|
+ ["fontName": "Helvetica", "fontSize": "11"]]
|
|
|
+ }
|
|
|
+
|
|
|
+// - (void)updateCurrentDefaultFont:(NSMenuItem *)item {
|
|
|
+// if (item.tag == 0) {
|
|
|
+// NSDictionary *newdic = @{@"fontName":self.annotationModel.fontName,@"fontSize":[NSString stringWithFormat:@"%.f",self.annotationModel.fontSize]};
|
|
|
+// switch (self.defaultPopUpButton.indexOfSelectedItem) {
|
|
|
+// case 1:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H1"];
|
|
|
+// break;
|
|
|
+// case 2:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H2"];
|
|
|
+// break;
|
|
|
+// case 3:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H3"];
|
|
|
+// break;
|
|
|
+// case 4:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B1"];
|
|
|
+// break;
|
|
|
+// case 5:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B2"];
|
|
|
+// break;
|
|
|
+// case 6:
|
|
|
+// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B3"];
|
|
|
+// break;
|
|
|
+// default:
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// [self updateFontView];
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
func updateFontNameAndStyle(name: String, style: String, needChangeListView: Bool = true) {
|
|
|
if fontName != name || fontStyle != style {
|
|
|
let styleArray = self.fetchFontStyleWithFontName(fontName: name)
|
|
@@ -716,69 +768,6 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
self.fontSize = size
|
|
|
}
|
|
|
}
|
|
|
-//
|
|
|
-// - (void)updateCurrentDefaultFont:(NSMenuItem *)item {
|
|
|
-// if (item.tag == 0) {
|
|
|
-// NSDictionary *newdic = @{@"fontName":self.annotationModel.fontName,@"fontSize":[NSString stringWithFormat:@"%.f",self.annotationModel.fontSize]};
|
|
|
-// switch (self.defaultPopUpButton.indexOfSelectedItem) {
|
|
|
-// case 1:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H1"];
|
|
|
-// break;
|
|
|
-// case 2:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H2"];
|
|
|
-// break;
|
|
|
-// case 3:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_H3"];
|
|
|
-// break;
|
|
|
-// case 4:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B1"];
|
|
|
-// break;
|
|
|
-// case 5:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B2"];
|
|
|
-// break;
|
|
|
-// case 6:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:newdic forKey:@"CPDFFreeTextDefaultFontObjects_B3"];
|
|
|
-// break;
|
|
|
-// default:
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// [self updateFontView];
|
|
|
-// } else if (item.tag == 1) {
|
|
|
-// switch (self.defaultPopUpButton.indexOfSelectedItem) {
|
|
|
-// case 1:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"36"} forKey:@"CPDFFreeTextDefaultFontObjects_H1"];
|
|
|
-// break;
|
|
|
-// case 2:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"24"} forKey:@"CPDFFreeTextDefaultFontObjects_H2"];
|
|
|
-// break;
|
|
|
-// case 3:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica-Bold",@"fontSize":@"18"} forKey:@"CPDFFreeTextDefaultFontObjects_H3"];
|
|
|
-// break;
|
|
|
-// case 4:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"14"} forKey:@"CPDFFreeTextDefaultFontObjects_B1"];
|
|
|
-// break;
|
|
|
-// case 5:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"12"} forKey:@"CPDFFreeTextDefaultFontObjects_B2"];
|
|
|
-// break;
|
|
|
-// case 6:
|
|
|
-// [[NSUserDefaults standardUserDefaults] setObject:@{@"fontName":@"Helvetica",@"fontSize":@"11"} forKey:@"CPDFFreeTextDefaultFontObjects_B3"];
|
|
|
-// break;
|
|
|
-// default:
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// [self defaultFontPopUpButtonAction:nil];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// - (IBAction)defaultFontPopUpButtonAction:(id)sender {
|
|
|
-// NSDictionary *model = [[CPDFAnnotationModel defaultFreeTextPropert] objectAtIndex:self.defaultPopUpButton.indexOfSelectedItem];
|
|
|
-// self.annotationModel.fontName = model[@"fontName"];
|
|
|
-// self.annotationModel.fontSize = [model[@"fontSize"] floatValue];
|
|
|
-// [self updateFillColorPickerVC];
|
|
|
-// [self updateFontView];
|
|
|
-// [self updateAnnotation];
|
|
|
-// [self createFreeTextProperties];
|
|
|
-// }
|
|
|
|
|
|
func fetchFontStyleWithFontName(fontName: String) -> [String] {
|
|
|
var styleArray: [String] = []
|
|
@@ -816,5 +805,64 @@ extension KMEditPDFTextPropertyViewController {
|
|
|
}
|
|
|
return styleArray
|
|
|
}
|
|
|
+
|
|
|
+ //MARK: 刷新预览图片
|
|
|
+ private func updatePreviewImage() {
|
|
|
+ let alignment = self.alignment
|
|
|
+ let fontSize = Float((self.fontSizeVC?.stringValue.replacingOccurrences(of: "pt", with: ""))!)
|
|
|
+ let fontName = self.fontNameVC?.stringValue
|
|
|
+ let fontStyle = self.fontStyleVC?.stringValue
|
|
|
+ let fontCurrentColor = self.currentColor
|
|
|
+
|
|
|
+ let editringareas = self.listView.editingAreas()
|
|
|
+ let count = self.listView.editingAreas()?.count
|
|
|
+ let editingSelectionString = self.listView.editingSelectionString()
|
|
|
+ let editingSelectionAlignment = self.listView.editingSelectionAlignment()
|
|
|
+
|
|
|
+
|
|
|
+ var string = NSLocalizedString("example", comment: "")
|
|
|
+ let style = NSMutableParagraphStyle()
|
|
|
+ style.alignment = alignment
|
|
|
+ if count == 1 {
|
|
|
+ let areas = editringareas?.first
|
|
|
+ if areas is CPDFEditTextArea {
|
|
|
+ string = editingSelectionString ?? NSLocalizedString("example", comment: "")
|
|
|
+ style.alignment = editingSelectionAlignment
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : fontName,NSFontDescriptor.AttributeName.face: fontStyle])
|
|
|
+ var font = NSFont.init(descriptor: attributeFontDescriptor, size: CGFloat(fontSize!))
|
|
|
+ var red : CGFloat = 0.0
|
|
|
+ var green : CGFloat = 0.0
|
|
|
+ var blue : CGFloat = 0.0
|
|
|
+ var alpha : CGFloat = 0.0
|
|
|
+ var color : NSColor = NSColor.white
|
|
|
+
|
|
|
+ fontCurrentColor.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
+ color = NSColor(red: red, green: green, blue: blue, alpha: alpha)
|
|
|
+
|
|
|
+ if font == nil {
|
|
|
+ self.fontName = ""
|
|
|
+ self.fontStyle = ""
|
|
|
+ attributeFontDescriptor = NSFontDescriptor.init(fontAttributes: [NSFontDescriptor.AttributeName.family : self.fontNameVC?.items[0] ?? "Helvetica",NSFontDescriptor.AttributeName.face : self.fontStyleVC?.items[0] ?? "Bold"])
|
|
|
+ font = NSFont.init(descriptor: attributeFontDescriptor, size: CGFloat(Float(self.fontSizeVC!.stringValue)!))
|
|
|
+ }
|
|
|
+
|
|
|
+ let attributes = [NSAttributedString.Key.font:font,NSAttributedString.Key.foregroundColor:color,NSAttributedString.Key.paragraphStyle:style]
|
|
|
+
|
|
|
+ let size = string.size(withAttributes:attributes as [NSAttributedString.Key : Any])
|
|
|
+ let image = NSImage(size: NSSize(width: self.preImageView.frame.size.width, height: size.height))
|
|
|
+ image.lockFocus()
|
|
|
+ NSGraphicsContext.current?.imageInterpolation = .high
|
|
|
+ NSString(string: string).draw(in: NSRect(x: 0, y: 0, width: self.preImageView.frame.size.width, height: image.size.height), withAttributes: attributes as [NSAttributedString.Key : Any])
|
|
|
+ NSGraphicsContext.current?.imageInterpolation = .default
|
|
|
+ image.unlockFocus()
|
|
|
+
|
|
|
+ self.preImageView.image = image
|
|
|
+ }
|
|
|
+
|
|
|
+ func supportFontSize() -> [String] {
|
|
|
+ return ["8pt", "9pt", "10pt", "11pt", "12pt", "14pt", "16pt", "18pt", "20pt", "22pt", "24pt", "26pt", "28pt", "36pt", "48pt", "72pt"]
|
|
|
+ }
|
|
|
}
|
|
|
|