Browse Source

【文字图片编辑】文字预览图片非nil判断

lizhe 1 year ago
parent
commit
bed8d7e8e2

+ 7 - 6
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/EditPDF/KMEditPDFTextPropertyViewController.swift

@@ -681,12 +681,13 @@ extension KMEditPDFTextPropertyViewController {
         
         let size = string.size(withAttributes:attributes as [NSAttributedString.Key : Any])
         let image = NSImage(size: NSSize(width: self.preImageView.frame.size.width, height: size.height))
-        image.lockFocus()
-        NSGraphicsContext.current?.imageInterpolation = .high
-        NSString(string: string).draw(in: NSRect(x: 0, y: 0, width: self.preImageView.frame.size.width, height: image.size.height), withAttributes: attributes as [NSAttributedString.Key : Any])
-        NSGraphicsContext.current?.imageInterpolation = .default
-        image.unlockFocus()
-        
+        if image.size.width != 0 && image.size.height != 0 {
+            image.lockFocus()
+            NSGraphicsContext.current?.imageInterpolation = .high
+            NSString(string: string).draw(in: NSRect(x: 0, y: 0, width: self.preImageView.frame.size.width, height: image.size.height), withAttributes: attributes as [NSAttributedString.Key : Any])
+            NSGraphicsContext.current?.imageInterpolation = .default
+            image.unlockFocus()
+        }
         self.preImageView.image = image
     }