|
@@ -52,7 +52,7 @@ extension CPDFListView {
|
|
|
}
|
|
|
|
|
|
//MARK: -比较注释中是否存在不同属性的参数
|
|
|
- func isAnnotationsContainMultiType(_ annotations: [CPDFAnnotation], withType type: CPDFAnnotationCompareType) -> Bool {
|
|
|
+ static func isAnnotationsContainMultiType(_ annotations: [CPDFAnnotation], withType type: CPDFAnnotationCompareType) -> Bool {
|
|
|
if annotations.count < 2 {
|
|
|
return false
|
|
|
}
|
|
@@ -67,7 +67,7 @@ extension CPDFListView {
|
|
|
case .color:
|
|
|
for annotation in annotations {
|
|
|
if firstAnnotation != annotation {
|
|
|
- if firstAnnotation.color != annotation.color {
|
|
|
+ if CPDFListView.isTheSameColor(firstAnnotation.color, anotherColor: annotation.color) == false{
|
|
|
multiInfo = true
|
|
|
break
|
|
|
}
|
|
@@ -78,7 +78,7 @@ extension CPDFListView {
|
|
|
case .opacity:
|
|
|
for annotation in annotations {
|
|
|
if firstAnnotation != annotation {
|
|
|
- if firstAnnotation.opacity != annotation.opacity {
|
|
|
+ if abs(firstAnnotation.opacity - annotation.opacity) > 1e-6 {
|
|
|
multiInfo = true
|
|
|
break
|
|
|
}
|
|
@@ -215,5 +215,56 @@ extension CPDFListView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static func isTheSameColor(_ firstColor: NSColor?, anotherColor secColor: NSColor?) -> Bool {
|
|
|
+ let color1:NSColor = firstColor ?? NSColor.clear
|
|
|
+ let color2:NSColor = secColor ?? NSColor.clear
|
|
|
+
|
|
|
+ let component = color1.cgColor.components
|
|
|
+ let component1 = color2.cgColor.components
|
|
|
+
|
|
|
+ guard let comp = component, let comp1 = component1 else {
|
|
|
+ // Handle the case where one or both colors don't have components
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if comp.count != comp1.count {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if comp.count > 0 && comp1.count > 0 {
|
|
|
+ if !compareSize(comp[0], comp1[0]) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if comp.count > 1 && comp1.count > 1 {
|
|
|
+ if !CPDFListView.compareSize(comp[1], comp1[1]) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if comp.count > 2 && comp1.count > 2 {
|
|
|
+ if !CPDFListView.compareSize(comp[2], comp1[2]) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if comp.count > 3 && comp1.count > 3 {
|
|
|
+ if !CPDFListView.compareSize(comp[3], comp1[3]) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ static func compareSize(_ floa1: CGFloat, _ floa2: CGFloat) -> Bool {
|
|
|
+ let t1 = String(format: "%.3f", floa1).stringToCGFloat()
|
|
|
+ let t2 = String(format: "%.3f", floa2).stringToCGFloat()
|
|
|
+
|
|
|
+ if abs(t1 - t2) > 1e-6 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|