Browse Source

【注释】填写与签名类型切换逻辑、属性面板展开获取初始状态

wanjun 1 year ago
parent
commit
c192b22f66

+ 6 - 5
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFStampAnnotation+PDFListView.swift

@@ -45,9 +45,10 @@ import Foundation
             context?.setStrokeColor(paintColor.cgColor)
             context?.setFillColor(paintColor.cgColor)
             context?.strokePath()
-        } else if (annotationModel.stampAnnotationType() == .signDot) {
+        } else if (annotationModel.stampAnnotationType() == .signCircle) {
             context?.setStrokeColor(red: 0, green: 0, blue: 0, alpha: 1)
-            context?.addArc(center: CGPoint(x: CGRectGetMidX(bounds)+1, y: CGRectGetMidY(bounds)-1), radius: min(CGRectGetWidth(bounds)/2.0 - 1 , CGRectGetHeight(bounds)/2.0 - 1), startAngle: 0, endAngle: Double.pi * 2, clockwise: true)
+            context?.addArc(center: CGPoint(x: CGRectGetMidX(bounds)+1, y: CGRectGetMidY(bounds)-1), radius: min(CGRectGetWidth(bounds)/2.0 - lineWidth , CGRectGetHeight(bounds)/2.0 - 1), startAngle: 0, endAngle: Double.pi * 2, clockwise: true)
+            context?.setLineWidth(lineWidth)
             context?.setStrokeColor(paintColor.cgColor)
             context?.setFillColor(paintColor.cgColor)
             context?.strokePath()
@@ -55,9 +56,9 @@ import Foundation
             let path = NSBezierPath(roundedRect: CGRectMake(CGRectGetMinX(bounds), CGRectGetMidY(bounds) - lineWidth, CGRectGetWidth(bounds), lineWidth), xRadius: lineWidth/2.0, yRadius: lineWidth/2.0)
             paintColor.set()
             path.fill()
-        } else if (annotationModel.stampAnnotationType() == .signCircle) {
-            let r = 4.0
-            let path = NSBezierPath(roundedRect: CGRectInset(bounds, lineWidth, lineWidth), xRadius: r, yRadius: r)
+        } else if (annotationModel.stampAnnotationType() == .signDot) {
+            let r = 16.0
+            let path = NSBezierPath(roundedRect: CGRectInset(bounds, annotationModel.noteWidth(), annotationModel.noteWidth()), xRadius: r, yRadius: r)
             path.lineWidth = lineWidth
             paintColor.set()
             path.fill()

+ 36 - 20
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMAnnotationSelfSignViewController.swift

@@ -41,9 +41,7 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
     @IBOutlet var lineWidthView: NSView!
     @IBOutlet var lineWidthViewTopConstraint: NSLayoutConstraint!
     
-    @IBOutlet var widthView: NSView!
-    
-    var annotation: KMSelfSignAnnotation?
+    private var _annotation: KMSelfSignAnnotation?
 
     // MARK: Life Cycle
     
@@ -55,6 +53,8 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
     override func loadView() {
         super.loadView()
         
+        selfSignType = annotationModel!.annotationType as CAnnotationType
+        
         colorLabel.stringValue = NSLocalizedString("Color", comment: "")
         colorLabel.textColor = KMAppearance.Layout.h0Color()
         opacityLabel.stringValue = NSLocalizedString("Opacity", comment: "")
@@ -70,23 +70,22 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
         imageBox.fillColor = KMAppearance.Layout.l1Color()
 
         var color: NSColor?
-        if let annotation = annotation {
-            selfSignType = annotation.annotationType
+        if annotationModel?.annotation != nil {
+            selfSignType = annotation!.annotationType
             typeSelected(selfSignType)
 
-            color = annotation.lineColor
-            lineWidthSlider.floatValue = Float(annotation.lineWidth())
+            color = annotation!.lineColor
+            lineWidthSlider.floatValue = Float(annotation!.lineWidth())
             lineWidthComboBox.stringValue = String(format: "%.1f pt", lineWidthSlider.floatValue)
         } else {
             bottomView.isHidden = true
-            color = KMSelfSignAnnotation.fetchStoredColor(selfSignType)
-            lineWidthSlider.floatValue = Float(KMSelfSignAnnotation.fetchStoredLineWidth(selfSignType))
+            color = annotationModel?.color()
+            lineWidthSlider.floatValue = Float((annotationModel?.lineWidth())!)
             lineWidthComboBox.stringValue = String(format: "%.1f pt", lineWidthSlider.floatValue)
         }
 
         colorPickView.color = color
-        var opacity: CGFloat = 1.0
-        color?.usingColorSpaceName(.calibratedRGB)?.getRed(nil, green: nil, blue: nil, alpha: &opacity)
+        var opacity: CGFloat = (annotationModel?.opacity())!
         opacityComboBox.stringValue = "\(Int(opacity * 100))%"
         opacitySlider.floatValue = Float(opacity)
         imageView.image = annotationModel?.annotationImage
@@ -136,6 +135,12 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
     
     // MARK: Set & Get
     
+    var annotation: CSelfSignAnnotation? {
+        get {
+            return ((annotationModel?.annotation)! as! CSelfSignAnnotation)
+        }
+    }
+    
     var annotations: [CSelfSignAnnotation] {
         get {
             return annotationModel?.annotations as! [CSelfSignAnnotation]
@@ -277,16 +282,24 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
     @IBAction func buttonClicked_TypeAwitch(_ sender: NSButton) {
         let tag = sender.tag
         
-        for tAnnotation in annotations {
+        if annotationModel?.annotation != nil {
             if tag == 1 {
-                tAnnotation.annotationType = .signature
+                selfSignType = .signTure
             } else if tag == 2 {
-                tAnnotation.annotationType = .signFalse
-            } else {
-                tAnnotation.annotationType = CAnnotationType(rawValue: tag) ?? .unkown
+                selfSignType = .signFalse
+            } else if tag == 3 {
+                selfSignType = .signCircle
+            } else if tag == 4 {
+                selfSignType = .signLine
+            } else if tag == 5 {
+                selfSignType = .signDot
             }
         }
-
+        
+        let lineWidth = annotationModel?.lineWidth()
+        let textColor = annotationModel?.color()
+        let opcity = annotationModel?.opacity()
+        
         var originalFrame = annotation!.bounds
         if annotation!.annotationType == .signFalse ||
             annotation!.annotationType == .signTure ||
@@ -299,11 +312,14 @@ typealias KMAnnotationSelfSignViewControllerCallBack = (CAnnotationType) -> Void
             annotation!.annotationType = .signCircle
         }
 
-        pdfview?.needsDisplay = true
-        selfSignType = annotation!.annotationType
-        imageView.image = annotationModel?.annotationImage
+        annotationModel?.setStampAnnotationType(selfSignType)
         typeSelected(selfSignType)
+        
+        annotationModel?.setLineWidth(CGFloat(lineWidth!))
+        annotationModel?.setOpacity(opcity!)
+        annotationModel?.setColor(textColor)
 
+        updateAnnotation()
         if let callBack = callBack {
             callBack(selfSignType)
         }

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMAnnotationSelfSignViewController.xib

@@ -28,7 +28,6 @@
                 <outlet property="selfSignTypeLabel" destination="x0t-6o-bFa" id="cq9-jU-KVL"/>
                 <outlet property="trueTypeButton" destination="Vu3-og-LXM" id="3UG-oW-Uuz"/>
                 <outlet property="view" destination="j0h-GU-ZZz" id="vbc-yH-dWN"/>
-                <outlet property="widthView" destination="4d3-Eg-lwC" id="e5B-Y6-3A6"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>