Forráskód Böngészése

优化字幕小字体模糊问题

zhongbaojian 5 éve
szülő
commit
6182ffb34b

+ 1 - 1
SuperShow/Tool/WSSUIViewExtension.swift

@@ -81,7 +81,7 @@ public extension UIView {
         isShoting = true
         let bounds = self.bounds
 
-        UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
+        UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
 
         let context = UIGraphicsGetCurrentContext()
         context?.saveGState()

+ 8 - 1
SuperShow/UI/CoolVoice/Views/CoreTextLabel/WSSCoolVoicePasterView.swift

@@ -38,6 +38,7 @@ class WSSCoolVoicePasterView: WSSPasterBaseView {
     var subtitleLabel: WSSCoolVoiceTextLabel?
     var currentFontSize: CGFloat = WSSCoolVoiceTextLabelViewModel.kDefaultFontSize
     var isSubtitleDragging: Bool = false
+    private var scale: CGFloat = 1.0
 
     fileprivate var boxView: UIImageView = {
         let box = UIImageView()
@@ -96,11 +97,17 @@ class WSSCoolVoicePasterView: WSSPasterBaseView {
         }
     }
 
+    func scaleFontSize(_ fontSize: CGFloat, scale: CGFloat) {
+        subtitleLabel?.scale = scale
+        self.scale = scale
+        changeFontSize(fontSize)
+    }
+
     func refreshLayout() {
         if var subtitleSize = self.subtitleLabel?.size {
             let oldCenter: CGPoint = center
 
-            let maxWidth: CGFloat = kOJSScreenWidth - OJAStyle.LRCommonMargin * 2.0
+            let maxWidth: CGFloat = (kOJSScreenWidth - OJAStyle.LRCommonMargin * 2.0) * scale
             if subtitleSize.width >= maxWidth {
                 subtitleSize.width = maxWidth
             } else {

+ 4 - 1
SuperShow/UI/CoolVoice/Views/CoreTextLabel/WSSCoolVoiceTextLabel.swift

@@ -10,6 +10,9 @@ import OJASwiftKit
 import UIKit
 
 class WSSCoolVoiceTextLabel: YYLabel {
+    
+    var scale:CGFloat = 1.0
+    
     var viewModel: WSSCoolVoiceTextLabelViewModel? {
         didSet {
             if let newModel = viewModel {
@@ -52,7 +55,7 @@ class WSSCoolVoiceTextLabel: YYLabel {
     }
 
     func refreshHeight() {
-        let maxWidth: CGFloat = kOJSScreenWidth - OJAStyle.LRCommonMargin * 2.0
+        let maxWidth: CGFloat = (kOJSScreenWidth - OJAStyle.LRCommonMargin * 2.0) * self.scale
         var newSize: CGSize = sizeThatFits(CGSize(width: maxWidth, height: CGFloat.greatestFiniteMagnitude))
 
         if newSize.width > maxWidth {

+ 10 - 6
SuperShow/UI/CoolVoice/WSSCoolVoiceSubtitleController.swift

@@ -1041,7 +1041,7 @@ fileprivate extension WSSCoolVoiceSubtitleController {
 
         effectExport?.didEndProcessingHandle = { [weak self] isUserCancel in
             guard !isUserCancel else {
-                    hideHud()
+                hideHud()
                 return
             }
             self?.movieWriter?.finishRecording(completionHandler: { [weak self] in
@@ -1145,10 +1145,8 @@ fileprivate extension WSSCoolVoiceSubtitleController {
         let centerYPercent: CGFloat = centerPoint.y / overlaySize.height
         let covertCenter: CGPoint = CGPoint(x: centerXPercent * rect.size.width, y: centerYPercent * rect.size.height)
 
-//        WSSSimpleLog("🥞🥞🥞: \(centerXPercent) + \(centerYPercent) + \(covertCenter) ++ \(rect)")
-
         for subtitleModel in currentShowingSubtitleInfos {
-            if let textModel = subtitleModel.fontViewModel {
+            if let textModel = subtitleModel.fontViewModel?.deepCopy() {
                 let tmpPasterView = WSSCoolVoicePasterView.createPasterView(withCenter: centerPoint, vm: textModel)
 
                 let sizeWidthPercent: CGFloat = tmpPasterView.size.width / overlaySize.width
@@ -1158,9 +1156,15 @@ fileprivate extension WSSCoolVoiceSubtitleController {
                 tmpPasterView.bounds = covertBounds
                 tmpPasterView.center = covertCenter
 
-//                    WSSSimpleLog("🥞🥞🥞aaa: \(sizeWidthPercent) + \(sizeHeightPercent) + \(covertBounds) ")
-
                 let vertex = calculateVertex(withPaster: tmpPasterView, targetView: placeholer).map({ NSNumber(value: Float($0)) })
+
+                // 为了提高小字体的字体清晰度
+                let needScaleFontSize: CGFloat = 24.0
+                if textModel.fontSize < needScaleFontSize {
+                    let scale: CGFloat = needScaleFontSize / textModel.fontSize
+                    tmpPasterView.scaleFontSize(needScaleFontSize, scale: scale)
+                }
+
                 if let image = tmpPasterView.subtitleLabel?.wss_screenShot() {
                     guard let input = setupInput(textImage: image, vertex: vertex) else { return }
                     let pasterData: (XunFeiSDKTool.MSCResultModel, OJAPasterFrameInput) = (subtitleModel, input)