Pārlūkot izejas kodu

【2025】【Markup】图形注释多选逻辑补充

niehaoyu 2 mēneši atpakaļ
vecāks
revīzija
26241df402

+ 1 - 5
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Dropdown/ComponentDropdownTool/ComponentDropdownTool.swift

@@ -106,11 +106,7 @@ public class ComponentDropdownTool: ComponentBaseXibView {
         } else {
             titleLabel.isHidden = true
             
-            if properties.showDropdown == true {
-                imageLeftConst.constant = 4
-            } else {
-                imageLeftConst.constant = 0
-            }
+            imageLeftConst.constant = 4
         }
         
     }

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

@@ -886,7 +886,40 @@ func SKFDFLineStyleFromPDFLineStyle(_ lineStyle: CPDFLineStyle) -> String {
     }
     return SKFDFLineStyleNone
 }
- 
+
+//MARK: - Compare
+@objc extension CPDFAnnotation {
+    //比较注释中是否同时存在方形跟圆形注释
+    class func isShapeAnnotationsContainMultiType(_ annotations: [CPDFAnnotation]) -> Bool {
+        if annotations.count < 2 {
+            return false
+        }
+        
+        var validAnnots: [CPDFAnnotation] = []
+        for annotation in annotations {
+            if annotation is CPDFSquareAnnotation {
+                validAnnots.append(annotation)
+            } else if annotation is CPDFCircleAnnotation {
+                validAnnots.append(annotation)
+            }
+        }
+        guard let firstAnnotation = validAnnots.first else {
+            return false
+        }
+        let firstType = firstAnnotation.type
+        
+        for annotation in validAnnots {
+            if firstAnnotation != annotation {
+                if firstType != annotation.type {
+                    return true
+                }
+            }
+        }
+        return false
+    }
+}
+
+//MARK: - Action
 @objc extension CPDFAnnotation {
     //MARK: - 高亮Form表单域
     class func updateHighlightFormFiled(_ pdfView: CPDFListView?, highlightFormFiled enable: Bool) {
@@ -943,6 +976,12 @@ extension CPDFAnnotation {
         }
         for annotation in annotations {
             annotation.opacity = opacity
+            
+            if let circleAnnotation = annotation as? CPDFCircleAnnotation {
+                circleAnnotation.interiorOpacity = opacity
+            } else if let squareAnnotation = annotation as? CPDFSquareAnnotation {
+                squareAnnotation.interiorOpacity = opacity
+            }
         }
         pdfView.setNeedsDisplayMultiAnnotations(annotations)
     }

+ 9 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/KMRightSideController.swift

@@ -562,15 +562,24 @@ class KMRightSideController: NSViewController {
         headerBGView.isHidden = false
         
         if contentViewController is KMHighlightController {
+            //高亮
             if CPDFMarkupAnnotation.isMarkupAnnotationsContainMultiType((contentViewController as! KMHighlightController).getValidAnnotations()) {
                 infoContendTopConst.constant = 0
                 headerBGView.isHidden = true
             }
         } else if contentViewController is KMLineController {
+            //线段
             if CPDFLineAnnotation.isLineAnnotationsContainMultiType((contentViewController as! KMLineController).getValidAnnotations()) {
                 infoContendTopConst.constant = 0
                 headerBGView.isHidden = true
             }
+        } else if contentViewController is KMRectangleController {
+            //图形
+            let annotations: [CPDFAnnotation] = self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
+            if CPDFAnnotation.isShapeAnnotationsContainMultiType(annotations) {
+                infoContendTopConst.constant = 0
+                headerBGView.isHidden = true
+            }
         }
         
     }

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

@@ -218,130 +218,31 @@ class KMRectangleController: NSViewController {
             }
         }
         
+        var _borderColor: NSColor?
+        var _fillColor: NSColor?
+        var _opacity: CGFloat?
         
-        if annotations.count == 0 {
-            if viewManager?.subToolMode == .Rectangle {
-                colorGroup.currentColor = CPDFSquareAnnotation.defaultColor()
-                
-                fillColorGroup.currentColor = CPDFSquareAnnotation.defaultInteriorColor()
-                
-                let opacity = CPDFSquareAnnotation.defaultOpacity()
-                colorSlider.properties.percent = opacity
-                colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-                
-                let border: CPDFBorder = CPDFSquareAnnotation.defaultBorder()
-                
-                dashProperty.state = .normal
-                solidProperty.state = .normal
-                if border.style == .dashed {
-                    dashProperty.state = .pressed
-                } else if border.style == .solid {
-                    solidProperty.state = .pressed
-                }
-                
-                let percent = border.lineWidth/18
-                lineWidthSlider.properties.percent = percent
-                lineWidthSlider.reloadData()
-                
-                lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
-                lineWidthSelect.reloadData()
-                
-                linedashInfoView.isHidden = true
-                if border.style == .dashed {
-                    linedashInfoView.isHidden = false
-                    
-                    var dash = 1.0
-                    for dashPattern in border.dashPattern {
-                        if let value = dashPattern as? CGFloat {
-                            dash = value
-                            break
-                        }
-                    }
-                    let percent: CGFloat = CGFloat(dash)/18
-                    lineDashSlider.properties.percent = percent
-                    lineDashSlider.reloadData()
-                    
-                    lineDashSelect.properties.text = String(format: "%.0f%@", CGFloat(dash), " pt")
-                    lineDashSelect.reloadData()
-                }
-                
-            } else if viewManager?.subToolMode == .Circle {
-                colorGroup.currentColor = CPDFCircleAnnotation.defaultColor()
-                
-                fillColorGroup.currentColor = CPDFCircleAnnotation.defaultInteriorColor()
-                
-                let opacity = CPDFCircleAnnotation.defaultOpacity()
-                colorSlider.properties.percent = opacity
-                colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-                
-                let border: CPDFBorder = CPDFCircleAnnotation.defaultBorder()
-                
-                dashProperty.state = .normal
-                solidProperty.state = .normal
-                if border.style == .dashed {
-                    dashProperty.state = .pressed
-                } else if border.style == .solid {
-                    solidProperty.state = .pressed
-                }
-                
-                let percent = border.lineWidth/18
-                lineWidthSlider.properties.percent = percent
-                lineWidthSlider.reloadData()
-                
-                lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
-                lineWidthSelect.reloadData()
-                
-                linedashInfoView.isHidden = true
-                if border.style == .dashed {
-                    linedashInfoView.isHidden = false
-                    
-                    var dash = 1.0
-                    for dashPattern in border.dashPattern {
-                        if let value = dashPattern as? CGFloat {
-                            dash = value
-                            break
-                        }
-                    }
-                    let percent: CGFloat = CGFloat(dash)/18
-                    lineDashSlider.properties.percent = percent
-                    lineDashSlider.reloadData()
-                    
-                    lineDashSelect.properties.text = String(format: "%.0f%@", CGFloat(dash), " pt")
-                    lineDashSelect.reloadData()
-                }
-            }
-        } else if annotations.count == 1, let annotation = firstAnnotation {
-            colorGroup.currentColor = annotation.color
+        var _borderStyle: CPDFBorderStyle?
+        var _borderWidth: CGFloat?
+        var _borderDashWidth: CGFloat?
+        
+        if let annotation = firstAnnotation {
+            _borderColor = annotation.color
             
-            if firstAnnotation is CPDFCircleAnnotation {
-                fillColorGroup.currentColor = (firstAnnotation as! CPDFCircleAnnotation).interiorColor
-            } else if firstAnnotation is CPDFSquareAnnotation {
-                fillColorGroup.currentColor = (firstAnnotation as! CPDFSquareAnnotation).interiorColor
+            if annotation is CPDFCircleAnnotation {
+                _fillColor = (annotation as! CPDFCircleAnnotation).interiorColor
+            } else if annotation is CPDFSquareAnnotation {
+                _fillColor = (annotation as! CPDFSquareAnnotation).interiorColor
             }
             
-            let opacity = annotation.opacity
-            colorSlider.properties.percent = opacity
-            
-            colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
+            _opacity = annotation.opacity
             
             let border: CPDFBorder = annotation.border ?? CPDFBorder()
-            dashProperty.state = .normal
-            solidProperty.state = .normal
-            if border.style == .dashed {
-                dashProperty.state = .pressed
-            } else if border.style == .solid {
-                solidProperty.state = .pressed
-            }
-            
-            let percent = border.lineWidth/18
-            lineWidthSlider.properties.percent = percent
             
-            lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
+            _borderStyle = border.style
+            _borderWidth = border.lineWidth
             
-            linedashInfoView.isHidden = true
             if border.style == .dashed {
-                linedashInfoView.isHidden = false
-                
                 var dash = 1.0
                 for dashPattern in border.dashPattern {
                     if let value = dashPattern as? CGFloat {
@@ -349,135 +250,127 @@ class KMRectangleController: NSViewController {
                         break
                     }
                 }
-                let percent: CGFloat = CGFloat(dash)/18
-                lineDashSlider.properties.percent = percent
-                
-                lineDashSelect.properties.text = String(format: "%.0f%@", CGFloat(dash), " pt")
-                
-            }
-        } else {
-            guard let annotation = firstAnnotation else {
-                return
+                _borderDashWidth = dash
             }
             
-            if true {
-                let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
-                if multiColor == true {
-                    colorGroup.currentColor = nil
-                } else {
-                    colorGroup.currentColor = annotation.color
+            if annotations.count > 1 {
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color) == true {
+                    _borderColor = nil
                 }
-            }
-            
-            if true {
-                let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .interiorColor)
-                if multiColor == true {
-                    fillColorGroup.currentColor = nil
-                } else {
-                    if firstAnnotation is CPDFSquareAnnotation {
-                        fillColorGroup.currentColor = (firstAnnotation as! CPDFSquareAnnotation).interiorColor
-                    } else if firstAnnotation is CPDFCircleAnnotation {
-                        fillColorGroup.currentColor = (firstAnnotation as! CPDFCircleAnnotation).interiorColor
-                    }
+                
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .interiorColor) == true {
+                    _fillColor = nil
                 }
-            }
-            
-            if true {
-                let multiOpacity: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity)
-                if multiOpacity {
-                    colorSlider.properties.percent = 0
-                    
-                    colorOpacitySelect.resetText("-")
-                } else {
-                    let opacity = annotation.opacity
-                    
-                    colorSlider.properties.percent = opacity
-                    colorSlider.reloadData()
-                    
-                    colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-                    colorOpacitySelect.reloadData()
+                
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity) {
+                    _opacity = nil
                 }
-            }
-            
-            if true {
-                let multiStyle: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
                 
-                linedashInfoView.isHidden = true
-                if multiStyle {
-                    dashProperty.state = .normal
-                    solidProperty.state = .normal
-                    
-                    lineTypeSelector.reloadData()
-                } else {
-                    let style = annotation.border?.style
-                    dashProperty.state = .normal
-                    solidProperty.state = .normal
-                    if style == .dashed {
-                        dashProperty.state = .pressed
-                    } else if style == .solid {
-                        solidProperty.state = .pressed
-                    }
-                    lineTypeSelector.reloadData()
-                    
-                    if style == .dashed {
-                        linedashInfoView.isHidden = false
-                    }
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .border_Style) {
+                    _borderStyle = nil
+                }
+                
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .line_Width) {
+                    _borderWidth = nil
                 }
-            }
-            
-            if true {
-                let multiLineWidth: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
                 
-                if multiLineWidth {
-                    lineWidthSlider.properties.percent = 0
-                    lineWidthSlider.reloadData()
-                    
-                    lineWidthSelect.resetText("-")
-                } else {
-                    let border: CPDFBorder = annotation.border ?? CPDFBorder()
-                    
-                    let percent = border.lineWidth/18
-                    lineWidthSlider.properties.percent = percent
-                    lineWidthSlider.reloadData()
-                    
-                    lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
-                    lineWidthSelect.reloadData()
+                if CPDFListView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern) {
+                    _borderDashWidth = nil
                 }
             }
             
-            if true {
-                let multiLineDash: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
-                if multiLineDash {
-                    lineDashSlider.properties.percent = 0
-                    lineDashSlider.reloadData()
-                    
-                    lineDashSelect.resetText("-")
-                } else {
-                    var dashA = 1.0
-                    for dashPattern in annotation.border?.dashPattern ?? [] {
+        } else {
+            if viewManager?.subToolMode == .Rectangle {
+                _borderColor = CPDFSquareAnnotation.defaultColor()
+                _fillColor = CPDFSquareAnnotation.defaultInteriorColor()
+                _opacity = CPDFSquareAnnotation.defaultOpacity()
+                
+                let border: CPDFBorder = CPDFSquareAnnotation.defaultBorder()
+                
+                _borderStyle = border.style
+                _borderWidth = border.lineWidth
+                
+                if border.style == .dashed {
+                    var dash = 1.0
+                    for dashPattern in border.dashPattern {
                         if let value = dashPattern as? CGFloat {
-                            dashA = value
+                            dash = value
                             break
                         }
                     }
-                    
-                    let percent = dashA / 18
-                    lineDashSlider.properties.percent = percent
-                    lineDashSlider.reloadData()
-                    
-                    lineDashSelect.properties.text = String(format: "%.0f%@", dashA, " pt")
-                    lineDashSelect.reloadData()
+                    _borderDashWidth = dash
+                }
+            } else if viewManager?.subToolMode == .Circle {
+                _borderColor = CPDFCircleAnnotation.defaultColor()
+                
+                _fillColor = CPDFCircleAnnotation.defaultInteriorColor()
+                _opacity = CPDFCircleAnnotation.defaultOpacity()
+                
+                let border: CPDFBorder = CPDFCircleAnnotation.defaultBorder()
+                
+                _borderStyle = border.style
+                _borderWidth = border.lineWidth
+                if border.style == .dashed {
+                    var dash = 1.0
+                    for dashPattern in border.dashPattern {
+                        if let value = dashPattern as? CGFloat {
+                            dash = value
+                            break
+                        }
+                    }
+                    _borderDashWidth = dash
                 }
             }
         }
         
+        colorGroup.currentColor = _borderColor
         colorGroup.refreshUI()
+        
+        fillColorGroup.currentColor = _fillColor
         fillColorGroup.refreshUI()
+        
+        if let value = _opacity {
+            colorSlider.properties.percent = value
+            colorOpacitySelect.properties.text = String(format: "%.0f%@", value*100, "%")
+        } else {
+            colorSlider.properties.percent = 0
+            colorOpacitySelect.properties.text = "-"
+        }
         colorSlider.reloadData()
         colorOpacitySelect.reloadData()
+        
+        linedashInfoView.isHidden = true
+        dashProperty.state = .normal
+        solidProperty.state = .normal
+        if let value = _borderStyle {
+            if value == .dashed {
+                linedashInfoView.isHidden = false
+                dashProperty.state = .pressed
+            } else if value == .solid {
+                solidProperty.state = .pressed
+            }
+        }
         lineTypeSelector.reloadData()
+        
+        if let value = _borderWidth {
+            let percent = value/18
+            lineWidthSlider.properties.percent = percent
+            lineWidthSelect.properties.text = String(format: "%.0f%@", value, " pt")
+        } else {
+            lineWidthSlider.properties.percent = 0
+            lineWidthSelect.properties.text = "-"
+        }
         lineWidthSlider.reloadData()
         lineWidthSelect.reloadData()
+        
+        if let value = _borderDashWidth {
+            let percent = value / 18
+            lineDashSlider.properties.percent = percent
+            lineDashSelect.properties.text = String(format: "%.0f%@", value, " pt")
+        } else {
+            lineDashSlider.properties.percent = 0
+            lineDashSelect.properties.text = "-"
+        }
         lineDashSlider.reloadData()
         lineDashSelect.reloadData()
         
@@ -679,7 +572,7 @@ extension KMRectangleController: ComponentCSelectorGroupDelegate {
             }
             
         } else if item.properties == dashProperty {
-            CPDFAnnotation.updateAnnotations(annotations, newBorderStyle: .solid, withPDFView: pdfView)
+            CPDFAnnotation.updateAnnotations(annotations, newBorderStyle: .dashed, withPDFView: pdfView)
             
             if circleAnnotations.count > 0  || viewManager?.subToolMode == .Circle {
                 CPDFCircleAnnotation.updateDefault_Style(.dashed)