|
@@ -62,35 +62,25 @@ open class PQSubTitleFilter: PQBaseFilter {
|
|
|
createTexture(currtime: .zero)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func getWidthWithTitle(text: String, font: UIFont) -> CGFloat {
|
|
|
- let label = UILabel(frame: CGRect(x: 0, y: 0, width: inputCGSize.width * 0.8, height: 0))
|
|
|
- label.text = text
|
|
|
- label.font = font
|
|
|
- label.sizeToFit()
|
|
|
- let width = label.frame.size.width
|
|
|
-
|
|
|
- return width
|
|
|
- }
|
|
|
-
|
|
|
func setupLabel(text: String) {
|
|
|
+
|
|
|
+ if(mSubtitles?.count == 0){
|
|
|
+ BFLog(message: "一个字幕也没有?数据错误!")
|
|
|
+ return
|
|
|
+ }
|
|
|
var boundingRect: CGRect = .zero
|
|
|
|
|
|
+ //字幕风格设置
|
|
|
+ let setting = mSubtitles?.first?.setting
|
|
|
// 小字幕字号大小
|
|
|
- var font: Int = 60
|
|
|
- if inputCGSize.width / inputCGSize.height > 1.5 {
|
|
|
- font = 68
|
|
|
- }
|
|
|
-// if !isBigSubtile {
|
|
|
- boundingRect = text.boundingRect(with: CGSize(width: inputCGSize.width * 0.8, height: 0), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: CGFloat(isBigSubtile ? 114 : font))], context: nil)
|
|
|
-// }
|
|
|
-
|
|
|
- let strokeWidth: CGFloat = 6
|
|
|
- let width = getWidthWithTitle(text: text, font: UIFont.boldSystemFont(ofSize: CGFloat(isBigSubtile ? 114 : font)))
|
|
|
+ let font: Int = setting?.subtitleSize ?? 0
|
|
|
|
|
|
+ //根据字号计算高度
|
|
|
+ boundingRect = text.boundingRect(with: CGSize(width: inputCGSize.width * 0.8, height: 0), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: CGFloat(isBigSubtile ? 114 : font))], context: nil)
|
|
|
+
|
|
|
subtitleLab = PQSubTitleLabel(frame: CGRect(x: 0, y: 0, width: inputCGSize.width * 0.8, height: boundingRect.height > inputCGSize.height - 120 ? inputCGSize.height - 120 : boundingRect.height))
|
|
|
- subtitleLab.strokeColor = UIColor.black
|
|
|
- subtitleLab.strokeWidth = strokeWidth
|
|
|
+ subtitleLab.strokeColor = setting?.strokeColor ?? UIColor.black
|
|
|
+ subtitleLab.strokeWidth = setting?.strokeWidth ?? 6
|
|
|
|
|
|
subtitleLab.font = UIFont.boldSystemFont(ofSize: CGFloat(isBigSubtile ? 114 : font))
|
|
|
subtitleLab.numberOfLines = 0
|
|
@@ -98,10 +88,10 @@ open class PQSubTitleFilter: PQBaseFilter {
|
|
|
BFLog(2, message: "字幕初始化时大小 \(subtitleLab.frame)")
|
|
|
|
|
|
subtitleLab.textAlignment = .center
|
|
|
- subtitleLab.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.5)
|
|
|
+ subtitleLab.backgroundColor = UIColor(red: setting?.backgroundColor.rgbaf[0] ?? 1, green: setting?.backgroundColor.rgbaf[1] ?? 1, blue: setting?.backgroundColor.rgbaf[2] ?? 1, alpha: CGFloat(setting?.backgroundAlpha ?? 0.5))
|
|
|
|
|
|
subtitleLab.alpha = 1
|
|
|
- subtitleLab.textColor = UIColor.white
|
|
|
+ subtitleLab.textColor = setting?.fontColor ?? UIColor.white
|
|
|
subtitleLab.text = text
|
|
|
}
|
|
|
|
|
@@ -220,13 +210,23 @@ open class PQSubTitleFilter: PQBaseFilter {
|
|
|
let texturePropertiesimagetwo = InputTextureProperties(textureCoordinates: inputFramebuffer.orientation.rotationNeededForOrientation(.portrait).textureCoordinates(), texture: subTitleTexture)
|
|
|
|
|
|
BFLog(2, message: "subtitleSize subtitleSize is\(String(describing: subtitleSize)) \(inputCGSize)")
|
|
|
-
|
|
|
- let size: CGSize = inputCGSize
|
|
|
- let bounds2: CGRect = CGRect(x: (inputCGSize.width - subtitleSize!.width) / 2, y: inputCGSize.height - subtitleSize!.height - 60, width: subtitleSize!.width, height: subtitleSize!.height)
|
|
|
- BFLog(2, message: "inputCGSize is \(size) bounds2\(bounds2)")
|
|
|
+ //根据风格设置不同的Y位置 X 值默认为中间
|
|
|
+
|
|
|
+ let subtitlePoint = mSubtitles?.first?.setting.subtitlePoint ?? 0
|
|
|
+ var originY:CGFloat = 0.0
|
|
|
+ //下
|
|
|
+ if(subtitlePoint == 0){
|
|
|
+ originY = inputCGSize.height * 0.70 - subtitleSize!.height
|
|
|
+ }else if(subtitlePoint == 1){//中
|
|
|
+ originY = inputCGSize.height / 2.0 - subtitleSize!.height / 2.0
|
|
|
+ }else if(subtitlePoint == 2){//上
|
|
|
+ originY = inputCGSize.height * 0.12
|
|
|
+ }
|
|
|
+ BFLog(2, message: "inputCGSize is \(inputCGSize) originY:\(originY)")
|
|
|
+
|
|
|
renderQuadWithShader(shader,
|
|
|
uniformSettings: uniformSettings,
|
|
|
- vertexBufferObject: PQGPUImageTools.NXGenerateVBO(for: PQGPUImageTools.computeVertices(viewSize: inputCGSize, _bounds: CGRect(x: (inputCGSize.width - subtitleSize!.width) / 2, y: isBigSubtile ? (inputCGSize.height - subtitleSize!.height - 60) / 2 : inputCGSize.height - subtitleSize!.height - 60, width: subtitleSize!.width, height: subtitleSize!.height))),
|
|
|
+ vertexBufferObject: PQGPUImageTools.NXGenerateVBO(for: PQGPUImageTools.computeVertices(viewSize: inputCGSize, _bounds: CGRect(x: (inputCGSize.width - subtitleSize!.width) / 2, y:originY, width: subtitleSize!.width, height: subtitleSize!.height))),
|
|
|
inputTextures: [texturePropertiesimagetwo])
|
|
|
|
|
|
releaseIncomingFramebuffers()
|