From 4807b81dd5d112e4dee8cceb777316354fbd316b Mon Sep 17 00:00:00 2001 From: lmk <1095689763@qq.com> Date: Thu, 25 Jun 2026 17:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=B9=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/video/caption_service.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/service/video/caption_service.go b/service/video/caption_service.go index e2ab6e4..ef5fdd2 100644 --- a/service/video/caption_service.go +++ b/service/video/caption_service.go @@ -388,15 +388,22 @@ func (s *captionService) buildHTML(taskID, videoPath, audioPath string, elements elemID, animClass, elem.StartTime, elemDuration, trackIdx, html.EscapeString(elem.ImageURL), imgStyle)) } else { bgStyle := "" + hasBg := false if elem.BgColor != "" { + hasBg = true if elem.BgOpacity > 0 && elem.BgOpacity < 1 { bgStyle = fmt.Sprintf("background:%s;padding:12px 24px;border-radius:8px;", hexToRGBA(elem.BgColor, elem.BgOpacity)) } else { bgStyle = fmt.Sprintf("background:%s;padding:12px 24px;border-radius:8px;", elem.BgColor) } } - sb.WriteString(fmt.Sprintf("
%s
\n", - elemID, animClass, elem.StartTime, elemDuration, trackIdx, style, bgStyle, html.EscapeString(elem.Text))) + if hasBg { + sb.WriteString(fmt.Sprintf("
%s
\n", + elemID, animClass, elem.StartTime, elemDuration, trackIdx, style, bgStyle, html.EscapeString(elem.Text))) + } else { + sb.WriteString(fmt.Sprintf("
%s
\n", + elemID, animClass, elem.StartTime, elemDuration, trackIdx, style, html.EscapeString(elem.Text))) + } } clipIndex++ } @@ -485,6 +492,7 @@ func (s *captionService) buildElemStyle(elem dto.CaptionElement, canvasWidth, ca maxWidthPct = 90 } maxWidth := int(float64(canvasWidth) * float64(maxWidthPct) / 100.0) + parts = append(parts, fmt.Sprintf("width:%dpx;", maxWidth)) parts = append(parts, fmt.Sprintf("max-width:%dpx;", maxWidth)) if elem.FontSize > 0 {