Parcourir la source

【2025】【Markup】属性面板处理

niehaoyu il y a 2 mois
Parent
commit
be2e054712

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

@@ -702,7 +702,7 @@ extension Date {
         let formatter = DateFormatter()
         formatter.dateFormat = "yyyyMMddHHmmssZZ"
         
-        var dateString = NSMutableString(string: "D:")
+        let dateString = NSMutableString(string: "D:")
         dateString.append(formatter.string(from: self))
         if dateString.hasPrefix("+0000") {
             dateString.replaceCharacters(in: NSMakeRange(dateString.length - 5, 5), with: "Z00'00'")
@@ -845,3 +845,30 @@ func SKFDFLineStyleFromPDFLineStyle(_ lineStyle: CPDFLineStyle) -> String {
 }
 
 
+// MARK: - Update
+extension CPDFAnnotation {
+    class func updateAnnotations(_ annotations: [CPDFAnnotation], newColor color: NSColor?, withPDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.color = resultColor
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
+    
+    class func updateAnnotations(_ annotations: [CPDFAnnotation], newOpacity opacity: CGFloat, withPDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.opacity = opacity
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
+    
+    
+}

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

@@ -437,36 +437,15 @@ extension CPDFMarkupAnnotation {
 //MARK: - Update
 extension CPDFMarkupAnnotation {
 
-    class func update(_ annotations: [CPDFMarkupAnnotation], _ color: NSColor?, PDFView pdfView: CPDFListView?) {
-        guard let resultColor = color else {
-            return
-        }
-        guard let pdfView = pdfView else {
-            return
-        }
-        for annotation in annotations {
-            annotation.color = resultColor
-            
-            if annotation.markupType() == .highlight {
-                pdfView.updateHighLightAnnotation(annotation)
-            } else {
-                pdfView.setNeedsDisplay(annotation)
-            }
+    class func updateMarkupAnnotationDefaultInfo(_ annotationType: CAnnotationType, _ color: NSColor?) {
+        if let resultColor = color {
+            CPDFAnnotationConfig.standard.setColor(resultColor, toType: annotationType)
         }
     }
     
-    class func update(_ annotations: [CPDFMarkupAnnotation], _ opacity: CGFloat, withPDFView pdfView: CPDFListView?) {
-        guard let pdfView = pdfView else {
-            return
-        }
-        for annotation in annotations {
-            annotation.opacity = opacity
-            
-            if annotation.markupType() == .highlight {
-                pdfView.updateHighLightAnnotation(annotation)
-            } else {
-                pdfView.setNeedsDisplay(annotation)
-            }
+    class func updateMarkupAnnotationDefaultInfo(_ annotationType: CAnnotationType, _ opacity: CGFloat?) {
+        if let resultOpacity = opacity {
+            CPDFAnnotationConfig.standard.setOpacity(resultOpacity, toType: annotationType)
         }
     }
     

+ 13 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Measure/CPDFPolylineAnnotation+PDFListView.swift

@@ -114,6 +114,14 @@ import Foundation
 
 //MARK: - Default默认值
 extension CPDFPolylineAnnotation {
+    class func default_measureType() -> CAnnotationType {
+        if let value = CPDFAnnotationConfig.getDefaultIntValue(forKey: CMeasureTypeKey) {
+            let style = CAnnotationType(rawValue: value) ?? .measureLine
+            return style
+        }
+        return .measureLine
+    }
+    
     class func default_measure_Color(annotationType: CAnnotationType) -> NSColor {
         if annotationType == .measureLine {
             if let color = CPDFAnnotationConfig.getDefaultColor(forKey: CMeasureLineFontColorKey) {
@@ -335,6 +343,11 @@ extension CPDFPolylineAnnotation {
 
 //MARK: - Update
 extension CPDFPolylineAnnotation {
+    
+    class func update_default_measureType(annotationType: CAnnotationType) {
+        CPDFAnnotationConfig.setDefaultIntValue(annotationType.rawValue, toKey: CMeasureTypeKey)
+    }
+    
     class func update_default_measure_Color(annotationType: CAnnotationType, _ color: NSColor?) {
         guard let resultColor = color else {
             return

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CStringConstants.h

@@ -230,6 +230,8 @@ extern NSString *CAnnotationRedactFontSizeKey;
 extern NSString *CAnnotationRedactOverlayStringKey;
 
 // Measure
+extern NSString *CMeasureTypeKey;
+
 extern NSString *CMeasureLineFontColorKey;
 extern NSString *CMeasureLineBorderColorKey;
 extern NSString *CMeasureLineOpacityKey;

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CStringConstants.m

@@ -232,6 +232,8 @@ NSString *CAnnotationRedactFontSizeKey      = @"KMPDFAnnotationRedactFontSize";
 NSString *CAnnotationRedactOverlayStringKey = @"CAnnotationRedactOverlayString";
 
 //MARK: - Measure
+NSString *CMeasureTypeKey = @"CMeasureTypeKey";
+
 NSString *CMeasureLineFontColorKey   = @"CMeasureLineFontColorKey";
 NSString *CMeasureLineBorderColorKey = @"CMeasureLineBorderColorKey";
 NSString *CMeasureLineOpacityKey     = @"CMeasureLineOpacityKey";

+ 1 - 1
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -501,7 +501,7 @@ struct KMNMWCFlags {
             } else if subToolMode == .Line {
                 listView.annotationType = .line
             } else if subToolMode == .Measure {
-                listView.annotationType = .measureLine
+                listView.annotationType = CPDFPolylineAnnotation.default_measureType()
             } else if subToolMode == .Stamp {
                 listView.annotationType = .stamp
             } else if subToolMode == .Sign {

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

@@ -57,7 +57,6 @@ class KMRightSideController: NSViewController {
     var edit_cropController: KMCropPropertyController?
     
     //Form
-    
     var form_fieldController: FormsTextFieldController?
     var form_checkBoxController: FormsCheckBoxController?
     var form_radioController: FormsRadioController?

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

@@ -131,7 +131,7 @@ class KMHighlightController: NSViewController {
         }
         
         if annotations.count == 0 {
-           
+            
             var curColor: NSColor = NSColor.clear
             var opacity: CGFloat = 0
             
@@ -151,7 +151,7 @@ class KMHighlightController: NSViewController {
             
             colorGroup.currentColor = curColor
             colorGroup.refreshUI()
-             
+            
             colorSlider.properties.percent = opacity
             colorSlider.reloadData()
             
@@ -196,7 +196,7 @@ class KMHighlightController: NSViewController {
     }
     
     func updateDefaultInfo(_ color: NSColor?, _ opacity: CGFloat?) {
-         if let resultColor = color {
+        if let resultColor = color {
             if annotations.count == 0 {
                 if viewManager?.subToolMode == .Highlight {
                     CPDFAnnotationConfig.standard.setColor(resultColor, toType: .highlight)
@@ -212,8 +212,8 @@ class KMHighlightController: NSViewController {
                     CPDFAnnotationConfig.standard.setColor(resultColor, toType: annotation.exchangeToAnnotationType(annotation.markupType()))
                 }
             }
-             
-             NotificationCenter.default.post(name: toolbarImageColorChangedNotificationName, object: nil)
+            
+            NotificationCenter.default.post(name: toolbarImageColorChangedNotificationName, object: nil)
         }
         
         if let resultOpacity = opacity {
@@ -248,7 +248,8 @@ class KMHighlightController: NSViewController {
 //MARK: - ComponentCColorDelegate
 extension KMHighlightController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        CPDFMarkupAnnotation.update(annotations, color, PDFView: pdfView)
+        
+        CPDFAnnotation.updateAnnotations(annotations, newColor: color, withPDFView: pdfView)
         
         updateDefaultInfo(color, nil)
         
@@ -272,7 +273,7 @@ extension KMHighlightController: ComponentCColorDelegate {
 extension KMHighlightController: ComponentSliderDelegate {
     func componentSliderDidUpdate(_ view: ComponentSlider) {
         let opacity = view.properties.percent
-        CPDFMarkupAnnotation.update(annotations, opacity, withPDFView: pdfView)
+        CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
         
         updateDefaultInfo(nil, opacity)
         
@@ -288,7 +289,7 @@ extension KMHighlightController: ComponentSelectDelegate {
                 result = result.stringByDeleteCharString(textUnit)
             }
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
-            CPDFMarkupAnnotation.update(annotations, opacity, withPDFView: pdfView)
+            CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             
             updateDefaultInfo(nil, opacity)
             
@@ -299,7 +300,7 @@ extension KMHighlightController: ComponentSelectDelegate {
     func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
         if let result = text {
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
-            CPDFMarkupAnnotation.update(annotations, opacity, withPDFView: pdfView)
+            CPDFAnnotation.updateAnnotations(annotations, newOpacity: opacity, withPDFView: pdfView)
             
             updateDefaultInfo(nil, opacity)
             

+ 6 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Measure/KMMeasureController.swift

@@ -83,6 +83,8 @@ class KMMeasureController: NSViewController {
         super.viewDidLoad()
         // Do view setup here.
         
+        annotationType = CPDFPolylineAnnotation.default_measureType()
+        
         setupProperty()
         
         reloadData()
@@ -664,6 +666,10 @@ extension KMMeasureController: ComponentSegmentedDelegate {
             annotationType = .measureSquare
         }
         
+        CPDFPolylineAnnotation.update_default_measureType(annotationType: annotationType)
+        
+        self.pdfView?.annotationType = annotationType
+        
         reloadData()
     }
 }