Просмотр исходного кода

【2025】【Form】Textfield注释处理

niehaoyu 2 месяцев назад
Родитель
Сommit
94260b54ff

+ 117 - 32
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFTextWidgetAnnotation+PDFListView.swift

@@ -72,7 +72,7 @@ import Foundation
         }
         return CPDFTextWidgetAnnotation._textW_keys
     }
-
+    
     override func isConvertibleAnnotation() -> Bool {
         return true
     }
@@ -82,7 +82,7 @@ import Foundation
 extension CPDFTextWidgetAnnotation {
     
     class func defaultIsMultiLine() -> Bool {
-         return CPDFAnnotationConfig.getDefaultBoolValue(forKey: CAnnotationTextWidgetMultilineKey)
+        return CPDFAnnotationConfig.getDefaultBoolValue(forKey: CAnnotationTextWidgetMultilineKey)
     }
     
     class func defaultTextColor() -> NSColor {
@@ -121,37 +121,35 @@ extension CPDFTextWidgetAnnotation {
         return .left
     }
     
-     
+    
 }
- 
+
 //MARK: - Update
 extension CPDFTextWidgetAnnotation {
- //    if annotation.shouldDisplay() {
-//        if annotation.shouldPrint() {
-//            formFieldIndex = 0
-//        } else {
-//            formFieldIndex = 2
-//        }
-//    } else {
-//        if annotation.shouldPrint() {
-//            formFieldIndex = 3
-//        } else {
-//            formFieldIndex = 1
-//        }
-//    }
-//    defaultValueText = annotation.stringValue
-//    isMultiLine = annotation.isMultiline
-//    
-//    textColor = annotation.color
-//    borderColor = annotation.borderColor
-//    fillColor = annotation.backgroundColor
-//    
-//    fontName = annotation.cFont.familyName
-//    fontStyle = annotation.cFont.styleName
-//    fontSize = annotation.fontSize
-//    alignment = annotation.alignment
-    
     
+    class func update(_ annotations: [CPDFTextWidgetAnnotation], state typeIndex: CPDFWidgetShowState, PDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        
+        for annotation in annotations {
+            if typeIndex == .Visiable {
+                annotation.setShouldPrint(true)
+                annotation.setShouldDisplay(true)
+            } else if typeIndex == .Hidden {
+                annotation.setShouldPrint(false)
+                annotation.setShouldDisplay(false)
+            } else if typeIndex == .ShowNoPrint {
+                annotation.setShouldPrint(false)
+                annotation.setShouldDisplay(true)
+            } else if typeIndex == .HideAndPrint {
+                annotation.setShouldPrint(true)
+                annotation.setShouldDisplay(false)
+            }
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+        
+    }
     
     class func update(_ annotations: [CPDFTextWidgetAnnotation], fieldName name: String?, PDFView pdfView: CPDFListView?) {
         guard let resultValue = name else {
@@ -162,7 +160,20 @@ extension CPDFTextWidgetAnnotation {
         }
         for annotation in annotations {
             annotation.setFieldName(resultValue)
-         }
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
+    
+    class func update(_ annotations: [CPDFTextWidgetAnnotation], stringValue name: String?, PDFView pdfView: CPDFListView?) {
+        guard let resultValue = name else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.setString(resultValue)
+        }
         pdfView.setNeedsDisplayMultiAnnotations(annotations)
     }
     
@@ -174,12 +185,86 @@ extension CPDFTextWidgetAnnotation {
             return
         }
         for annotation in annotations {
-            annotation.color = resultColor
-         }
+            annotation.fontColor = resultColor
+        }
         pdfView.setNeedsDisplayMultiAnnotations(annotations)
     }
     
+    class func update(_ annotations: [CPDFTextWidgetAnnotation], borderColor color: NSColor?, PDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.borderColor = resultColor
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
     
+    class func update(_ annotations: [CPDFTextWidgetAnnotation], fillColor color: NSColor?, PDFView pdfView: CPDFListView?) {
+        guard let resultColor = color else {
+            return
+        }
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.backgroundColor = resultColor
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
+    
+    class func update(_ annotations: [CPDFTextWidgetAnnotation], isMultiLine multi: Bool, PDFView pdfView: CPDFListView?) {
+        
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.isMultiline = multi
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+    }
+    
+    class func updateFontAlignment(_ annotations: [CPDFTextWidgetAnnotation], _ alignment: NSTextAlignment, withPDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.alignment = alignment
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+        
+        CPDFAnnotationConfig.setDefaultIntValue(alignment.rawValue, toKey: CFreeTextNoteAlignmentKey)
+        
+    }
     
+    class func updateFont(_ annotations: [CPDFTextWidgetAnnotation], _ cfont: CPDFFont, withPDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.cFont = cfont
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+        
+        CPDFAnnotationConfig.setDefaultStringValue(cfont.familyName, toKey: CFreeTextNoteFontNameKey)
+        
+        if let styleName = cfont.styleName {
+            CPDFAnnotationConfig.setDefaultStringValue(styleName, toKey: CFreeTextNoteFontStyleKey)
+        }
+    }
     
+    class func updateFontSize(_ annotations: [CPDFTextWidgetAnnotation], _ size: CGFloat, withPDFView pdfView: CPDFListView?) {
+        guard let pdfView = pdfView else {
+            return
+        }
+        for annotation in annotations {
+            annotation.fontSize = size
+        }
+        pdfView.setNeedsDisplayMultiAnnotations(annotations)
+        
+        CPDFAnnotationConfig.setDefaultFloatValue(size, toKey: CFreeTextNoteFontSizeKey)
+    }
 }

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFWidgetAnnotation+PDFListView.swift

@@ -7,6 +7,13 @@
 
 import Foundation
 
+enum CPDFWidgetShowState: Int, CaseIterable {
+    case Visiable = 0
+    case Hidden
+    case ShowNoPrint
+    case HideAndPrint
+}
+
 @objc extension CPDFWidgetAnnotation {
     override func resizeHandleForPoint(_ point: NSPoint, scaleFactor: CGFloat) -> CRectEdges {
         let rect = NSRectFromCGRect(KMRectInset(NSRectToCGRect(self.bounds),0, 0))

+ 134 - 85
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/Forms/Forms_TextField/FormsTextFieldController.swift

@@ -27,7 +27,7 @@ class FormsTextFieldController: NSViewController {
     @IBOutlet var defaultValueLabel: NSTextField!
     @IBOutlet var defaultValueTextarea: ComponentTextarea!
     @IBOutlet var defaultValueCheckbox: ComponentCheckBox!
-     
+    
     
     @IBOutlet var appearanceBox: NSBox!
     //Color
@@ -36,7 +36,7 @@ class FormsTextFieldController: NSViewController {
     @IBOutlet var fontColorGroup: ComponentCColorGroup!
     @IBOutlet var borderColorGroup: ComponentCColorGroup!
     @IBOutlet var fillColorGroup: ComponentCColorGroup!
- 
+    
     //Font
     @IBOutlet var fontBGView: NSView!
     @IBOutlet var fontLabel: NSTextField!
@@ -44,12 +44,12 @@ class FormsTextFieldController: NSViewController {
     @IBOutlet var fontStyleSelect: ComponentSelect!
     @IBOutlet var fontSizeSelect: ComponentSelect!
     @IBOutlet var fontAlignmentGroup: ComponentCSelectorGroup!
-     
+    
     
     private var tabIndex: Int = 0
     private var generalTabProperty: ComponentTabsProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: KMLocalizedString("General"))
     private var appearanceTabProperty: ComponentTabsProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: KMLocalizedString("Appearance"))
-     
+    
     private var familyNames = CPDFFont.familyNames
     private let fontAlign_leftItem: ComponentCSelectorProperty = ComponentCSelectorProperty.init(size: .m, state: .normal, iconImage: NSImage(named: "fontAlign_left"), identifier: "fontAlign_left")
     private let fontAlign_centerItem: ComponentCSelectorProperty = ComponentCSelectorProperty.init(size: .m, state: .normal, iconImage: NSImage(named: "fontAlign_center"), identifier: "fontAlign_center")
@@ -72,7 +72,7 @@ class FormsTextFieldController: NSViewController {
     func setupProperty() {
         typeTabs.updateItemProperty([generalTabProperty, appearanceTabProperty])
         typeTabs.delegate = self
-         
+        
         //MARK: -General
         nameInput.properties = ComponentInputProperty(size: .s, text: "")
         nameInput.delegate = self
@@ -149,7 +149,7 @@ class FormsTextFieldController: NSViewController {
     func reloadUI() {
         self.view.wantsLayer = true
         self.view.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
-         
+        
         generalBox.fillColor = NSColor.clear
         
         appearanceBox.fillColor = NSColor.clear
@@ -166,7 +166,7 @@ class FormsTextFieldController: NSViewController {
         formFieldLabel.stringValue = KMLocalizedString("Form Field")
         formFieldLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
         formFieldLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-         
+        
         defaultValueLabel.stringValue = KMLocalizedString("Default Value")
         defaultValueLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
         defaultValueLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
@@ -261,7 +261,7 @@ class FormsTextFieldController: NSViewController {
         print("1")
         
         var name: String?
-        var formFieldIndex: Int = 0
+        var formFieldIndex: Int = -1
         var defaultValueText: String?
         var isMultiLine: Bool = false
         
@@ -294,7 +294,7 @@ class FormsTextFieldController: NSViewController {
             defaultValueText = annotation.stringValue
             isMultiLine = annotation.isMultiline
             
-            textColor = annotation.color
+            textColor = annotation.fontColor
             borderColor = annotation.borderColor
             fillColor = annotation.backgroundColor
             
@@ -304,15 +304,64 @@ class FormsTextFieldController: NSViewController {
             alignment = annotation.alignment
             
         }
+        
+        if let value = name {
+            nameInput.properties.text = value
+        }
+        if formFieldIndex >= 0 {
+            formFieldSelect.selectItemAtIndex(formFieldIndex)
+        }
+        if let value = defaultValueText {
+            defaultValueTextarea.properties.text = value
+        }
+        defaultValueCheckbox.properties.checkboxType = isMultiLine ? .selected : .normal
+        
+        if let value = textColor {
+            fontColorGroup.currentColor = value
+        } else {
+            fontColorGroup.currentColor = nil
+        }
+        
+        if let value = borderColor {
+            borderColorGroup.currentColor = value
+        } else {
+            borderColorGroup.currentColor = nil
+        }
+        
+        if let value = fillColor {
+            fillColorGroup.currentColor = value
+        } else {
+            fillColorGroup.currentColor = nil
+        }
          
+        fontNameSelect.properties.text = fontName ?? "-"
+        fontStyleSelect.properties.text = fontStyle ?? "-"
+        if let value = fontSize {
+            fontSizeSelect.properties.text = String(format: "%.0f", value)
+        } else {
+            fontSizeSelect.properties.text = "-"
+        }
+      
         
+        nameInput.reloadData()
+        formFieldSelect.reloadData()
+        defaultValueTextarea.reloadData()
+        defaultValueCheckbox.reloadData()
         
+        fontColorGroup.refreshUI()
+        borderColorGroup.refreshUI()
+        fillColorGroup.refreshUI()
+        
+        fontNameSelect.reloadData()
+        fontStyleSelect.reloadData()
+        fontSizeSelect.reloadData()
+    
     }
     
     @objc func multilineCheckboxClicked(_ box: ComponentCheckBox) {
         
     }
-     
+    
     
     //MARK: - Mouse
     override func mouseDown(with event: NSEvent) {
@@ -349,13 +398,13 @@ extension FormsTextFieldController: ComponentInputDelegate {
 //MARK: - ComponentCColorDelegate
 extension FormsTextFieldController: ComponentCColorDelegate {
     func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-//        if view == fontColorGroup {
-//            CPDFFreeTextAnnotation.updateFontColor(annotations, color, withPDFView: pdfView)
-//        } else if view == borderColorGroup {
-//            CPDFFreeTextAnnotation.updateBorderColor(annotations, color, withPDFView: pdfView)
-//        } else if view == fillColorGroup {
-//            CPDFFreeTextAnnotation.updateColor(annotations, color, withPDFView: pdfView)
-//        }
+        //        if view == fontColorGroup {
+        //            CPDFFreeTextAnnotation.updateFontColor(annotations, color, withPDFView: pdfView)
+        //        } else if view == borderColorGroup {
+        //            CPDFFreeTextAnnotation.updateBorderColor(annotations, color, withPDFView: pdfView)
+        //        } else if view == fillColorGroup {
+        //            CPDFFreeTextAnnotation.updateColor(annotations, color, withPDFView: pdfView)
+        //        }
         reloadData()
     }
 }
@@ -364,26 +413,26 @@ extension FormsTextFieldController: ComponentCColorDelegate {
 extension FormsTextFieldController: ComponentSelectDelegate {
     func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
         if let result = text {
-//            if view == opacitySelect {
-//                let opacity = max(0, min(1, result.stringToCGFloat()/100))
-//                CPDFFreeTextAnnotation.updateOpacity(annotations, opacity, withPDFView: pdfView)
-//            } else if view == lineWidthSelect {
-//                var value = result.stringToCGFloat()
-//                if value > 18 {
-//                    value = 18
-//                } else if value < 1 {
-//                    value = 1
-//                }
-//                CPDFFreeTextAnnotation.updateLineWidth(annotations, value, withPDFView: pdfView)
-//            } else if view == lineDashSelect {
-//                var value = result.stringToCGFloat()
-//                if value > 18 {
-//                    value = 18
-//                } else if value < 1 {
-//                    value = 1
-//                }
-//                CPDFFreeTextAnnotation.updateDashPattern(annotations, value, withPDFView: pdfView)
-//            }
+            //            if view == opacitySelect {
+            //                let opacity = max(0, min(1, result.stringToCGFloat()/100))
+            //                CPDFFreeTextAnnotation.updateOpacity(annotations, opacity, withPDFView: pdfView)
+            //            } else if view == lineWidthSelect {
+            //                var value = result.stringToCGFloat()
+            //                if value > 18 {
+            //                    value = 18
+            //                } else if value < 1 {
+            //                    value = 1
+            //                }
+            //                CPDFFreeTextAnnotation.updateLineWidth(annotations, value, withPDFView: pdfView)
+            //            } else if view == lineDashSelect {
+            //                var value = result.stringToCGFloat()
+            //                if value > 18 {
+            //                    value = 18
+            //                } else if value < 1 {
+            //                    value = 1
+            //                }
+            //                CPDFFreeTextAnnotation.updateDashPattern(annotations, value, withPDFView: pdfView)
+            //            }
             reloadData()
         }
     }
@@ -393,39 +442,39 @@ extension FormsTextFieldController: ComponentSelectDelegate {
             if let textUnit = view?.properties.textUnit {
                 result = result.stringByDeleteCharString(textUnit)
             }
-//            if view == fontNameSelect {
-//                var styleName = "Regular"
-//                let styleNames = CPDFFont.fontNames(forFamilyName: result)
-//                if let first = styleNames.first {
-//                    styleName = first
-//                }
-//                CPDFFreeTextAnnotation.updateFont(annotations, CPDFFont(familyName: result, fontStyle: styleName), withPDFView: pdfView)
-//            } else if view == fontStyleSelect {
-//                let styleName = fontNameSelect.properties.text ?? "Helvetica"
-//                CPDFFreeTextAnnotation.updateFont(annotations, CPDFFont(familyName: result, fontStyle: styleName), withPDFView: pdfView)
-//            } else if view == fontSizeSelect {
-//                let size = result.stringToCGFloat()
-//                CPDFFreeTextAnnotation.updateFontSize(annotations, size, withPDFView: pdfView)
-//            } else if view == opacitySelect {
-//                let opacity = max(0, min(1, result.stringToCGFloat()/100))
-//                CPDFFreeTextAnnotation.updateOpacity(annotations, opacity, withPDFView: pdfView)
-//            } else if view == lineWidthSelect {
-//                var value = result.stringToCGFloat()
-//                if value > 18 {
-//                    value = 18
-//                } else if value < 1 {
-//                    value = 1
-//                }
-//                CPDFFreeTextAnnotation.updateLineWidth(annotations, value, withPDFView: pdfView)
-//            } else if view == lineDashSelect {
-//                var value = result.stringToCGFloat()
-//                if value > 18 {
-//                    value = 18
-//                } else if value < 1 {
-//                    value = 1
-//                }
-//                CPDFFreeTextAnnotation.updateDashPattern(annotations, value, withPDFView: pdfView)
-//            }
+            //            if view == fontNameSelect {
+            //                var styleName = "Regular"
+            //                let styleNames = CPDFFont.fontNames(forFamilyName: result)
+            //                if let first = styleNames.first {
+            //                    styleName = first
+            //                }
+            //                CPDFFreeTextAnnotation.updateFont(annotations, CPDFFont(familyName: result, fontStyle: styleName), withPDFView: pdfView)
+            //            } else if view == fontStyleSelect {
+            //                let styleName = fontNameSelect.properties.text ?? "Helvetica"
+            //                CPDFFreeTextAnnotation.updateFont(annotations, CPDFFont(familyName: result, fontStyle: styleName), withPDFView: pdfView)
+            //            } else if view == fontSizeSelect {
+            //                let size = result.stringToCGFloat()
+            //                CPDFFreeTextAnnotation.updateFontSize(annotations, size, withPDFView: pdfView)
+            //            } else if view == opacitySelect {
+            //                let opacity = max(0, min(1, result.stringToCGFloat()/100))
+            //                CPDFFreeTextAnnotation.updateOpacity(annotations, opacity, withPDFView: pdfView)
+            //            } else if view == lineWidthSelect {
+            //                var value = result.stringToCGFloat()
+            //                if value > 18 {
+            //                    value = 18
+            //                } else if value < 1 {
+            //                    value = 1
+            //                }
+            //                CPDFFreeTextAnnotation.updateLineWidth(annotations, value, withPDFView: pdfView)
+            //            } else if view == lineDashSelect {
+            //                var value = result.stringToCGFloat()
+            //                if value > 18 {
+            //                    value = 18
+            //                } else if value < 1 {
+            //                    value = 1
+            //                }
+            //                CPDFFreeTextAnnotation.updateDashPattern(annotations, value, withPDFView: pdfView)
+            //            }
             reloadData()
         }
     }
@@ -435,21 +484,21 @@ extension FormsTextFieldController: ComponentSelectDelegate {
 //MARK: - ComponentCSelectorGroupDelegate
 extension FormsTextFieldController: ComponentCSelectorGroupDelegate {
     func componentCSelectorGroupDidChoose(_ view: ComponentCSelectorGroup, _ item: ComponentCSelectorItem) {
-//        if view == fontAlignmentGroup {
-//            if item.properties == fontAlign_leftItem {
-//                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .left, withPDFView: pdfView)
-//            } else if item.properties == fontAlign_centerItem {
-//                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .center, withPDFView: pdfView)
-//            } else if item.properties == fontAlign_rightItem {
-//                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .right, withPDFView: pdfView)
-//            }
-//        } else if view == lineTypeSelector {
-//            if item.properties == solidProperty {
-//                CPDFFreeTextAnnotation.updateBorderStyle(annotations, .solid, withPDFView: pdfView)
-//            } else if item.properties == dashProperty {
-//                CPDFFreeTextAnnotation.updateBorderStyle(annotations, .dashed, withPDFView: pdfView)
-//            }
-//        }
+        //        if view == fontAlignmentGroup {
+        //            if item.properties == fontAlign_leftItem {
+        //                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .left, withPDFView: pdfView)
+        //            } else if item.properties == fontAlign_centerItem {
+        //                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .center, withPDFView: pdfView)
+        //            } else if item.properties == fontAlign_rightItem {
+        //                CPDFFreeTextAnnotation.updateFontAlignment(annotations, .right, withPDFView: pdfView)
+        //            }
+        //        } else if view == lineTypeSelector {
+        //            if item.properties == solidProperty {
+        //                CPDFFreeTextAnnotation.updateBorderStyle(annotations, .solid, withPDFView: pdfView)
+        //            } else if item.properties == dashProperty {
+        //                CPDFFreeTextAnnotation.updateBorderStyle(annotations, .dashed, withPDFView: pdfView)
+        //            }
+        //        }
         reloadData()
     }
 }

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

@@ -4789,5 +4789,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "AA7F41FA-E242-4EAB-95FB-4EC607076FC0"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/KMClass/KMPDFViewController/RightSideController/KMRightSideController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "514"
+            endingLineNumber = "514"
+            landmarkName = "reloadData()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>