Browse Source

【2025】【Markup】高亮注释逻辑自测

niehaoyu 2 months ago
parent
commit
1c3afb3840

+ 14 - 0
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Controller/Color/ComponentCColorGroup.swift

@@ -135,6 +135,20 @@ public class ComponentCColorGroup: ComponentBaseXibView {
         
         
     }
     }
     
     
+    public func getAllItemColors() -> [NSColor] {
+        var colors: [NSColor] = []
+        for property in colorPropertyArr {
+            if let color = property.color {
+                colors.append(color)
+            }
+        }
+        if let color = customColorItem.properties?.color {
+            colors.append(color)
+        }
+        return colors
+    }
+    
+    
     //MARK: - MouseEvent
     //MARK: - MouseEvent
     public override func mouseEntered(with event: NSEvent) {
     public override func mouseEntered(with event: NSEvent) {
         super.mouseEntered(with: event)
         super.mouseEntered(with: event)

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

@@ -33,7 +33,7 @@ class CPDFAnnotationMarkupExtraIvars: NSObject {
         } else if markupType == .squiggly {
         } else if markupType == .squiggly {
             return .squiggly
             return .squiggly
         }
         }
-        return .highlight
+        return .unkown
     }
     }
     
     
     func lineRects() -> NSPointerArray? {
     func lineRects() -> NSPointerArray? {
@@ -437,13 +437,13 @@ extension CPDFMarkupAnnotation {
 //MARK: - Update
 //MARK: - Update
 extension CPDFMarkupAnnotation {
 extension CPDFMarkupAnnotation {
 
 
-    class func updateMarkupAnnotationDefaultInfo(_ annotationType: CAnnotationType, _ color: NSColor?) {
+    class func updateMarkupAnnotationDefaultColor(_ annotationType: CAnnotationType, _ color: NSColor?) {
         if let resultColor = color {
         if let resultColor = color {
             CPDFAnnotationConfig.standard.setColor(resultColor, toType: annotationType)
             CPDFAnnotationConfig.standard.setColor(resultColor, toType: annotationType)
         }
         }
     }
     }
     
     
-    class func updateMarkupAnnotationDefaultInfo(_ annotationType: CAnnotationType, _ opacity: CGFloat?) {
+    class func updateMarkupAnnotationDefaultOpacity(_ annotationType: CAnnotationType, _ opacity: CGFloat?) {
         if let resultOpacity = opacity {
         if let resultOpacity = opacity {
             CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: annotationType)
             CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: annotationType)
         }
         }

+ 34 - 1
PDF Office/PDF Master/KMClass/KMPDFViewController/KMPDFViewManager.swift

@@ -51,5 +51,38 @@ class KMPDFViewManager: NSObject {
 
 
 //MARK: - Annotation注释
 //MARK: - Annotation注释
 extension KMPDFViewManager {
 extension KMPDFViewManager {
-    
+   class func getValidPDFAnnotationType(_ subToolMode: KMPDFSubToolMode?) -> CAnnotationType {
+        if subToolMode == .Highlight {
+            return .highlight
+        } else if subToolMode == .Underline {
+            return .underline
+        } else if subToolMode == .Waveline {
+            return .squiggly
+        } else if subToolMode == .Strikethrough {
+            return .strikeOut
+        } else if subToolMode == .Text {
+            return .freeText
+        } else if subToolMode == .Note {
+            return .anchored
+        } else if subToolMode == .Pen {
+            return .ink
+        } else if subToolMode == .Eraser {
+            return .eraser
+        } else if subToolMode == .Rectangle {
+            return .square
+        } else if subToolMode == .Circle {
+            return .circle
+        } else if subToolMode == .Arrow {
+            return .arrow
+        } else if subToolMode == .Line {
+            return .line
+        } else if subToolMode == .Measure {
+             
+        } else if subToolMode == .Stamp {
+            
+        } else if subToolMode == .Sign {
+             
+        }
+        return .unkown
+    }
 }
 }

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

@@ -45,6 +45,11 @@ class KMHighlightController: NSViewController {
         return annotations
         return annotations
     }
     }
     
     
+    func getValidAnnotationType() -> CAnnotationType {
+        
+        return .highlight
+    }
+    
     func setupProperty() {
     func setupProperty() {
         
         
         colorLabel.stringValue = KMLocalizedString("Color")
         colorLabel.stringValue = KMLocalizedString("Color")
@@ -195,46 +200,6 @@ class KMHighlightController: NSViewController {
         }
         }
     }
     }
     
     
-    func updateDefaultInfo(_ color: NSColor?, _ opacity: CGFloat?) {
-        if let resultColor = color {
-            if annotations.count == 0 {
-                if viewManager?.subToolMode == .Highlight {
-                    CPDFAnnotationConfig.standard.setColor(resultColor, toType: .highlight)
-                } else if viewManager?.subToolMode == .Underline {
-                    CPDFAnnotationConfig.standard.setColor(resultColor, toType: .underline)
-                } else if viewManager?.subToolMode == .Strikethrough {
-                    CPDFAnnotationConfig.standard.setColor(resultColor, toType: .strikeOut)
-                } else if viewManager?.subToolMode == .Waveline {
-                    CPDFAnnotationConfig.standard.setColor(resultColor, toType: .squiggly)
-                }
-            } else {
-                for annotation in annotations {
-                    CPDFAnnotationConfig.standard.setColor(resultColor, toType: annotation.exchangeToAnnotationType(annotation.markupType()))
-                }
-            }
-            
-            NotificationCenter.default.post(name: toolbarImageColorChangedNotificationName, object: nil)
-        }
-        
-        if let resultOpacity = opacity {
-            if annotations.count == 0 {
-                if viewManager?.subToolMode == .Highlight {
-                    CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: .highlight)
-                } else if viewManager?.subToolMode == .Underline {
-                    CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: .underline)
-                } else if viewManager?.subToolMode == .Strikethrough {
-                    CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: .strikeOut)
-                } else if viewManager?.subToolMode == .Waveline {
-                    CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: .squiggly)
-                }
-            } else {
-                for annotation in annotations {
-                    CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: annotation.exchangeToAnnotationType(annotation.markupType()))
-                }
-            }
-        }
-    }
-    
     //MARK: - Mouse
     //MARK: - Mouse
     override func mouseDown(with event: NSEvent) {
     override func mouseDown(with event: NSEvent) {
         super.mouseDown(with: event)
         super.mouseDown(with: event)
@@ -248,12 +213,20 @@ class KMHighlightController: NSViewController {
 //MARK: - ComponentCColorDelegate
 //MARK: - ComponentCColorDelegate
 extension KMHighlightController: ComponentCColorDelegate {
 extension KMHighlightController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        
         CPDFAnnotation.updateAnnotations(annotations, newColor: color, withPDFView: pdfView)
         CPDFAnnotation.updateAnnotations(annotations, newColor: color, withPDFView: pdfView)
         
         
-        updateDefaultInfo(color, nil)
+        if annotations.count == 0 {
+            CPDFMarkupAnnotation.updateMarkupAnnotationDefaultColor(KMPDFViewManager.getValidPDFAnnotationType(viewManager?.subToolMode), color)
+        } else {
+            for annotation in annotations {
+                CPDFMarkupAnnotation.updateMarkupAnnotationDefaultColor(annotation.exchangeToAnnotationType(annotation.markupType()), color)
+            }
+        }
+        
+        NotificationCenter.default.post(name: toolbarImageColorChangedNotificationName, object: nil)
         
         
         reloadData()
         reloadData()
+        
     }
     }
     
     
     //    func componentCColorDidRightMouseUpWithItems(_ view: NSView) -> [ComponentMenuitemProperty] {
     //    func componentCColorDidRightMouseUpWithItems(_ view: NSView) -> [ComponentMenuitemProperty] {
@@ -273,11 +246,19 @@ extension KMHighlightController: ComponentCColorDelegate {
 extension KMHighlightController: ComponentSliderDelegate {
 extension KMHighlightController: ComponentSliderDelegate {
     func componentSliderDidUpdate(_ view: ComponentSlider) {
     func componentSliderDidUpdate(_ view: ComponentSlider) {
         let opacity = view.properties.percent
         let opacity = view.properties.percent
+        
         CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
         CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
         
         
-        updateDefaultInfo(nil, opacity)
+        if annotations.count == 0 {
+            CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(KMPDFViewManager.getValidPDFAnnotationType(viewManager?.subToolMode), opacity)
+        } else {
+            for annotation in annotations {
+                CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(annotation.exchangeToAnnotationType(annotation.markupType()), opacity)
+            }
+        }
         
         
         reloadData()
         reloadData()
+        
     }
     }
 }
 }
 
 
@@ -291,7 +272,13 @@ extension KMHighlightController: ComponentSelectDelegate {
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
             CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             
             
-            updateDefaultInfo(nil, opacity)
+            if annotations.count == 0 {
+                CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(KMPDFViewManager.getValidPDFAnnotationType(viewManager?.subToolMode), opacity)
+            } else {
+                for annotation in annotations {
+                    CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(annotation.exchangeToAnnotationType(annotation.markupType()), opacity)
+                }
+            }
             
             
             reloadData()
             reloadData()
         }
         }
@@ -302,9 +289,16 @@ extension KMHighlightController: ComponentSelectDelegate {
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
             CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             
             
-            updateDefaultInfo(nil, opacity)
+            if annotations.count == 0 {
+                CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(KMPDFViewManager.getValidPDFAnnotationType(viewManager?.subToolMode), opacity)
+            } else {
+                for annotation in annotations {
+                    CPDFMarkupAnnotation.updateMarkupAnnotationDefaultOpacity(annotation.exchangeToAnnotationType(annotation.markupType()), opacity)
+                }
+            }
             
             
             reloadData()
             reloadData()
+            
         }
         }
     }
     }
 }
 }