浏览代码

【PDFView】Form注释设置透明色兼容问题

dinglingui 3 月之前
父节点
当前提交
21fefebf9f

+ 3 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFButtonWidgetAnnotation+PDFListView.swift

@@ -13,21 +13,21 @@ import Foundation
         self.bounds = bounds
         if (controlType == .radioButtonControl) {
             if let annotationModel = CPDFAnnotationModel(annotationType: .radioButton) {
-                self.backgroundColor = annotationModel.backgroundColor()
+                setCurrentBackColor(backgroundColor: annotationModel.backgroundColor())
                 self.backgroundOpacity = annotationModel.backgroundOpacity()
                 self.border = CPDFBorder(style: annotationModel.style(), lineWidth: annotationModel.lineWidth(), dashPattern: annotationModel.dashPattern())
                 self.setFieldName(String(format: "%@%@", "Radio Button_",CPDFAnnotationModel.tagString()!))
             }
         } else if (controlType == .checkBoxControl) {
             if let annotationModel = CPDFAnnotationModel(annotationType: .checkBox) {
-                self.backgroundColor = annotationModel.backgroundColor()
+                setCurrentBackColor(backgroundColor: annotationModel.backgroundColor())
                 self.backgroundOpacity = annotationModel.backgroundOpacity()
                 self.border = CPDFBorder(style: annotationModel.style(), lineWidth: annotationModel.lineWidth(), dashPattern: annotationModel.dashPattern())
                 self.setFieldName(String(format: "%@%@", "Check Box_",CPDFAnnotationModel.tagString()!))
             }
         } else if (controlType == .pushButtonControl) {
             if let annotationModel = CPDFAnnotationModel(annotationType: .actionButton) {
-                self.backgroundColor = annotationModel.backgroundColor()
+                setCurrentBackColor(backgroundColor: annotationModel.backgroundColor())
                 self.backgroundOpacity = annotationModel.backgroundOpacity()
                 self.fontColor = annotationModel.fontColor()
                 self.border = CPDFBorder(style: annotationModel.style(), lineWidth: annotationModel.lineWidth(), dashPattern: annotationModel.dashPattern())

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFChoiceWidgetAnnotation+PDFListView.swift

@@ -13,7 +13,7 @@ import Foundation
         self.bounds = bounds
         if (isListChoice) {
             if let annotationModel = CPDFAnnotationModel(annotationType: .listMenu) {
-                self.backgroundColor = annotationModel.backgroundColor()
+                setCurrentBackColor(backgroundColor: annotationModel.backgroundColor())
                 self.backgroundOpacity = annotationModel.backgroundOpacity()
                 self.border = CPDFBorder(style: annotationModel.style(), lineWidth: annotationModel.lineWidth(), dashPattern: annotationModel.dashPattern())
                 self.fontColor = annotationModel.fontColor()
@@ -23,7 +23,7 @@ import Foundation
             }
         } else {
             if let annotationModel = CPDFAnnotationModel(annotationType: .comboBox) {
-                self.backgroundColor = annotationModel.backgroundColor()
+                setCurrentBackColor(backgroundColor: annotationModel.backgroundColor())
                 self.backgroundOpacity = annotationModel.backgroundOpacity()
                 self.border = CPDFBorder(style: annotationModel.style(), lineWidth: annotationModel.lineWidth(), dashPattern: annotationModel.dashPattern())
                 self.fontColor = annotationModel.fontColor()

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFSignatureWidgetAnnotation+PDFListView.swift

@@ -11,7 +11,7 @@ import Foundation
     convenience init(PDFListViewNoteWith document: CPDFDocument) {
         self.init(document: document)
         if let model = CPDFAnnotationModel(annotationType: .signature) {
-            self.backgroundColor = model.backgroundColor()
+            setCurrentBackColor(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()))

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFTextWidgetAnnotation+PDFListView.swift

@@ -12,7 +12,7 @@ import Foundation
         self.init(document: document)
         if let model = CPDFAnnotationModel(annotationType: .textField) {
             self.font = NSFont(name: model.fontName(), size: model.fontSize())
-            self.backgroundColor = model.backgroundColor()
+            setCurrentBackColor(backgroundColor: model.backgroundColor())
             self.fontColor = model.fontColor()
             self.isMultiline = model.isMultiline()
             self.alignment = model.alignment()

+ 17 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFWidgetAnnotation+PDFListView.swift

@@ -105,4 +105,21 @@ import Foundation
          return self.toolTips?:@"";
      }
      */
+    
+   public func setCurrentBackColor(backgroundColor:NSColor?) {
+        if let calibratedColor = backgroundColor {
+            var red: CGFloat = 0
+            var green: CGFloat = 0
+            var blue: CGFloat = 0
+            var alpha: CGFloat = 0
+            calibratedColor.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: nil)
+            if abs(alpha - 0) < 0.001 {
+                self.removeBackgroundColor()
+            } else {
+                self.backgroundColor = backgroundColor
+            }
+        } else {
+            self.removeBackgroundColor()
+        }
+    }
 }

+ 1 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -4423,8 +4423,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 textWidget.backgroundColor = backgroundColor;
                 textWidget.backgroundOpacity = 1;
             } else {
-                textWidget.backgroundColor = [NSColor clearColor];
-                textWidget.backgroundOpacity = 0;
+                [textWidget removeBackgroundColor];
             }
             
             NSColor* fontColor = [sud colorForKey:CAnnotationTextWidgetFontColorKey];