Browse Source

【fix】内容编辑】图片属性面板,调整宽高比后,图片消失

tangchao 7 months ago
parent
commit
6d8b6b4bb8

+ 20 - 3
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/EditPDF/KMEditImagePropertyViewController.swift

@@ -936,12 +936,20 @@ extension KMEditImagePropertyViewController: KMTextFieldDelegate {
             for area in areas {
                 let state =  self.whVC?.state ?? .None
                 var bounds = area.bounds
-                let width = string?.stringToCGFloat() ?? 0
+                var width = string?.stringToCGFloat() ?? 0
                 if width == 0 {
                     return
                 }
                 
-//                bounds.origin.x = max(0, bounds.origin.x-width*0.5)
+                let pageBounds = area.page?.bounds ?? .zero
+                if width > NSWidth(pageBounds) {
+                    width = NSWidth(pageBounds)
+                    
+                    let value = String(format: "%.1f", width)
+                    self.wTextFieldItemView.stringValue = value
+                }
+                bounds.origin.x = max(0, (pageBounds.size.width-width)*0.5)
+                
                 if state == .Act { // 寛高约束
                     var scale: CGFloat = 0
                     if bounds.size.width != 0 {
@@ -970,11 +978,20 @@ extension KMEditImagePropertyViewController: KMTextFieldDelegate {
 //            if let area = areas.first as? CPDFEditImageArea {
                 let state =  self.whVC?.state ?? .None
                 var bounds = area.bounds
-                let height = string?.stringToCGFloat() ?? 0
+                var height = string?.stringToCGFloat() ?? 0
                 if height == 0 {
                     return
                 }
 
+                let pageBounds = area.page?.bounds ?? .zero
+                if height > NSHeight(pageBounds) {
+                    height = NSHeight(pageBounds)
+                    
+                    let value = String(format: "%.1f", height)
+                    self.hTextFieldItemView.stringValue = value
+                }
+                bounds.origin.y = max(0, (pageBounds.size.height-height)*0.5)
+                
                 if state == .Act { // 寛高约束
                     var scale: CGFloat = 0
                     if bounds.size.height != 0 {