jsonwang 3 tahun lalu
induk
melakukan
17019b8cfc
1 mengubah file dengan 10 tambahan dan 6 penghapusan
  1. 10 6
      BFFramework/Classes/PQGPUImage/akfilters/PQTextFilter.swift

+ 10 - 6
BFFramework/Classes/PQGPUImage/akfilters/PQTextFilter.swift

@@ -50,19 +50,23 @@ open class PQTextFilter: PQBaseFilter {
                 UILabel.init(frame: CGRect(x: 0, y: 0, width: self?.stickerInfo?.materialPosition?.width ?? 0, height: self?.stickerInfo?.materialPosition?.height ?? 0))
              
                 subtitleLab.numberOfLines = 2
+                subtitleLab.lineBreakMode = .byWordWrapping
 
                 FilterLog(message: "字幕初始化时大小 \(subtitleLab.frame)")
-
-                subtitleLab.textAlignment = .center
                 subtitleLab.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.5)
-
                 subtitleLab.alpha = 1
-               
-                let attributedText: NSMutableAttributedString = NSMutableAttributedString(string: (self?.stickerInfo?.subtitleInfo?.text ?? ""), attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: CGFloat(self?.stickerInfo?.subtitleInfo?.fontSize ?? 0)), NSAttributedString.Key.foregroundColor:UIColor.white,NSAttributedString.Key.kern: 0])
+          
+                let paraph = NSMutableParagraphStyle()
+                paraph.lineSpacing = 0
+                paraph.alignment = .center
+ 
+                
+                let attributedText: NSMutableAttributedString = NSMutableAttributedString(string: (self?.stickerInfo?.subtitleInfo?.text ?? ""), attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: CGFloat(self?.stickerInfo?.subtitleInfo?.fontSize ?? 0)), NSAttributedString.Key.foregroundColor:UIColor.white,NSAttributedString.Key.kern: 0,NSAttributedString.Key.paragraphStyle:paraph])
                 subtitleLab.attributedText = attributedText
  
                 let size: CGSize = subtitleLab.bounds.size
-                UIGraphicsBeginImageContextWithOptions(size, false, 1)
+                //如果传0,则这个参数会用设备的scale,
+                UIGraphicsBeginImageContextWithOptions(size, false, 2)
                 subtitleLab.layer.render(in: UIGraphicsGetCurrentContext()!)
 
                 self?.subtitleImage = UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()