Browse Source

【2025】【Edit】编辑模块处理

niehaoyu 3 ngày trước cách đây
mục cha
commit
68de8338e4

+ 28 - 1
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Select/ComponentSelect.swift

@@ -153,7 +153,16 @@ public class ComponentSelect: ComponentBaseXibView {
             inputField.isEditable = false
         }
         inputField.font = properties.propertyInfo.textFont
-        inputField.stringValue = properties.text ?? ""
+        
+        if let text = properties.text {
+            inputField.stringValue = text
+            
+            if let unit = properties.textUnit {
+                if text.hasSuffix(unit) == false {
+                    inputField.stringValue = text + unit
+                }
+            }
+        }
         
     }
     
@@ -299,6 +308,15 @@ public class ComponentSelect: ComponentBaseXibView {
             isGroupViewShow == false {
             properties.state = .normal
             
+            //拼接单位
+            if let unit = properties.textUnit, unit.count > 0 {
+                var string = inputField.stringValue
+                if string.hasSuffix(unit) == false {
+                    string = string + unit
+                 }
+                inputField.stringValue = string
+            }
+            
             refreshUI()
             
             properties.text = inputField.stringValue
@@ -380,6 +398,15 @@ extension ComponentSelect: ComponentTextFieldDelegate {
             if inputField.isResponder {
                 properties.state = .pressed
                 
+                //拼接单位
+                if let unit = properties.textUnit, unit.count > 0 {
+                    var string = inputField.stringValue
+                    if string.hasSuffix(unit) {
+                        string = String(string.dropLast(unit.count))
+                     }
+                    inputField.stringValue = string
+                }
+                
                 if properties.autoShowPopupView == true {
                     showGroupView()
                 }

+ 3 - 0
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Select/ComponentSelectProperty.swift

@@ -20,6 +20,7 @@ public class ComponentSelectProperties: NSObject {
     public var errorText: String?                 //错误文字信息
     public var creatable: Bool = false            //输入框是否允许编辑
     public var text: String?                      //文字信息
+    public var textUnit: String?
     public var regexString: String?               //允许输入的文字类型 eg:"0123456789"
     
     public var autoShowPopupView: Bool = false
@@ -37,6 +38,7 @@ public class ComponentSelectProperties: NSObject {
                 errorText: String? = nil,
                 creatable: Bool = false,
                 text: String? = nil,
+                textUnit: String? = nil,
                 regexString: String? = nil) {
 
         self.size = size
@@ -48,6 +50,7 @@ public class ComponentSelectProperties: NSObject {
         self.errorText = errorText
         self.creatable = creatable
         self.text = text
+        self.textUnit = textUnit
         self.regexString = regexString
         
     }

+ 8 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Edit.swift

@@ -272,4 +272,12 @@ extension CPDFListView {
             self.verticalMirror(with: area)
         }
     }
+    
+    func setEditingAreasOpacity(_ opacity: CGFloat) {
+        let areas = self.km_EditingAreas()
+        for area in areas {
+            self.setOpacityEditArea(area, opacity: opacity)
+        }
+    }
+ 
 }

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

@@ -131,10 +131,11 @@ class KMRightSideController: NSViewController {
                 
             } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
                 //编辑文字
-                 
+                edit_textController?.pdfView = self.pdfView
                 edit_textController?.reloadData()
             } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
                 //编辑图片
+                edit_imageController?.pdfView = self.pdfView
                 edit_imageController?.reloadData()
                 
             } else {

+ 87 - 18
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/EditPDF/KMEditImageController.swift

@@ -43,7 +43,7 @@ class KMEditImageController: NSViewController {
         }
     }
      
-    var currentArea: CPDFEditTextArea?
+    var currentArea: CPDFEditImageArea?
     
     //MARK: - func
     override func viewDidAppear() {
@@ -105,11 +105,12 @@ class KMEditImageController: NSViewController {
         rotateSelect.properties = ComponentSelectProperties(size: .s,
                                                             state: .normal,
                                                             creatable: true,
-                                                            text: "100%",
-                                                            regexString: "0123456789%")
+                                                            text: "100",
+                                                            textUnit: "°",
+                                                            regexString: "0123456789-")
         if true {
             var opacityItems: [ComponentMenuitemProperty] = []
-            for string in ["25%", "50%", "75%", "100%"] {
+            for string in ["0°", "45°", "-45°", "90°", "-90°"] {
                 let item = ComponentMenuitemProperty(type: .normal, text: string)
                 opacityItems.append(item)
             }
@@ -135,12 +136,14 @@ class KMEditImageController: NSViewController {
         opacityLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
         
         opacitySlider.properties = ComponentSliderProperty(size: .m, percent: 1)
+        opacitySlider.delegate = self
         
         opacitySelect.properties = ComponentSelectProperties(size: .s,
-                                                                  state: .normal,
-                                                                  creatable: true,
-                                                                  text: "100%",
-                                                                  regexString: "0123456789%")
+                                                             state: .normal,
+                                                             creatable: true,
+                                                             text: "100",
+                                                             textUnit: "%",
+                                                             regexString: "0123456789%")
         if true {
             var opacityItems: [ComponentMenuitemProperty] = []
             for string in ["25%", "50%", "75%", "100%"] {
@@ -165,7 +168,7 @@ class KMEditImageController: NSViewController {
     
     func reloadData() {
         
-        let areas = pdfView?.km_editingTextAreas() ?? []
+        let areas = pdfView?.km_editingImageAreas() ?? []
         if areas.count == 0 {
             currentArea = nil
         } else if areas.count == 1 {
@@ -175,15 +178,32 @@ class KMEditImageController: NSViewController {
         }
         
         if let area = currentArea {
-            let fontName = pdfView?.km_editTextAreasFontNames([area])
-            let fontStyle = pdfView?.km_editTextAreasFontStyles([area])
-            let fontSize = pdfView?.km_editTextAreasFontSizes([area])
-            let bold = pdfView?.km_editTextAreasFontBolds([area])
-            let itality = pdfView?.km_editTextAreasFontItalics([area])
-            let alignment = pdfView?.km_editTextAreasTextAlignments([area])
-            let colors = pdfView?.km_editTextAreasFontColors([area])
-            let opacity = pdfView?.km_editAreasOpacitys([area])
-            print("1")
+            
+            
+            if let opacitys = pdfView?.km_editAreasOpacitys([area]) {
+                if opacitys.count > 0 {
+                    var opacity = opacitys.first ?? 1
+                    opacity = min(1, opacity)
+                    opacity = max(0, opacity)
+                    
+                    opacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
+                    opacitySelect.reloadData()
+                    
+                    opacitySlider.properties.percent = opacity
+                    opacitySlider.reloadData()
+                }
+            }
+            
+            if let rotates = pdfView?.km_editAreasRotates([area]) {
+                if rotates.count > 0 {
+                    var rotate = rotates.first ?? 1
+                    
+                    rotateSelect.properties.text = String(format: "%.0f", rotate)
+                    rotateSelect.reloadData()
+                     
+                }
+            }
+            
         }
         
         
@@ -208,15 +228,64 @@ class KMEditImageController: NSViewController {
         } else if sender == ExtrackButton {
             
         }
+        
+        reloadData()
+    }
+    
+    
+    //MARK: - MouseEvent
+    override func mouseDown(with event: NSEvent) {
+        super.mouseDown(with: event)
+        
+        view.window?.makeFirstResponder(nil)
     }
     
 }
 
 
+//MARK: - ComponentSelectDelegate
 extension KMEditImageController: ComponentSelectDelegate {
+    func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
+        if view == opacitySelect {
+            if let text = opacitySelect.properties.text {
+                let result = text.stringByDeleteCharString("%")
+                let opacity = result.stringToCGFloat()/100
+                
+                pdfView?.setEditingAreasOpacity(opacity)
+                
+                reloadData()
+            }
+        }
+    }
     
+    func componentSelectTextDidEndEditing(_ view: ComponentSelect) {
+        if view == opacitySelect {
+            if let text = opacitySelect.properties.text {
+                let result = text.stringByDeleteCharString("%")
+                let opacity = result.stringToCGFloat()/100
+                
+                pdfView?.setEditingAreasOpacity(opacity)
+                
+                reloadData()
+            }
+        }
+    }
 }
 
+//MARK: - ComponentCColorDelegate
 extension KMEditImageController: ComponentCColorDelegate {
  
 }
+
+//MARK: - ComponentSliderDelegate
+extension KMEditImageController: ComponentSliderDelegate {
+    func componentSliderDidUpdate(_ view: ComponentSlider) {
+        let percent = view.properties.percent
+        
+        self.pdfView?.setEditingAreasOpacity(percent)
+        
+        reloadData()
+        
+    }
+}
+