|
@@ -10,12 +10,12 @@ import Foundation
|
|
|
@objc extension CPDFSignatureWidgetAnnotation {
|
|
|
convenience init(PDFListViewNoteWith document: CPDFDocument) {
|
|
|
self.init(document: document)
|
|
|
- if let model = CPDFAnnotationModel(annotationType: .signature) {
|
|
|
- self.backgroundColor = model.backgroundColor()
|
|
|
- self.backgroundOpacity = model.backgroundOpacity()
|
|
|
- self.border = CPDFBorder(style: model.style(), lineWidth: model.lineWidth(), dashPattern: model.dashPattern())
|
|
|
- self.setFieldName(String(format: "%@%@", "Signature_", CPDFAnnotationModel.tagString()))
|
|
|
- }
|
|
|
+
|
|
|
+ self.backgroundColor = CPDFSignatureWidgetAnnotation.defaultFillColor()
|
|
|
+ self.backgroundOpacity = 1
|
|
|
+ self.border = CPDFBorder(style: .solid, lineWidth: 1, dashPattern: [5])
|
|
|
+ self.setFieldName(self.getValidName(inPage: self.page))
|
|
|
+
|
|
|
}
|
|
|
|
|
|
override func isMovable() -> Bool {
|
|
@@ -25,4 +25,170 @@ import Foundation
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ func getValidName(inPage page: CPDFPage?) -> String {
|
|
|
+ guard let page = page else {
|
|
|
+ return "Signature"
|
|
|
+ }
|
|
|
+ var availableIndex = 1
|
|
|
+ for annotation in page.annotations {
|
|
|
+ if annotation is CPDFSignatureWidgetAnnotation {
|
|
|
+ let name = (annotation as! CPDFSignatureWidgetAnnotation).fieldName() ?? ""
|
|
|
+ if name.hasPrefix("Signature") {
|
|
|
+ if let index = Int(name.dropFirst("Signature".count)), index >= availableIndex {
|
|
|
+ availableIndex = index + 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "Signature\(availableIndex)"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: - Update Default默认值
|
|
|
+extension CPDFSignatureWidgetAnnotation {
|
|
|
+
|
|
|
+ class func defaultTextColor() -> NSColor {
|
|
|
+ return CPDFAnnotationConfig.getDefaultColor(forKey: CAnnotationTextWidgetFontColorKey) ?? NSColor(red: 0, green: 0, blue: 0, alpha: 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func defaultBorderColor() -> NSColor {
|
|
|
+ return CPDFAnnotationConfig.getDefaultColor(forKey: CAnnotationTextWidgetBorderColorKey) ?? NSColor.clear
|
|
|
+ }
|
|
|
+
|
|
|
+ class func defaultFillColor() -> NSColor {
|
|
|
+ return CPDFAnnotationConfig.getDefaultColor(forKey: CAnnotationTextWidgetBackgroundColorKey) ?? NSColor.clear
|
|
|
+ }
|
|
|
+
|
|
|
+ class func defaultFont() -> CPDFFont {
|
|
|
+ return CPDFFont(familyName: CPDFTextWidgetAnnotation.defaultFontName(), fontStyle: CPDFTextWidgetAnnotation.defaultFontStyle())
|
|
|
+ }
|
|
|
+
|
|
|
+ class func defaultFontName() -> String {
|
|
|
+ return CPDFAnnotationConfig.getDefaultStringValue(forKey: SKAnnotationTextWidgetFontNameKey) ?? "Helvetica"
|
|
|
+ }
|
|
|
+
|
|
|
+ class func defaultFontStyle() -> String {
|
|
|
+ return CPDFAnnotationConfig.getDefaultStringValue(forKey: SKAnnotationTextWidgetFontStyleKey) ?? "Regular"
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: - Update
|
|
|
+extension CPDFSignatureWidgetAnnotation {
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], state typeIndex: CPDFWidgetShowState, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for annotation in annotations {
|
|
|
+ if typeIndex == .Visiable {
|
|
|
+ annotation.setShouldPrint(true)
|
|
|
+ annotation.setShouldDisplay(true)
|
|
|
+ } else if typeIndex == .Hidden {
|
|
|
+ annotation.setShouldPrint(false)
|
|
|
+ annotation.setShouldDisplay(false)
|
|
|
+ } else if typeIndex == .ShowNoPrint {
|
|
|
+ annotation.setShouldPrint(false)
|
|
|
+ annotation.setShouldDisplay(true)
|
|
|
+ } else if typeIndex == .HideAndPrint {
|
|
|
+ annotation.setShouldPrint(true)
|
|
|
+ annotation.setShouldDisplay(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], fieldName name: String?, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let resultValue = name else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.setFieldName(resultValue)
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], stringValue name: String?, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let resultValue = name else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.stringValue = resultValue
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], textColor color: NSColor?, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let resultColor = color else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.fontColor = resultColor
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+
|
|
|
+ CPDFAnnotationConfig.setDefaultColor(resultColor, toKey: CAnnotationTextWidgetFontColorKey)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], borderColor color: NSColor?, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let resultColor = color else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.borderColor = resultColor
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+
|
|
|
+ CPDFAnnotationConfig.setDefaultColor(resultColor, toKey: CAnnotationTextWidgetBorderColorKey)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func update(_ annotations: [CPDFTextWidgetAnnotation], fillColor color: NSColor?, PDFView pdfView: CPDFListView?) {
|
|
|
+ guard let resultColor = color else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.backgroundColor = resultColor
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+
|
|
|
+ CPDFAnnotationConfig.setDefaultColor(resultColor, toKey: CAnnotationTextWidgetBackgroundColorKey)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func updateFont(_ annotations: [CPDFTextWidgetAnnotation], _ cfont: CPDFFont, withPDFView pdfView: CPDFListView?) {
|
|
|
+ guard let pdfView = pdfView else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for annotation in annotations {
|
|
|
+ annotation.cFont = cfont
|
|
|
+ }
|
|
|
+ pdfView.setNeedsDisplayMultiAnnotations(annotations)
|
|
|
+
|
|
|
+ CPDFAnnotationConfig.setDefaultStringValue(cfont.familyName, toKey: SKAnnotationTextWidgetFontNameKey)
|
|
|
+
|
|
|
+ if let styleName = cfont.styleName {
|
|
|
+ CPDFAnnotationConfig.setDefaultStringValue(styleName, toKey: SKAnnotationTextWidgetFontStyleKey)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|