fix: 字体变更时重置fontLoaded状态并重新检测
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 45s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 53s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m44s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 1m17s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m40s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m51s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m45s
AI Code Review / AI Code Review (pull_request) Failing after 4m17s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m48s
CI/CD Pipeline / CI Gate (pull_request) Successful in 10s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 988h49m45s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 988h49m46s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 988h49m46s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 988h49m47s
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 988h53m43s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 988h49m47s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 988h53m43s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 988h49m47s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 988h54m35s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 988h54m35s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 988h54m36s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 989h23m3s
CI/CD Pipeline / PR Build Worker Image (pull_request) Failing after 989h26m59s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 989h27m52s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 45s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 53s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m44s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 1m17s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m40s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m51s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m45s
AI Code Review / AI Code Review (pull_request) Failing after 4m17s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m48s
CI/CD Pipeline / CI Gate (pull_request) Successful in 10s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 988h49m45s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 988h49m46s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 988h49m46s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 988h49m47s
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 988h53m43s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 988h49m47s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 988h53m43s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 988h49m47s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 988h54m35s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 988h54m35s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 988h54m36s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 988h54m37s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 989h23m3s
CI/CD Pipeline / PR Build Worker Image (pull_request) Failing after 989h26m59s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 989h27m52s
- titleSettings变更时setFontLoaded(false)重置 - 使用document.fonts.check(fontSpec)精确检测目标字体 - 字体未加载时用document.fonts.load等待后重绘 - 移除setTimeout魔法数字,改用requestAnimationFrame
This commit is contained in:
@@ -267,21 +267,50 @@ export const PreviewVideoPanel: React.FC<PreviewVideoPanelProps> = ({
|
||||
return () => observer.disconnect()
|
||||
}, [showTitlePreview, hasPreview, isError, drawNoVideoTitle])
|
||||
|
||||
// 字体加载完成后重绘(Canvas measureText 依赖字体已加载)
|
||||
// 字体加载检测:当字体变更时重新检测,确保 measureText 使用正确字体计算
|
||||
useEffect(() => {
|
||||
if (!showTitlePreview) return
|
||||
if (!showTitlePreview || !titleSettings) {
|
||||
setFontLoaded(false)
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
document.fonts.ready.then(() => {
|
||||
if (cancelled) return
|
||||
// 短暂延迟确保字体完全可用
|
||||
setTimeout(() => {
|
||||
if (!cancelled) setFontLoaded(true)
|
||||
}, 50)
|
||||
})
|
||||
setFontLoaded(false) // 字体变更时重置,防止使用 fallback 字体绘制
|
||||
|
||||
const fontWeight = titleSettings.bold ? "bold" : ""
|
||||
const fontStyle = titleSettings.italic ? "italic" : ""
|
||||
const fontSpec =
|
||||
`${fontStyle} ${fontWeight} ${titleSettings.size}px "${titleSettings.font}"`.trim()
|
||||
|
||||
// 优先用 document.fonts.check 精确检测目标字体
|
||||
if (document.fonts.check(fontSpec)) {
|
||||
setFontLoaded(true)
|
||||
return
|
||||
}
|
||||
|
||||
// 字体尚未加载,等待后重试
|
||||
document.fonts
|
||||
.load(fontSpec)
|
||||
.then(() => {
|
||||
if (!cancelled) {
|
||||
// requestAnimationFrame 确保在下一帧绘制前字体已可用
|
||||
requestAnimationFrame(() => {
|
||||
if (!cancelled) setFontLoaded(true)
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// load 失败时回退到 fonts.ready
|
||||
if (!cancelled) {
|
||||
document.fonts.ready.then(() => {
|
||||
if (!cancelled) setFontLoaded(true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [showTitlePreview])
|
||||
}, [showTitlePreview, titleSettings])
|
||||
|
||||
// video 加载完成后重绘
|
||||
const handleVideoLoaded = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user