瀏覽代碼

【2025】【注释】修改注释比较方法

dinglingui 3 月之前
父節點
當前提交
a1e2a94b36

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLineAnnotation+PDFListView.swift

@@ -245,6 +245,13 @@ import Foundation
         image.unlockFocus()
         return image
     }
+    
+    func isArrowLine() -> Bool {
+        if(self.endLineStyle != .none && self.startLineStyle != .none) {
+            return false
+        }
+        return true
+    }
 }
 
 //MARK: - Update

+ 54 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+AnnotationsCompare.swift

@@ -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
+    }
+    
 }
 

+ 2 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Highlight/KMHighlightController.swift

@@ -148,7 +148,7 @@ class KMHighlightController: NSViewController {
             colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
             colorOpacitySelect.reloadData()
         } else {
-            let multiColor: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .color)
+            let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
             if multiColor == true {
                 colorGroup.currentColor = NSColor.clear
             } else {
@@ -156,7 +156,7 @@ class KMHighlightController: NSViewController {
             }
             colorGroup.refreshUI()
             
-            let multiOpacity: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .opacity)
+            let multiOpacity: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity)
             if multiOpacity {
                 colorSlider.properties.percent = 0
                 colorSlider.reloadData()

+ 2 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Note/KMNoteController.swift

@@ -135,7 +135,7 @@ class KMNoteController: NSViewController {
                 typeItemF.properties.state = .pressed
             }
         } else {
-            var multiColor: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .color)
+            var multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
             if multiColor == true {
                 colorGroup.currentColor = NSColor.clear
             } else {
@@ -145,7 +145,7 @@ class KMNoteController: NSViewController {
             }
             colorGroup.refreshUI()
             
-            var multiType = pdfView.isAnnotationsContainMultiType(annotations, withType: .note_Type)
+            var multiType = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .note_Type)
             if multiType == true {
                 
             } else if let annotation = firstAnnotation {

+ 5 - 5
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Pen/KMPenController.swift

@@ -260,7 +260,7 @@ class KMPenController: NSViewController {
             }
             
             if true {
-                let multiColor: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .color)
+                let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
                  if multiColor == true {
                     colorGroup.currentColor = NSColor.clear
                 } else {
@@ -270,7 +270,7 @@ class KMPenController: NSViewController {
             }
             
             if true {
-                let multiOpacity: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .opacity)
+                let multiOpacity: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity)
                 
                 if multiOpacity {
                     colorSlider.properties.percent = 0
@@ -289,7 +289,7 @@ class KMPenController: NSViewController {
             }
             
             if true {
-                var multiStyle: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
+                var multiStyle: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
                 
                 linedashInfoView.isHidden = true
                 if multiStyle {
@@ -315,7 +315,7 @@ class KMPenController: NSViewController {
             }
             
             if true {
-                var multiLineWidth: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
+                var multiLineWidth: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
                 if multiLineWidth {
                     lineWidthSlider.properties.percent = 0
                     lineWidthSlider.reloadData()
@@ -334,7 +334,7 @@ class KMPenController: NSViewController {
             }
              
             if true {
-                var multiLineDash: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
+                var multiLineDash: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
                 if multiLineDash {
                     lineDashSlider.properties.percent = 0
                     lineDashSlider.reloadData()

+ 5 - 5
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Rectangle/KMRectangleController.swift

@@ -358,7 +358,7 @@ class KMRectangleController: NSViewController {
             }
             
             if true {
-                var multiColor: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .color)
+                var multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
                 if multiColor == true {
                     colorGroup.currentColor = NSColor.clear
                 } else {
@@ -367,7 +367,7 @@ class KMRectangleController: NSViewController {
             }
             
             if true {
-                var multiOpacity: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .opacity)
+                var multiOpacity: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity)
                 if multiOpacity {
                     colorSlider.properties.percent = 0
                     
@@ -384,7 +384,7 @@ class KMRectangleController: NSViewController {
             }
             
             if true {
-                var multiStyle: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
+                var multiStyle: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
                 
                 linedashInfoView.isHidden = true
                 if multiStyle {
@@ -410,7 +410,7 @@ class KMRectangleController: NSViewController {
             }
             
             if true {
-                var multiLineWidth: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
+                var multiLineWidth: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
                 
                 if multiLineWidth {
                     lineWidthSlider.properties.percent = 0
@@ -430,7 +430,7 @@ class KMRectangleController: NSViewController {
             }
             
             if true {
-                var multiLineDash: Bool = pdfView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
+                var multiLineDash: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
                 if multiLineDash {
                     lineDashSlider.properties.percent = 0
                     lineDashSlider.reloadData()