Browse Source

【2025】【Markup】逻辑优化

niehaoyu 3 months ago
parent
commit
356b670a28

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotationModel.m

@@ -243,7 +243,7 @@
     return image;
 }
 
--(BOOL)isMultiAnnottation {
+- (BOOL)isMultiAnnottation {
     if (self.annotation) {
         if (self.annotations.count>1) {
             return YES;

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

@@ -199,6 +199,49 @@ class CPDFAnnotationMarkupExtraIvars: NSObject {
         
         return image
     }
+    
+    //MARK: - Update
+    func updateColor(_ color: NSColor?, withPDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        
+        self.color = resultColor
+        if self.markupType() == .highlight {
+            pdfView.updateHighLightAnnotation(self)
+        } else {
+            pdfView.setNeedsDisplay(self)
+        }
+        
+        CPDFAnnotationConfig.standard.setColor(resultColor, toType: self.exchangeToAnnotationType(self.markupType()))
+
+    }
+    
+    func updateOpacity(_ opacity: CGFloat, withPDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        
+        self.opacity = opacity
+        
+        if self.markupType() == .highlight {
+            pdfView.updateHighLightAnnotation(self)
+        } else {
+            pdfView.setNeedsDisplay(self)
+        }
+        
+        CPDFAnnotationConfig.standard.setOpacity(opacity, toType: self.exchangeToAnnotationType(self.markupType()))
+        
+    }
+    
+     
+    
 }
 
 // MARK: - PDFAnnotationMarkup_Override
@@ -356,6 +399,7 @@ class CPDFAnnotationMarkupExtraIvars: NSObject {
         }
         return textString
     }
+    
     override func colorDefaultKey() -> String? {
         let type = self.markupType()
         if type == .highlight {

+ 44 - 14
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFTextAnnotation+PDFListView.swift

@@ -18,15 +18,6 @@ import Foundation
         
     }
     
-    override func isMovable() -> Bool {
-        return true
-    }
-    
-    override func resizeHandleForPoint(_ point: NSPoint, scaleFactor: CGFloat) -> CRectEdges {
-        let offsetNum = CPDFListViewConfig.defaultManager.annotationBorderOffset
-        let rect = NSRectFromCGRect(KMRectInset(NSRectToCGRect(self.bounds), CGFloat(-(offsetNum.floatValue)), CGFloat(-(offsetNum.floatValue))))
-        return CPDFListViewResizeHandleForPointFromRect(point, rect, 8.0 / scaleFactor)
-    }
     
     class func annotationImage(annotationModel: CPDFAnnotationModel) -> NSImage? {
         var imageName = "note_note_bg"
@@ -121,6 +112,50 @@ import Foundation
         return image
     }
     
+    //MARK: - Update
+    func updateColor(_ color: NSColor?, withPDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        
+        self.color = resultColor
+        
+        pdfView.setNeedsDisplay(self)
+         
+        CPDFAnnotationConfig.standard.setColor(resultColor, toType: .anchored)
+     }
+    
+    func updateIconType(_ type: CPDFTextAnnotationIconType, withPDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        
+        self.setIconType(type)
+        pdfView.setNeedsDisplay(self)
+        
+        CPDFAnnotationConfig.setDefaultIntValue(type.rawValue, toKey: CAnchoredNoteIconTypeKey)
+        
+    }
+    
+}
+
+// MARK: - SKNPDFAnnotationNote_SKExtensions
+
+extension CPDFTextAnnotation {
+    
+    override func isMovable() -> Bool {
+        return true
+    }
+    
+    override func resizeHandleForPoint(_ point: NSPoint, scaleFactor: CGFloat) -> CRectEdges {
+        let offsetNum = CPDFListViewConfig.defaultManager.annotationBorderOffset
+        let rect = NSRectFromCGRect(KMRectInset(NSRectToCGRect(self.bounds), CGFloat(-(offsetNum.floatValue)), CGFloat(-(offsetNum.floatValue))))
+        return CPDFListViewResizeHandleForPointFromRect(point, rect, 8.0 / scaleFactor)
+    }
+    
     override func drawSelectionHighlightForView(_ pdfView: CPDFListView, inContext context: CGContext, isHover: Bool) {
         if (NSIsEmptyRect(self.bounds)) {
             return
@@ -148,11 +183,6 @@ import Foundation
         }
         return CPDFTextAnnotation._text_keys
     }
-}
-
-// MARK: - SKNPDFAnnotationNote_SKExtensions
-
-extension CPDFTextAnnotation {
     
     override func toolTipsString() -> String {
         return self.string() ?? ""

+ 0 - 56
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Annotations.swift

@@ -8,62 +8,6 @@
 import Foundation
 
 extension CPDFListView {
-    
-    //MARK: -Color
-    func setAnnotationsColor(_ annotations: [CPDFAnnotation], _ color: NSColor?) {
-        guard let resultColor = color else {
-            return
-        }
-        for annotation in annotations {
-            if annotation is CPDFMarkupAnnotation {
-                (annotation as! CPDFMarkupAnnotation).color = resultColor
-                
-                if (annotation as! CPDFMarkupAnnotation).markupType() == .highlight {
-                    self.updateHighLightAnnotation(annotation)
-                } else {
-                    self.setNeedsDisplay(annotation)
-                }
-                
-                CPDFAnnotationConfig.standard.setColor(resultColor, toType: (annotation as! CPDFMarkupAnnotation).exchangeToAnnotationType((annotation as! CPDFMarkupAnnotation).markupType()))
-            } else if annotation is CPDFTextAnnotation {
-                (annotation as! CPDFTextAnnotation).color = resultColor
-                
-                self.setNeedsDisplay(annotation)
-                
-                CPDFAnnotationConfig.standard.setColor(resultColor, toType: .anchored)
-            }
-        }
-    }
      
-    //MARK: -Opacity
-    func setAnnotationsOpacity(_ annotations: [CPDFAnnotation], _ opacity: CGFloat) {
-        for annotation in annotations {
-            if annotation is CPDFMarkupAnnotation {
-                let markupAnnotation = (annotation as! CPDFMarkupAnnotation)
-                markupAnnotation.opacity = opacity
-                
-                if (annotation as! CPDFMarkupAnnotation).markupType() == .highlight {
-                    self.updateHighLightAnnotation(annotation)
-                } else {
-                    self.setNeedsDisplay(annotation)
-                }
-                
-                CPDFAnnotationConfig.standard.setOpacity(opacity, toType: markupAnnotation.exchangeToAnnotationType(markupAnnotation.markupType()))
-            }
-        }
-    }
-    
-    //MARK: -AnchoredType
-    func setAnchoredAnnotationType(_ annotations: [CPDFAnnotation], _ type: CPDFTextAnnotationIconType) {
-        for annotation in annotations {
-            if annotation is CPDFTextAnnotation {
-                (annotation as! CPDFTextAnnotation).setIconType(type)
-                self.setNeedsDisplay(annotation)
-                
-                CPDFAnnotationConfig.setDefaultIntValue(type.rawValue, toKey: CAnchoredNoteIconTypeKey)
-            }
-        }
-    }
-    
     
 }

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

@@ -16,7 +16,7 @@ class KMHighlightController: NSViewController {
     @IBOutlet var colorSlider: ComponentSlider!
     @IBOutlet var colorOpacitySelect: ComponentSelect!
     
-    private var annotations: [CPDFAnnotation] = []
+    private var annotations: [CPDFMarkupAnnotation] = []
     
     var pdfView: CPDFListView?
     
@@ -167,7 +167,9 @@ class KMHighlightController: NSViewController {
 //MARK: - ComponentCColorDelegate
 extension KMHighlightController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        pdfView?.setAnnotationsColor(annotations, color)
+        for annotation in self.annotations {
+            annotation.updateColor(color, withPDFView: pdfView)
+        }
         
         reloadData()
     }
@@ -177,7 +179,9 @@ extension KMHighlightController: ComponentCColorDelegate {
 extension KMHighlightController: ComponentSliderDelegate {
     func componentSliderDidUpdate(_ view: ComponentSlider) {
         let percent = view.properties.percent
-        pdfView?.setAnnotationsOpacity(annotations, percent)
+        for annotation in self.annotations {
+            annotation.updateOpacity(percent, withPDFView: pdfView)
+        }
         
         reloadData()
     }
@@ -188,8 +192,9 @@ extension KMHighlightController: ComponentSelectDelegate {
     func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
         if let result = text {
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
-            pdfView?.setAnnotationsOpacity(annotations, opacity)
-            
+            for annotation in self.annotations {
+                annotation.updateOpacity(opacity, withPDFView: pdfView)
+            }
             reloadData()
         }
     }

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

@@ -23,7 +23,7 @@ class KMNoteController: NSViewController {
     @IBOutlet var typeItemF: ComponentCSelector!
     @IBOutlet var typeItemG: ComponentCSelector!
     
-    private var annotations: [CPDFAnnotation] = []
+    private var annotations: [CPDFTextAnnotation] = []
     
     var pdfView: CPDFListView?
     
@@ -81,12 +81,14 @@ class KMNoteController: NSViewController {
             return
         }
         
+        guard let firstAnnotation = annotations.first else {
+            return
+        }
+        
         for item in [typeItemA, typeItemB, typeItemC, typeItemD, typeItemE, typeItemF, typeItemG] {
             item!.properties.state = .normal
         }
         
-        let firstAnnotation = annotations.first as! CPDFTextAnnotation
-        
         if annotations.count == 1 {
             colorGroup.currentColor = firstAnnotation.color
             colorGroup.refreshUI()
@@ -184,7 +186,9 @@ class KMNoteController: NSViewController {
         } else if sender == typeItemG {
             anchoredIconType = .newParagraph
         }
-        pdfView?.setAnchoredAnnotationType(annotations, anchoredIconType)
+        for annotation in annotations {
+            annotation.updateIconType(anchoredIconType, withPDFView: pdfView)
+        }
         
         reloadData()
     }
@@ -192,8 +196,9 @@ class KMNoteController: NSViewController {
 
 extension KMNoteController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        pdfView?.setAnnotationsColor(annotations, color)
-        
+        for annotation in self.annotations {
+            annotation.updateColor(color, withPDFView: pdfView)
+        }
         reloadData()
     }
 }

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

@@ -203,7 +203,7 @@ class KMPenController: NSViewController {
 //MARK: - ComponentCColorDelegate
 extension KMPenController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        pdfView?.setAnnotationsColor(annotations, color)
+         
         
         reloadData()
     }
@@ -213,8 +213,7 @@ extension KMPenController: ComponentCColorDelegate {
 extension KMPenController: ComponentSliderDelegate {
     func componentSliderDidUpdate(_ view: ComponentSlider) {
         let percent = view.properties.percent
-        pdfView?.setAnnotationsOpacity(annotations, percent)
-        
+       
         reloadData()
     }
 }
@@ -224,8 +223,7 @@ extension KMPenController: ComponentSelectDelegate {
     func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
         if let result = text {
             let opacity = max(0, min(1, result.stringToCGFloat()/100))
-            pdfView?.setAnnotationsOpacity(annotations, opacity)
-            
+             
             reloadData()
         }
     }

+ 64 - 16
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -3014,22 +3014,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "8EDB3030-91EA-445E-8D64-BFBB1A2CD276"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/KMClass/ImageToPDF/Controller/KMBatchOperateImageToPDFViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "235"
-            endingLineNumber = "235"
-            landmarkName = "updateUILanguage()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
@@ -3739,6 +3723,38 @@
             endingLineNumber = "17"
             landmarkName = "annotationImage(annotationModel:)"
             landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "76A27C4D-5AF5-48C1-BD55-869F07F57A9F - 85f5a68034bf728c"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "static __C.CPDFStampAnnotation.annotationImage(annotationModel: __C.CPDFAnnotationModel) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFStampAnnotation+PDFListView.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "17"
+                  endingLineNumber = "17"
+                  offsetFromSymbolStart = "504">
+               </Location>
+               <Location
+                  uuid = "76A27C4D-5AF5-48C1-BD55-869F07F57A9F - 85f5a68034bf728c"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "static __C.CPDFStampAnnotation.annotationImage(annotationModel: __C.CPDFAnnotationModel) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFStampAnnotation+PDFListView.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "17"
+                  endingLineNumber = "17"
+                  offsetFromSymbolStart = "624">
+               </Location>
+            </Locations>
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy
@@ -3803,6 +3819,38 @@
             endingLineNumber = "209"
             landmarkName = "annotationImage(annotationModel:)"
             landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "A0A71635-2537-47F3-9687-908806EFCEDE - 178ad1848db946bc"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "__C.CPDFLineAnnotation.calculateNormalVector(startPoint: __C.CGPoint, endPoint: __C.CGPoint) -&gt; __C.CGPoint"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLineAnnotation+PDFListView.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "209"
+                  endingLineNumber = "209"
+                  offsetFromSymbolStart = "92">
+               </Location>
+               <Location
+                  uuid = "A0A71635-2537-47F3-9687-908806EFCEDE - e7df717b809c65df"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "static __C.CPDFLineAnnotation.annotationImage(annotationModel: __C.CPDFAnnotationModel) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
+                  moduleName = "PDF Reader Pro"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/kdanmobile/Documents/Git/PDF_Office/PDF%20Office/PDF%20Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLineAnnotation+PDFListView.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "209"
+                  endingLineNumber = "209"
+                  offsetFromSymbolStart = "368">
+               </Location>
+            </Locations>
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy